/**
  * Apply a restriction on the given data view
  *
  * @param   string      $restriction    The name of restriction
  * @param   Filterable  $filterable     The filterable to restrict
  *
  * @return  Filterable  The filterable
  */
 protected static function applyRestriction($restriction, Filterable $filterable)
 {
     $restrictions = Filter::matchAny();
     foreach (Manager::getInstance()->getRestrictions($restriction) as $filter) {
         $restrictions->addFilter(Filter::fromQueryString($filter));
     }
     $filterable->applyFilter($restrictions);
     return $filterable;
 }
Example #2
0
 /**
  * Apply a restriction on the given data view
  *
  * @param   string      $restriction    The name of restriction
  * @param   Filterable  $view           The filterable to restrict
  *
  * @return  Filterable  The filterable
  */
 protected function applyRestriction($restriction, Filterable $view)
 {
     $restrictions = Filter::matchAny();
     $restrictions->setAllowedFilterColumns(array('host_name', 'hostgroup_name', 'service_description', 'servicegroup_name', function ($c) {
         return preg_match('/^_(?:host|service)_/', $c);
     }));
     foreach ($this->getRestrictions($restriction) as $filter) {
         try {
             $restrictions->addFilter(Filter::fromQueryString($filter));
         } catch (QueryException $e) {
             throw new ConfigurationError($this->translate('Cannot apply restriction %s using the filter %s. You can only use the following columns: %s'), $restriction, $filter, implode(', ', array('host_name', 'hostgroup_name', 'service_description', 'servicegroup_name', '_(host|service)_<customvar-name>')), $e);
         }
     }
     $view->applyFilter($restrictions);
     return $view;
 }
 protected function selectColumn(Filter $filter = null)
 {
     $active = $filter === null ? null : $filter->getColumn();
     if ($this->cachedColumnSelect === null && $this->query === null) {
         return sprintf('<input type="text" name="%s" value="%s" />', $this->elementId('column', $filter), $this->view()->escape($active));
     }
     if ($this->cachedColumnSelect === null && $this->query instanceof FilterColumns) {
         $this->cachedColumnSelect = $this->arrayForSelect($this->query->getFilterColumns(), true);
         asort($this->cachedColumnSelect);
     } elseif ($this->cachedColumnSelect === null) {
         throw new ProgrammingError('No columns set nor does the query provide any');
     }
     $cols = $this->cachedColumnSelect;
     if ($active && !isset($cols[$active])) {
         $cols[$active] = str_replace('_', ' ', ucfirst(ltrim($active, '_')));
     }
     return $this->select($this->elementId('column', $filter), $cols, $active);
 }
Example #4
0
 /**
  * Apply a restriction of the authenticated on the given filterable
  *
  * @param   string      $name       Name of the restriction
  * @param   Filterable  $filterable Filterable to restrict
  *
  * @return  Filterable  The filterable having the restriction applied
  */
 protected function applyRestriction($name, Filterable $filterable)
 {
     $filterable->applyFilter($this->getRestriction($name));
     return $filterable;
 }