Example #1
0
 private function createAndPersistProducts(Category $category)
 {
     for ($i = 1; $i <= $this->productsPerCategory; $i++) {
         $this->productsCount++;
         $product = new Product();
         $product->setCode(sprintf('code_%s_%s', $category->getId(), $i))->setTitle(sprintf('title %s %s %s', $category->getId(), $i, uniqid()))->setDescription(sprintf('product description %s', $i));
         $category->addProduct($product);
         $this->manager->persist($product);
         $this->setReference(sprintf('product_%s', $this->productsCount), $product);
     }
 }
Example #2
0
 /**
  * @param Category $category
  * @param          $limit
  * @param          $page
  * @return \Doctrine\ORM\QueryBuilder
  */
 public function getPostsByCategoryQuery(Category $category, $limit, $page)
 {
     $query = $this->createQueryBuilder('p');
     $categoriesIds[] = $category->getId();
     $categories = $category->getChildren();
     foreach ($categories as $cat) {
         $categoriesIds[] = $cat->getId();
     }
     return $query->select('p')->where($query->expr()->eq('p.isPublished', true))->andWhere($query->expr()->in('p.category', $categoriesIds))->orderBy('p.updated', 'DESC')->setMaxResults($limit)->setFirstResult($page);
 }
 /**
  * Test an empty Category entity
  */
 public function testEmptyCategory()
 {
     $category = new Category();
     $this->assertEquals('New Category', $category->__toString());
     $this->assertNull($category->getId());
     $this->assertNull($category->getTitle());
     $this->assertEquals(0, $category->getItems()->count());
     $this->assertInstanceOf('\\Doctrine\\Common\\Collections\\ArrayCollection', $category->getItems());
     $this->assertNull($category->getCreatedAt());
     $this->assertNull($category->getUpdatedAt());
 }
 /**
  * @Route("/categorie/{id}/question/ajouter", name="question_add")
  */
 public function addAction(Request $request, Category $category)
 {
     $question = new Question();
     $category->addQuestion($question);
     $form = $this->createForm(new QuestionType(), $question);
     $form->handleRequest($request);
     if ($form->isValid() && $form->isSubmitted()) {
         $em = $this->getDoctrine()->getEntityManager();
         $em->persist($question);
         $em->flush();
         return $this->redirect($this->generateUrl('category_show', ['id' => $category->getId()]));
     }
     return $this->render(':question:add.html.twig', ['form' => $form->createView()]);
 }
 /**
  * Creates the delete form for blog categories
  *
  * @param Category $category The category object
  *
  * @return \Symfony\Component\Form\Form The form
  */
 private function createDeleteForm(Category $category)
 {
     return $this->createFormBuilder()->setAction($this->generateUrl('admin_category_delete', array('id' => $category->getId())))->setMethod('DELETE')->getForm();
 }
 /**
  * {@inheritDoc}
  */
 public function getId()
 {
     if ($this->__isInitialized__ === false) {
         return (int) parent::getId();
     }
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getId', array());
     return parent::getId();
 }