/** * Create a new view * * @param ConnectionInterface $connection * @param array $columns */ public function __construct(ConnectionInterface $connection, array $columns = null) { $this->connection = $connection; $this->query = $connection->query($this->getQueryName(), $columns); $this->filter = Filter::matchAll(); $this->init(); }
/** * @return Filter */ public function getFilter() { if ($this->filter === null) { $this->filter = Filter::matchAll(); } return $this->filter; }
/** * {@inheritdoc} */ public function render() { $repo = new AnnouncementIniRepository(); $etag = $repo->getEtag(); $cookie = new AnnouncementCookie(); if ($cookie->getEtag() !== $etag) { $cookie->setEtag($etag); $cookie->setNextActive($repo->findNextActive()); Icinga::app()->getResponse()->setCookie($cookie); } $acked = array(); foreach ($cookie->getAcknowledged() as $hash) { $acked[] = Filter::expression('hash', '!=', $hash); } $acked = Filter::matchAll($acked); $announcements = $repo->findActive(); $announcements->applyFilter($acked); if ($announcements->hasResult()) { $html = '<ul role="alert" id="announcements">'; foreach ($announcements as $announcement) { $ackForm = new AcknowledgeAnnouncementForm(); $ackForm->populate(array('hash' => $announcement->hash)); $html .= '<li><div>' . $this->view()->escape($announcement->message) . '</div>' . $ackForm . '</li>'; } $html .= '</ul>'; return $html; } // Force container update on XHR return '<div style="display: none;"></div>'; }
/** * Constructor * * @param mixed $ds */ public function __construct($ds, $columns = null) { $this->ds = $ds; $this->filter = Filter::matchAll(); if ($columns !== null) { $this->desiredColumns = $columns; } $this->init(); if ($this->desiredColumns !== null) { $this->columns($this->desiredColumns); } }
/** * Create and add elements to this form * * @param array $formData The data sent by the user */ public function createElements(array $formData) { // TODO(jom): Fetching already existing members to prevent the user from mistakenly creating duplicate // memberships (no matter whether the data source permits it or not, a member does never need to be // added more than once) should be kept at backend level (GroupController::fetchUsers) but this does // not work currently as our ldap protocol stuff is unable to handle our filter implementation.. $members = $this->backend->select()->from('group_membership', array('user_name'))->where('group_name', $this->groupName)->fetchColumn(); $filter = empty($members) ? Filter::matchAll() : Filter::not(Filter::where('user_name', $members)); $users = $this->ds->select()->from('user', array('user_name'))->applyFilter($filter)->fetchColumn(); if (!empty($users)) { $this->addElement('multiselect', 'user_name', array('multiOptions' => array_combine($users, $users), 'label' => $this->translate('Backend Users'), 'description' => $this->translate('Select one or more users (fetched from your user backends) to add as group member'), 'class' => 'grant-permissions')); } $this->addElement('textarea', 'users', array('required' => empty($users), 'label' => $this->translate('Users'), 'description' => $this->translate('Provide one or more usernames separated by comma to add as group member'))); $this->setTitle(sprintf($this->translate('Add members for group %s'), $this->groupName)); $this->setSubmitLabel($this->translate('Add')); }
/** * Return the corresponding filter-object * * @returns Filter */ public function getFilter() { $baseFilter = Filter::matchAny(Filter::expression('type', '=', 'hard_state')); if ($this->getValue('objecttype', 'hosts') === 'hosts') { $objectTypeFilter = Filter::expression('object_type', '=', 'host'); } else { $objectTypeFilter = Filter::expression('object_type', '=', 'service'); } $states = array('cnt_down_hard' => Filter::expression('state', '=', '1'), 'cnt_unreachable_hard' => Filter::expression('state', '=', '2'), 'cnt_up' => Filter::expression('state', '=', '0'), 'cnt_critical_hard' => Filter::expression('state', '=', '2'), 'cnt_warning_hard' => Filter::expression('state', '=', '1'), 'cnt_unknown_hard' => Filter::expression('state', '=', '3'), 'cnt_ok' => Filter::expression('state', '=', '0')); $state = $this->getValue('state', 'cnt_critical_hard'); $stateFilter = $states[$state]; if (in_array($state, array('cnt_ok', 'cnt_up'))) { return Filter::matchAll($objectTypeFilter, $stateFilter); } return Filter::matchAll($baseFilter, $objectTypeFilter, $stateFilter); }
/** * {@inheritdoc} */ public function isValid($formData) { if (!parent::isValid($formData)) { return false; } if (($filterString = $this->getValue('filter')) !== null) { $filter = Filter::matchAll(); $filter->setAllowedFilterColumns(array('host_name', 'hostgroup_name', 'instance_name', 'service_description', 'servicegroup_name', 'contact_name', 'contactgroup_name', function ($c) { return preg_match('/^_(?:host|service)_/', $c); })); try { $filter->addFilter(Filter::fromQueryString($filterString)); } catch (QueryException $_) { $this->getElement('filter')->addError(sprintf($this->translate('Invalid filter provided. You can only use the following columns: %s'), implode(', ', array('instance_name', 'host_name', 'hostgroup_name', 'service_description', 'servicegroup_name', 'contact_name', 'contactgroup_name', '_(host|service)_<customvar-name>')))); return false; } } return true; }
protected function applyChanges($changes) { $filter = $this->filter; $pairs = array(); $addTo = null; $add = array(); foreach ($changes as $k => $v) { if (preg_match('/^(column|value|sign|operator)((?:_new)?)_([\\d-]+)$/', $k, $m)) { if ($m[2] === '_new') { if ($addTo !== null && $addTo !== $m[3]) { throw new \Exception('F...U'); } $addTo = $m[3]; $add[$m[1]] = $v; } else { $pairs[$m[3]][$m[1]] = $v; } } } $operators = array(); foreach ($pairs as $id => $fs) { if (array_key_exists('operator', $fs)) { $operators[$id] = $fs['operator']; } else { $f = $filter->getById($id); $f->setColumn($fs['column']); if ($f->getSign() !== $fs['sign']) { if ($f->isRootNode()) { $filter = $f->setSign($fs['sign']); } else { $filter->replaceById($id, $f->setSign($fs['sign'])); } } $f->setExpression($fs['value']); } } krsort($operators, version_compare(PHP_VERSION, '5.4.0') >= 0 ? SORT_NATURAL : SORT_REGULAR); foreach ($operators as $id => $operator) { $f = $filter->getById($id); if ($f->getOperatorName() !== $operator) { if ($f->isRootNode()) { $filter = $f->setOperatorName($operator); } else { $filter->replaceById($id, $f->setOperatorName($operator)); } } } if ($addTo !== null) { if ($addTo === '0') { $filter = Filter::expression($add['column'], $add['sign'], $add['value']); } else { $parent = $filter->getById($addTo); $f = Filter::expression($add['column'], $add['sign'], $add['value']); if (isset($add['operator'])) { switch ($add['operator']) { case 'AND': if ($parent->isExpression()) { if ($parent->isRootNode()) { $filter = Filter::matchAll(clone $parent, $f); } else { $filter = $filter->replaceById($addTo, Filter::matchAll(clone $parent, $f)); } } else { $parent->addFilter(Filter::matchAll($f)); } break; case 'OR': if ($parent->isExpression()) { if ($parent->isRootNode()) { $filter = Filter::matchAny(clone $parent, $f); } else { $filter = $filter->replaceById($addTo, Filter::matchAny(clone $parent, $f)); } } else { $parent->addFilter(Filter::matchAny($f)); } break; case 'NOT': if ($parent->isExpression()) { if ($parent->isRootNode()) { $filter = Filter::not(Filter::matchAll($parent, $f)); } else { $filter = $filter->replaceById($addTo, Filter::not(Filter::matchAll($parent, $f))); } } else { $parent->addFilter(Filter::not($f)); } break; } } else { $parent->addFilter($f); } } } return $filter; }
/** * Remove a group member */ public function removememberAction() { $this->assertPermission('config/authentication/groups/edit'); $this->assertHttpMethod('POST'); $groupName = $this->params->getRequired('group'); $backend = $this->getUserGroupBackend($this->params->getRequired('backend'), 'Icinga\\Data\\Reducible'); $form = new Form(array('onSuccess' => function ($form) use($groupName, $backend) { foreach ($form->getValue('user_name') as $userName) { try { $backend->delete('group_membership', Filter::matchAll(Filter::where('group_name', $groupName), Filter::where('user_name', $userName))); Notification::success(sprintf(t('User "%s" has been removed from group "%s"'), $userName, $groupName)); } catch (NotFoundError $e) { throw $e; } catch (Exception $e) { Notification::error($e->getMessage()); } } $redirect = $form->getValue('redirect'); if (!empty($redirect)) { $form->setRedirectUrl(htmlspecialchars_decode($redirect)); } return true; })); $form->setUidDisabled(); $form->setSubmitLabel('btn_submit'); // Required to ensure that isSubmitted() is called $form->addElement('hidden', 'user_name', array('required' => true, 'isArray' => true)); $form->addElement('hidden', 'redirect'); try { $form->handleRequest(); } catch (NotFoundError $_) { $this->httpNotFound(sprintf($this->translate('Group "%s" not found'), $groupName)); } }
public function init() { $this->hostList = new HostList($this->backend); $this->hostList->addFilter(Filter::matchAll()); $this->getTabs()->add('show', array('title' => 'Show Status Map', 'label' => 'Status Map', 'url' => Url::fromRequest()))->activate('show'); }
/** * Create a new filter that needs to fullfill the base filter and the optional filter (if it exists) * * @param string $url The url to apply the new filter to * @param Filter $filter The base filter * @param Filter $optional The optional filter * * @return Url The altered URL containing the new filter * @throws ProgrammingError */ public static function urlAddFilterOptional($url, $filter, $optional) { $url = Url::fromPath($url); $f = $filter; if (isset($optional)) { $f = Filter::matchAll($filter, $optional); } return $url->setQueryString($f->toQueryString()); }
public function andFilter(Filter $filter) { return Filter::matchAll($this, $filter); }
/** * Returns a Filter that matches all hosts in this HostList * * @param array $columns Override filter column names * * @return Filter */ public function objectsFilter($columns = array('host' => 'host', 'service' => 'service')) { $filterExpression = array(); foreach ($this as $service) { $filterExpression[] = Filter::matchAll(Filter::where($columns['host'], $service->getHost()->getName()), Filter::where($columns['service'], $service->getName())); } return FilterOr::matchAny($filterExpression); }
public function testCloningDeepFilters() { $a = Filter::where('a', 'a1'); $b = Filter::where('b', 'b1'); $c = Filter::matchAll($a, $b); $d = clone $c; $b->setColumn('bb'); $this->assertNotEquals((string) $c, (string) $d); }
/** * Fetch all entries and forecasts by using the dataview associated with this timeline * * @return array The dataview's result */ private function fetchResults() { $hookResults = array(); foreach (Hook::all('timeline') as $timelineProvider) { $hookResults = array_merge($hookResults, $timelineProvider->fetchEntries($this->displayRange), $timelineProvider->fetchForecasts($this->forecastRange)); foreach ($timelineProvider->getIdentifiers() as $identifier => $attributes) { if (!array_key_exists($identifier, $this->identifiers)) { $this->identifiers[$identifier] = $attributes; } } } $query = $this->dataview; $filter = Filter::matchAll(Filter::where('type', array_keys($this->identifiers)), Filter::expression('timestamp', '<=', $this->displayRange->getStart()->getTimestamp()), Filter::expression('timestamp', '>', $this->displayRange->getEnd()->getTimestamp())); $query->applyFilter($filter); return array_merge($query->getQuery()->fetchAll(), $hookResults); }
/** * Set the new Filter of the url to be the current filter and the given filter * * @param Filter $and */ public function addFilter($and) { $this->setQueryString(Filter::matchAll($and, Filter::fromQueryString($this->getQueryString()))->toQueryString()); return $this; }