public function __construct(CronkGridTemplateXmlParser $template, AgaviContext $context, $connection = "icinga") { $this->setTemplate($template); $this->setContext($context); $this->user = $context->getUser()->getNsmUser(); $this->connection = $connection; $view = $this->readDataSourceDefinition(); $source = $template->getSection("datasource"); $this->parser = $context->getModel("Views.ApiDQLView", "Api", array("view" => $view, "parameters" => isset($source["parameters"]) ? $source["parameters"] : array(), "connection" => $connection)); /** * @var IcingaDoctrine_Query */ $this->query = $this->parser->getQuery(); // Allow setting filterPresets if (isset($source["filterPresets"])) { try { $filter = json_decode($source["filterPresets"], true); $filterObj = new IcingaDQLViewFilter(); $query = $filterObj->getDQLFromFilterArray($filter, $this); $this->query->addWhere($query[0], $query[1]); } catch (Exception $e) { AppKitLogger::warn("Ignoring filterpreset : %s", $source["filterPresets"]); } } }
public function toDQL() { $dql = "("; $els = array(); if (empty($this->children)) { return false; } foreach ($this->children as $child) { if (IcingaDQLViewFilter::isGroup($child)) { $keys = array_keys($child); $subEl = new IcingaDQLViewFilterGroup($child[$keys[0]], $keys[0], $this->negate, $this->template); $els[] = $subEl->toDQL(); $this->values = array_merge($this->values, $subEl->getValues()); } else { $subEl = new IcingaDQLViewFilterElement($child, $this->negate, $this->template); $els[] = $subEl->toDQL(); $this->values[] = $subEl->getValue(); } } $cleared = array(); foreach ($els as $element) { if ($element == "") { continue; } $cleared[] = $element; } if (empty($cleared)) { return false; } return "(" . join(" " . $this->type . " ", $cleared) . ")"; }