コード例 #1
0
 /**
  * Lists all servicePacks matching a criteria
  */
 public function indexAction()
 {
     // Check permissions
     $sp = new ServicePackModel();
     $this->_helper->allowed('list', $sp);
     // Pagination
     $params = $this->_getPaginatorParams();
     // Filters
     $filters = $this->_mapToFilter($this->_getFilterParams());
     $this->_checkFilterParams($filters, ServicePackFilterFields::getWhiteList());
     $filterList = $this->_spSrv->buildFilterList($filters);
     $this->_helper->filterNotAllowedFilters('filter_by', $filterList);
     // Search
     $spList = $this->_spSrv->listAll($filterList, $params);
     if ($spList) {
         $list = array();
         foreach ($spList->getItems() as $item) {
             try {
                 $this->_helper->allowed('read', $item);
                 $this->_helper->filterNotAllowedFields('read_field', $item);
                 $list[] = $item;
             } catch (Exception $e) {
                 // Do nothing
             }
         }
         // Simulate pagination
         $it = new ArrayIterator($list);
         $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_Iterator($it));
         $paginator->setItemCountPerPage($params['count']);
         // Result
         $iterator = $paginator->getItemsByPage($params['page']);
         $this->view->servicePacks = iterator_to_array($iterator, false);
     }
 }
コード例 #2
0
 /**
  * Builds a filter list based on params.
  * @param  array          $params
  * @return App_ListFilter | null
  */
 public function buildFilterList(array $params, $throwEx = false)
 {
     $factory = new \App_ListFilter_FilterFactory();
     $factory->setWhiteList(ServicePackFilterFields::getWhiteList());
     $factory->setSortingWhiteList(ServicePackFilterFields::getWhiteList());
     $filterList = $factory->constructFilter($params);
     $filterList->setResourceId(ServicePackFilterFields::getResourceId());
     $filterList->setValidators(ServicePackFilterFields::getValidatorSpec());
     $filterList->setThrowExceptionOnValidationFail($throwEx);
     if (!$filterList->isValid()) {
         $filterList = $factory->constructFilter(array());
     }
     $filterList->addExtraData('filterType', 'servicePack');
     \App::log()->debug('Unused filters [' . implode(',', $factory->getUnusedList()) . ']');
     return $filterList;
 }