/** * @Route("/show_category/{slug}", name="show_category") * @ParamConverter("category", class="AppBundle\Entity\Category", options={"mapping": {"slug": "title"}}) */ public function showCategoryAction(Request $request, Category $category) { $em = $this->getDoctrine()->getManager(); $estates = $em->getRepository('AppBundle\\Entity\\Estate')->getEstateFromCategory($category->getTitle()); $paginator = $this->get('knp_paginator'); $pagination = $paginator->paginate($estates, $request->query->getInt('page', 1), 5); $this->container->get('app.breadcrumps_maker')->makeBreadcrumps($category); return $this->render("AppBundle::site/index.html.twig", array('pagination' => $pagination)); }
/** * 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()); }
/** * @param Category $category * @param Request $request * @Route("/category/delete/{id}", name="admin_category_delete", * requirements={ * "id": "\d+" * }) * @Method({"POST"}) * @ParamConverter("category", class="AppBundle:Category") * @Template("AppBundle:admin:messages.html.twig") * @return array|\Symfony\Component\HttpFoundation\RedirectResponse */ public function deleteCategoryAction(Category $category, Request $request) { $countProducts = $category->getProducts()->count(); if ($countProducts > 0) { $message = "Cannot delete category '" . $category->getTitle() . "', because it has " . $countProducts . " products."; } else { $formDelete = $this->createForm(DeleteType::class, null, []); $formDelete->handleRequest($request); if ($formDelete->isValid()) { $em = $this->getDoctrine()->getManager(); $em->remove($category); $em->flush(); } return $this->redirectToRoute('admin_categories'); } return ['message' => $message]; }