{{ code.body }}
- diff --git a/src/Govnokod/CodeBundle/Controller/CodeController.php b/src/Govnokod/CodeBundle/Controller/CodeController.php index aea5057..7c27ec6 100644 --- a/src/Govnokod/CodeBundle/Controller/CodeController.php +++ b/src/Govnokod/CodeBundle/Controller/CodeController.php @@ -5,34 +5,40 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Govnokod\CodeBundle\Entity\Code; use Govnokod\CommentBundle\Entity\Thread; +use Symfony\Component\HttpFoundation\Request; class CodeController extends Controller { - public function listAction($category = null) + public function listAction(Request $request, $category = null) { - $em = $this->getDoctrine()->getManager(); - - $criteria = array(); - if (!is_null($category)) { - $categoryRepository = $em->getRepository("GovnokodCodeBundle:Category"); - $categoryEntity = $categoryRepository->findByName($category); + /* var $codeService \Govnokod\CodeBundle\Service\CodeService */ + $codeService = $this->container->get('code_service'); + /* var $categoryService \Govnokod\CodeBundle\Service\CategoryService */ + $categoryService = $this->container->get('category_service'); + $categoryEntity = null; + + if ($category) { + $categoryEntity = $categoryService->getEntity($category); if (!$categoryEntity) { throw $this->createNotFoundException("Category «{$category}» doesn't exists"); } - $criteria['category'] = $categoryEntity; } - $codeRepository = $em->getRepository('GovnokodCodeBundle:Code'); - $codes = $codeRepository->findBy($criteria, array('created_at' => 'DESC')); + $page = $request->query->get('page', 0); + $pageSize = $this->container->getParameter('code_controller.page_size'); - return $this->render('GovnokodCodeBundle:Code:list.html.twig', array( - 'codes' => $codes - )); + list($codes, $pageCount, $actualPage) = $codeService->paginate($page, $pageSize, $categoryEntity); + + return $this->render('GovnokodCodeBundle:Code:list.html.twig', [ + 'codes' => $codes, + 'currentPage' => $actualPage, + 'pageCount' => $pageCount, + 'current_filters' => ['category' => $category] + ]); } - public function viewAction($id) + public function viewAction(Request $request, $id) { - $request = $this->getRequest(); $em = $this->getDoctrine()->getManager(); $codeRepository = $em->getRepository('GovnokodCodeBundle:Code'); @@ -64,9 +70,8 @@ public function viewAction($id) )); } - public function saveAction($id = null) + public function saveAction(Request $request, $id = null) { - $request = $this->getRequest(); $em = $this->getDoctrine()->getManager(); $codeRepository = $em->getRepository('GovnokodCodeBundle:Code'); diff --git a/src/Govnokod/CodeBundle/Resources/config/routing.yml b/src/Govnokod/CodeBundle/Resources/config/routing.yml index 045ae5b..21c2985 100644 --- a/src/Govnokod/CodeBundle/Resources/config/routing.yml +++ b/src/Govnokod/CodeBundle/Resources/config/routing.yml @@ -21,5 +21,7 @@ code_view_legacy: id: \d+ code_list: - pattern: /{category}/ + pattern: /{category} defaults: { _controller: GovnokodCodeBundle:Code:list } + requirements: + category: "[a-z]*" diff --git a/src/Govnokod/CodeBundle/Resources/config/services.yml b/src/Govnokod/CodeBundle/Resources/config/services.yml index 8ee016c..d293619 100644 --- a/src/Govnokod/CodeBundle/Resources/config/services.yml +++ b/src/Govnokod/CodeBundle/Resources/config/services.yml @@ -1,5 +1,7 @@ parameters: -# govnokod_code.example.class: Govnokod\CodeBundle\Example + code_service.class: Govnokod\CodeBundle\Service\CodeService + category_service.class: Govnokod\CodeBundle\Service\CategoryService + code_controller.page_size: 20 services: sonata.admin.govnokod: @@ -7,3 +9,13 @@ services: arguments: [null, 'Govnokod\CodeBundle\Entity\Category', 'SonataAdminBundle:CRUD'] tags: - { name: sonata.admin, manager_type: orm, label: Категории говнокода } + + code_service: + class: %code_service.class% + arguments: + entityManager: "@doctrine.orm.entity_manager" + + category_service: + class: %category_service.class% + arguments: + entityManager: "@doctrine.orm.entity_manager" diff --git a/src/Govnokod/CodeBundle/Resources/views/Code/list.html.twig b/src/Govnokod/CodeBundle/Resources/views/Code/list.html.twig index 28a9f8d..10e915a 100644 --- a/src/Govnokod/CodeBundle/Resources/views/Code/list.html.twig +++ b/src/Govnokod/CodeBundle/Resources/views/Code/list.html.twig @@ -2,33 +2,85 @@ {% block content %}
+ +
{% if code.rating > 0 %}+{% elseif code.rating < 0 %}−{% endif %}{{ code.rating|abs }} -
-{{ code.body }}
- - {{ code.description|nl2br }} -
-{# - -#} -
+ {{ code.description|nl2br }} +
+ +