Пример #1
0
 public function render()
 {
     $url = Url::fromRequest();
     $view = $this->view();
     $html = ' <form method="post" class="inline" action="' . $url . '"><input type="text" name="q" style="width: 8em" class="search" value="" placeholder="' . t('Add filter...') . '" /></form>';
     // $html .= $this->renderFilter($this->filter);
     $editorUrl = clone $url;
     $editorUrl->setParam('modifyFilter', true);
     if ($this->filter->isEmpty()) {
         $title = t('Filter this list');
         $txt = $view->icon('plus');
         $remove = '';
     } else {
         $txt = t('Filtered');
         $title = t('Modify this filter');
         $remove = ' <a href="' . Url::fromRequest()->setParams(array()) . '" title="' . t('Remove this filter') . '">' . $view->icon('cancel') . '</a>';
     }
     $filter = $this->filter->isEmpty() ? '' : ': ' . $this->filter;
     $html .= ($filter ? '<p>' : ' ') . '<a href="' . $editorUrl . '" title="' . $title . '">' . $txt . '</a>' . $this->shorten($filter, 72) . $remove . ($filter ? '</p>' : '');
     return $html;
 }
Пример #2
0
 public function renderSearch()
 {
     $html = ' <form method="post" class="search inline dontprint" action="' . $this->preservedUrl() . '"><input type="text" name="q" style="width: 8em" class="search" value="" placeholder="' . t('Search...') . '" /></form>';
     if ($this->filter->isEmpty()) {
         $title = t('Filter this list');
     } else {
         $title = t('Modify this filter');
         if (!$this->filter->isEmpty()) {
             $title .= ': ' . $this->filter;
         }
     }
     return $html . '<a href="' . $this->preservedUrl()->with('modifyFilter', true) . '" aria-label="' . $title . '" title="' . $title . '">' . '<i aria-hidden="true" class="icon-filter"></i>' . '</a>';
 }
 protected function filterChainToArray(Filter $filter)
 {
     if ($filter instanceof FilterAnd) {
         $op = 'and';
     } elseif ($filter instanceof FilterOr) {
         $op = 'or';
     } elseif ($filter instanceof FilterNot) {
         $op = 'not';
     } else {
         throw new QueryException('Cannot render filter: %s', $filter);
     }
     $parts = array($op);
     if (!$filter->isEmpty()) {
         foreach ($filter->filters() as $f) {
             $parts[] = $this->filterToArray($f);
         }
     }
     return $parts;
 }
Пример #4
0
 /**
  * Filter rendering
  *
  * Happens recursively, useful for filters and for Stats expressions
  *
  * @param Filter $filter    The filter that should be rendered
  * @param string $type      Filter type. Usually "Filter" or "Stats"
  * @param int    $level     Nesting level during recursion. Don't touch
  * @param bool   $keylookup Whether to resolve alias names
  *
  * @return string
  */
 protected function renderFilter(Filter $filter, $type = 'Filter', $level = 0, $keylookup = true)
 {
     $str = '';
     if ($filter instanceof FilterChain) {
         if ($filter instanceof FilterAnd) {
             $op = 'And';
         } elseif ($filter instanceof FilterOr) {
             $op = 'Or';
         } elseif ($filter instanceof FilterNot) {
             $op = 'Negate';
         } else {
             throw new IcingaException('Cannot render filter: %s', $filter);
         }
         $parts = array();
         if (!$filter->isEmpty()) {
             foreach ($filter->filters() as $f) {
                 $parts[] = $this->renderFilter($f, $type, $level + 1, $keylookup);
             }
             $str .= implode("\n", $parts);
             if ($type === 'Filter') {
                 if (count($parts) > 1) {
                     $str .= "\n" . $op . ': ' . count($parts);
                 }
             } else {
                 $str .= "\n" . $type . $op . ': ' . count($parts);
             }
         }
     } else {
         $str .= $type . ': ' . $this->renderFilterExpression($filter, $keylookup);
     }
     return $str;
 }
 public function fetchResources(Filter $filter = null, $exported = null)
 {
     if ($filter === null || $filter->isEmpty()) {
         $query = null;
     } else {
         $query = FilterRenderer::forFilter($filter)->toArray();
     }
     if ($exported !== null) {
         if ($query === null) {
             $query = array('=', 'exported', $exported);
         } else {
             $query = array('and', array('=', 'exported', $exported), $query);
         }
     }
     $url = 'resources';
     $columns = array('certname', 'type', 'title', 'exported', 'parameters', 'environment');
     if ($query !== null) {
         if ($this->version === 'v4') {
             $query = array('extract', $columns, $query);
         }
         $url .= '?' . $this->encodeParameter('query', $query);
     }
     $order = array(array('field' => 'type', 'order' => 'asc'), array('field' => 'title', 'order' => 'asc'));
     if ($exported === null) {
         array_unshift($order, array('field' => 'exported', 'order' => 'desc'));
     }
     $url .= '&' . $this->orderBy($order);
     return $this->fetchLimited($url);
 }