/** * Component for entity list. * * As a component, this action should not return all the html macro, but * only the specific component * * @param Paginator $paginator Paginator instance * @param PaginatorAttributes $paginatorAttributes Paginator Attributes * @param integer $page Page * @param integer $limit Limit of items per page * @param string $orderByField Field to order by * @param string $orderByDirection Direction to order by * * @return array Result * * @Route( * path = "s/component/{page}/{limit}/{orderByField}/{orderByDirection}", * name = "admin_rule_list_component", * requirements = { * "page" = "\d*", * "limit" = "\d*", * }, * defaults = { * "page" = "1", * "limit" = "50", * "orderByField" = "id", * "orderByDirection" = "DESC", * }, * ) * @Template("AdminRuleBundle:Rule:Component/listComponent.html.twig") * @Method({"GET"}) * * @PaginatorAnnotation( * class = "elcodi.entity.rule.class", * page = "~page~", * limit = "~limit~", * orderBy = { * {"x", "~orderByField~", "~orderByDirection~"} * } * ) */ public function listComponentAction(Paginator $paginator, PaginatorAttributes $paginatorAttributes, $page, $limit, $orderByField, $orderByDirection) { return ['paginator' => $paginator, 'page' => $page, 'limit' => $limit, 'orderByField' => $orderByField, 'orderByDirection' => $orderByDirection, 'totalPages' => $paginatorAttributes->getTotalPages(), 'totalElements' => $paginatorAttributes->getTotalElements()]; }
/** * Evaluates Paginator attributes. * * @param Request $request Request * @param AnnotationPaginator $annotation Annotation * @param Paginator $paginator Paginator * @param integer $limitPerPage Limit per page * @param integer $page Page */ protected function evaluateAttributes(Request $request, AnnotationPaginator $annotation, Paginator $paginator, $limitPerPage, $page) { if ($annotation->getAttributes()) { $paginatorAttributes = new PaginatorAttributes(); $total = $paginator->count(); $paginatorAttributes->setCurrentPage($page)->setLimitPerPage($limitPerPage)->setTotalElements($total)->setTotalPages(ceil($total / $limitPerPage)); $request->attributes->set(trim($annotation->getAttributes()), $paginatorAttributes); } }
/** * Component for entity list. * * As a component, this action should not return all the html macro, but * only the specific component * * @param Paginator $paginator Paginator instance * @param PaginatorAttributes $paginatorAttributes Paginator attributes * @param integer $page Page * @param integer $limit Limit of items per page * * @return array Result * * @Route( * path = "s/list/component/{page}/{limit}/{orderByField}/{orderByDirection}", * name = "admin_attribute_list_component", * requirements = { * "page" = "\d*", * "limit" = "\d*", * }, * defaults = { * "page" = "1", * "limit" = "50", * "orderByField" = "id", * "orderByDirection" = "DESC", * }, * methods = {"GET"} * ) * @Template("AdminAttributeBundle:Attribute:listComponent.html.twig") * * @PaginatorAnnotation( * attributes = "paginatorAttributes", * class = "elcodi.entity.attribute.class", * page = "~page~", * limit = "~limit~", * orderBy = { * {"x", "~orderByField~", "~orderByDirection~"}, * }, * ) */ public function listComponentAction(Paginator $paginator, PaginatorAttributes $paginatorAttributes, $page, $limit) { return ['paginator' => $paginator, 'page' => $page, 'limit' => $limit, 'totalPages' => $paginatorAttributes->getTotalPages(), 'totalElements' => $paginatorAttributes->getTotalElements()]; }
/** * Public pagination method * * @\Mmoreram\ControllerExtraBundle\Annotation\Paginator( * attributes = "paginatorAttributes", * class = { * "factory" = "Mmoreram\ControllerExtraBundle\Tests\FakeBundle\Factory\FakeFactory", * "method" = "createNonStatic", * "static" = false * }, * limit = "#limit#", * page = "#page#", * wheres = { * { "x", "id" , "LIKE", "#id#", true } * }, * ) * * @\Mmoreram\ControllerExtraBundle\Annotation\JsonResponse() */ public function paginatorRequestAction(Paginator $paginator, PaginatorAttributes $paginatorAttributes) { return array('count' => $paginator->getIterator()->count(), 'totalPages' => $paginatorAttributes->getTotalPages(), 'totalElements' => $paginatorAttributes->getTotalElements(), 'currentPage' => $paginatorAttributes->getCurrentPage()); }
/** * Home page. * * @param Paginator $paginator * @param PaginatorAttributes $paginatorAttributes * * @return Response Response * * @Route( * path = "/{page}", * name = "store_homepage", * methods = {"GET"}, * requirements = { * "page" = "\d+", * }, * defaults = { * "page" = "1", * }, * ) * * @PaginatorAnnotation( * attributes = "paginatorAttributes", * class = "elcodi.entity.product.class", * page = "~page~", * limit = "6", * wheres = { * {"x", "enabled", "=", true}, * {"x", "showInHome", "=", true}, * }, * orderBy = { * {"x", "updatedAt", "DESC"}, * } * ) * */ public function homeAction(Paginator $paginator, PaginatorAttributes $paginatorAttributes) { return $this->renderTemplate('Pages:home-view.html.twig', ['products' => $paginator, 'currentPage' => $paginatorAttributes->getCurrentPage(), 'totalPages' => $paginatorAttributes->getTotalPages(), 'limitPerPage' => $paginatorAttributes->getLimitPerPage()]); }