Exemple #1
0
 /**
  * Display block.
  *
  * @param array $blockInfo A blockInfo structure.
  *
  * @return string|void The rendered block.
  */
 public function display($blockInfo)
 {
     // Security check
     if (!SecurityUtil::checkPermission('ZikulaPagesModule:pageslistblock:', "{$blockInfo['title']}::", ACCESS_READ)) {
         return false;
     }
     // Get variables from content block
     $vars = BlockUtil::varsFromContent($blockInfo['content']);
     // Defaults
     if (empty($vars['numitems'])) {
         $vars['numitems'] = 5;
     }
     // Check if the module is available.
     if (!ModUtil::available($this->name)) {
         return false;
     }
     // Call the modules API to get the items
     $pagesManager = new PageCollectionManager($this->get('doctrine.entitymanager'));
     $pagesManager->setItemsPerPage($vars['numitems']);
     $pagesManager->setOrder('lu_date', 'DESC');
     $pages = $pagesManager->get();
     // Check for no items returned
     if (empty($pages)) {
         return false;
     }
     // Call the modules API to get the numitems
     $countitems = count($pages);
     // Compare the numitems with the block setting
     if ($countitems <= $vars['numitems']) {
         $vars['numitems'] = $countitems;
     }
     // Display each item, permissions permitting
     $pageArray = array();
     /** @var \Zikula\PagesModule\Entity\PageEntity $page */
     foreach ($pages as $page) {
         if (SecurityUtil::checkPermission($this->name . '::', "{$page->getTitle()}::{$page->getPageid()}", ACCESS_OVERVIEW)) {
             if (SecurityUtil::checkPermission($this->name . '::', "{$page->getTitle()}::{$page->getPageid()}", ACCESS_READ)) {
                 $pageArray[] = array('url' => $this->get('router')->generate('zikulapagesmodule_user_display', array('urltitle' => $page->getUrltitle())), 'title' => $page['title']);
             } else {
                 $pageArray[] = array('title' => $page['title']);
             }
         }
     }
     $blockInfo['content'] = $this->render('ZikulaPagesModule:Block:pagesListDisplay.html.twig', array('pages' => $pageArray))->getContent();
     return BlockUtil::themeBlock($blockInfo);
 }
Exemple #2
0
 /**
  * @Route("")
  * @Theme("admin")
  *
  * view items
  *
  * @param Request $request
  *
  * @return Response HTML output
  */
 public function indexAction(Request $request)
 {
     // Get parameters
     $startnum = $request->query->get('startnum', 1);
     $orderBy = $request->query->get('orderby', 'pageid');
     $currentSortDirection = $request->query->get('sdir', Column::DIRECTION_DESCENDING);
     $filterForm = $this->createForm(new FilterType(), $request->query->all(), array('action' => $this->generateUrl('zikulapagesmodule_admin_index'), 'method' => 'POST', 'entityCategoryRegistries' => CategoryRegistryUtil::getRegisteredModuleCategories($this->name, 'PageEntity', 'id')));
     $filterForm->handleRequest($request);
     $filterData = $filterForm->isSubmitted() ? $filterForm->getData() : $request->query->all();
     $sortableColumns = new SortableColumns($this->get('router'), 'zikulapagesmodule_admin_index', 'orderby', 'sdir');
     $sortableColumns->addColumn(new Column('pageid'));
     // first added is automatically the default
     $sortableColumns->addColumn(new Column('title'));
     $sortableColumns->addColumn(new Column('cr_date'));
     $sortableColumns->setOrderBy($sortableColumns->getColumn($orderBy), $currentSortDirection);
     $sortableColumns->setAdditionalUrlParameters(array('language' => isset($filterData['language']) ? $filterData['language'] : null, 'filtercats_serialized' => isset($filterData['categories']) ? serialize($filterData['categories']) : null));
     $pages = new PageCollectionManager($this->container->get('doctrine.entitymanager'));
     $pages->setStartNumber($startnum);
     $pages->setItemsPerPage(\ModUtil::getVar($this->name, 'itemsperpage'));
     $pages->setOrder($orderBy, $currentSortDirection);
     $pages->enablePager();
     $pages->setFilterBy($filterData);
     $templateParameters = array();
     $templateParameters['filter_active'] = isset($filterData['category']) && count($filterData['category']) > 0 || !empty($filterData['language']);
     $templateParameters['sort'] = $sortableColumns->generateSortableColumns();
     $templateParameters['pages'] = $pages->get();
     $templateParameters['lang'] = ZLanguage::getLanguageCode();
     $templateParameters['pager'] = $pages->getPager();
     $templateParameters['modvars'] = \ModUtil::getModvars();
     // temporary solution
     $templateParameters['filterForm'] = $filterForm->createView();
     // attempt to disable caching for this only
     $response = new Response();
     $response->expire();
     return $this->render('ZikulaPagesModule:Admin:view.html.twig', $templateParameters, $response);
 }
Exemple #3
0
 /**
  * @Route("/view/{prop}/{cat}/{startnum}", requirements={"startnum" = "^[1-9]\d*$", "cat" = "^[1-9]\d*$"})
  *
  * view page list
  *
  * @param Request $request
  *
  * @throws AccessDeniedException
  *
  * @return Response html string
  */
 public function viewAction(Request $request, $prop, $cat, $startnum = 1)
 {
     if (!SecurityUtil::checkPermission($this->name . '::', '::', ACCESS_OVERVIEW)) {
         throw new AccessDeniedException();
     }
     // @TODO the prop category must be converted to the propId and links adjusted throughout
     // then the CollectionManager must also include this parameter in the search
     $pages = new PageCollectionManager($this->container->get('doctrine.entitymanager'));
     $pages->setStartNumber($startnum);
     $pages->setItemsPerPage(\ModUtil::getVar($this->name, 'itemsperpage'));
     $pages->setOrder('title', 'ASC');
     $pages->setCategory($cat);
     $pages->enablePager();
     $templateParameters = array('startnum' => $startnum, 'category' => CategoryUtil::getCategoryByID($cat), 'lang' => \ZLanguage::getLanguageCode(), 'pages' => $pages->get(), 'pager' => $pages->getPager());
     $request->attributes->set('_legacy', true);
     // forces template to render inside old theme
     return $this->render('ZikulaPagesModule:User:view.html.twig', $templateParameters);
 }