Ejemplo n.º 1
0
 /**
  * @covers SortableColumns::generateSortableColumns
  * @covers SortableColumns::setAdditionalUrlParameters
  */
 public function testGenerateSortableColumnsWithAdditionalUrlParameters()
 {
     $expected = ['a' => ['url' => '/foo?x=1&z=0&sort-direction=' . Column::DIRECTION_DESCENDING . '&sort-field=a', 'class' => Column::CSS_CLASS_ASCENDING], 'b' => ['url' => '/foo?x=1&z=0&sort-direction=' . Column::DIRECTION_ASCENDING . '&sort-field=b', 'class' => Column::CSS_CLASS_UNSORTED], 'c' => ['url' => '/foo?x=1&z=0&sort-direction=' . Column::DIRECTION_ASCENDING . '&sort-field=c', 'class' => Column::CSS_CLASS_UNSORTED]];
     $this->sortableColumns->setOrderBy($this->sortableColumns->getColumn('a'), Column::DIRECTION_ASCENDING);
     $this->sortableColumns->setAdditionalUrlParameters(['x' => 1, 'z' => 0]);
     $this->assertEquals($expected, $this->sortableColumns->generateSortableColumns());
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 3
0
 /**
  * @Route("/view")
  * @Theme("admin")
  * @Template
  *
  * View all blocks.
  *
  * @param Request $request
  *
  * @return \Symfony\Component\HttpFoundation\Response symfony response object
  *
  * @throws AccessDeniedException Thrown if the user doesn't have edit permissions to the module
  */
 public function viewAction(Request $request)
 {
     if (!$this->hasPermission('ZikulaBlocksModule::', '::', ACCESS_EDIT)) {
         throw new AccessDeniedException();
     }
     $clear = $request->request->get('clear', 0);
     if ($clear) {
         $request->getSession()->set('zikulablocksmodule.filter', []);
     }
     $sessionFilterData = $request->getSession()->get('zikulablocksmodule.filter', []);
     $sortField = $request->query->get('sort-field', isset($sessionFilterData['sort-field']) ? $sessionFilterData['sort-field'] : 'bid');
     $currentSortDirection = $request->query->get('sort-direction', isset($sessionFilterData['sort-direction']) ? $sessionFilterData['sort-direction'] : Column::DIRECTION_ASCENDING);
     $filterForm = $this->createForm('Zikula\\BlocksModule\\Form\\Type\\AdminViewFilterType', $sessionFilterData, ['action' => $this->generateUrl('zikulablocksmodule_admin_view'), 'method' => 'POST', 'translator' => $this->get('translator'), 'moduleChoices' => $this->get('zikula_blocks_module.api.block')->getModulesContainingBlocks(), 'positionChoices' => $this->getDoctrine()->getRepository('ZikulaBlocksModule:BlockPositionEntity')->getPositionChoiceArray()]);
     $filterFormClone = clone $filterForm;
     $filterForm->handleRequest($request);
     $filterData = $sessionFilterData;
     if ($filterForm->isSubmitted()) {
         if ($filterForm->get('filterButton')->isClicked()) {
             $filterData = $filterForm->getData();
         } else {
             $filterForm = $filterFormClone;
             //  set to empty form on 'clear' submission.
         }
     }
     $filterData['sort-field'] = $sortField;
     $filterData['sort-direction'] = $currentSortDirection;
     $request->getSession()->set('zikulablocksmodule.filter', $filterData);
     // remember
     $sortableColumns = new SortableColumns($this->get('router'), 'zikulablocksmodule_admin_view');
     $sortableColumns->addColumn(new Column('bid'));
     // first added is automatically the default
     $sortableColumns->addColumn(new Column('title'));
     $sortableColumns->addColumn(new Column('blocktype'));
     $sortableColumns->addColumn(new Column('language'));
     $sortableColumns->addColumn(new Column('state'));
     $sortableColumns->setOrderBy($sortableColumns->getColumn($sortField), $currentSortDirection);
     $sortableColumns->setAdditionalUrlParameters(array('position' => isset($filterData['position']) ? $filterData['position'] : null, 'module' => isset($filterData['module']) ? $filterData['module'] : null, 'language' => isset($filterData['language']) ? $filterData['language'] : null, 'status' => isset($filterData['status']) ? $filterData['status'] : null));
     $templateParameters = [];
     $templateParameters['blocks'] = $this->getDoctrine()->getManager()->getRepository('ZikulaBlocksModule:BlockEntity')->getFilteredBlocks($filterData);
     $templateParameters['positions'] = $this->getDoctrine()->getManager()->getRepository('ZikulaBlocksModule:BlockPositionEntity')->findAll();
     $templateParameters['filter_active'] = !empty($filterData['position']) || !empty($filterData['module']) || !empty($filterData['language']) || !empty($filterData['active']) && in_array($filterData['active'], [0, 1]);
     $templateParameters['sort'] = $sortableColumns->generateSortableColumns();
     $templateParameters['filterForm'] = $filterForm->createView();
     return $templateParameters;
 }