Beispiel #1
0
 public function register(Container $container)
 {
     $container['cms.get_post_url_attributes'] = $container->protect(function (Post $post) {
         return ['date' => $post->getCreated()->format('Y/m/d'), 'slug' => $post->getSlug()];
     });
     $container['cms'] = function () use($container) {
         $cms = new CMS($container['em']);
         $postCmsEntity = new CMSEntity(Post::class, PostType::class);
         $postCmsEntity->addColumn('title', function (Post $post) use($container) {
             $href = $container->path('post', $container['cms.get_post_url_attributes']($post));
             return '<a href="' . $href . '">' . $post->getTitle() . '</a>';
         });
         $postCmsEntity->addColumn('slug', 'slug');
         $cms->addCMSEntity($postCmsEntity);
         $pageCmsEntity = new CMSEntity(Page::class, PageType::class);
         $pageCmsEntity->addColumn('title', 'title');
         $pageCmsEntity->addColumn('slug', 'slug');
         $cms->addCMSEntity($pageCmsEntity);
         $menuCMSEntity = new CMSEntity(Menu::class, MenuType::class);
         $menuCMSEntity->addColumn('name', 'name');
         $cms->addCMSEntity($menuCMSEntity);
         $categoryCmsEntity = new CMSEntity(Category::class, CategoryType::class);
         $categoryCmsEntity->addColumn('Name', 'name');
         $cms->addCMSEntity($categoryCmsEntity);
         return $cms;
     };
 }
Beispiel #2
0
 public function listEntityAction(CMSEntity $cmsEntity, Application $app, Request $request)
 {
     $pageNumber = $request->query->has('page') ? $request->query->get('page') : 1;
     $limit = $request->query->has('limit') ? $request->query->get('limit') : $cmsEntity->getDefaultPageLimit();
     $qb = $app['em']->getRepository($cmsEntity->getClass())->createQueryBuilder('e');
     if ($limit && $limit >= 0) {
         $qb->setMaxResults($limit);
         $qb->setFirstResult(($pageNumber - 1) * $limit);
     } else {
         $limit = null;
         $pageNumber = 1;
     }
     $paginator = new Paginator($qb);
     $entities = [];
     foreach ($paginator as $entity) {
         $entities[] = $entity;
     }
     $resultCount = count($paginator);
     $totalPages = $limit && $limit <= $resultCount ? ceil($resultCount / $limit) : 1;
     return $app->render('admin/list.html.twig', ['columns' => $cmsEntity->getColumns(), 'items' => $entities, 'cmsEntity' => $cmsEntity, 'heading' => ucwords($cmsEntity), 'resultCount' => $resultCount, 'currentPage' => $pageNumber, 'limit' => $limit, 'totalPages' => $totalPages]);
 }