/**
  * Lists all Producto entities.
  *
  */
 public function indexAction(Request $request, $categoria, $tipo)
 {
     $em = $this->get('doctrine.orm.entity_manager');
     $categoria = $em->getRepository('GulloaStoreBackendBundle:Categoria')->findOneBySlug($categoria);
     $tipo = $em->getRepository('GulloaStoreBackendBundle:Tipo')->findOneBySlug($tipo);
     if ($tipo == null) {
         if ($categoria == null) {
             $dql = "SELECT p\n                        FROM GulloaStoreBackendBundle:Producto p\n                        LEFT JOIN p.tipo t\n                        LEFT JOIN t.categoria ca\n                ";
             $entities = $em->createQuery($dql);
             $categoria = new Categoria();
             $tipo = new Tipo();
         } else {
             $categoriaId = $categoria->getId();
             $dql = "SELECT p\n                        FROM GulloaStoreBackendBundle:Producto p\n                        LEFT JOIN p.tipo t\n                        LEFT JOIN t.categoria ca\n                        WHERE ca.id = {$categoriaId}\n                ";
             $entities = $em->createQuery($dql);
             $tipo = new Tipo();
         }
     } else {
         $tipoId = $tipo->getId();
         $dql = "SELECT p\n                    FROM GulloaStoreBackendBundle:Producto p\n                    LEFT JOIN p.tipo t\n                    LEFT JOIN t.categoria ca\n                    WHERE t.id = {$tipoId}\n                ";
         $entities = $em->createQuery($dql);
     }
     $categorias = $em->getRepository('GulloaStoreBackendBundle:Categoria')->findAll();
     $paginator = $this->get('knp_paginator');
     $entities = $paginator->paginate($entities, $request->query->getInt('page', 1), 10);
     return $this->render('GulloaStoreBackendBundle:Producto:index.html.twig', array('entities' => $entities, 'categorias' => $categorias, 'categoria' => $categoria, 'tipo' => $tipo));
 }
Example #2
0
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     for ($i = 1; $i <= 14; $i++) {
         $tipo = new Tipo();
         $tipo->setNombre('Tipo ' . $i)->setCategoria($this->getReference('categoria-' . rand(1, 3)));
         $this->addReference('tipo-' . $i, $tipo);
         $manager->persist($tipo);
     }
     $manager->flush();
 }