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 postConnect(Doctrine_Event $event) { $invoker = $event->getInvoker(); if (!$invoker instanceof Doctrine_Connection) { AppKitLogger::warn("Couldn't call ConnectionListenerHook, no connection found"); return; } if ($this->initConnectionSql !== null) { AppKitLogger::verbose("Executing connection init command for connection %s : %s", $invoker->getName(), $this->initConnectionSql); } $invoker->setDateFormat($this->dateFormat); $invoker->execute($this->initConnectionSql); }
private function resolveReferenceToken($token, $query) { $results = array(); preg_match_all('/(?P<view>[^\\.\\}]+)\\.(?P<field>[^\\}]+)/', $token, $results); if (count($results["view"]) < 1) { AppKitLogger::warn("Invalid token %s found in view s%, ignoring", $token, $this->view["name"]); return; } for ($i = 0; $i < count($results["field"]); $i++) { // Check if it's a paremeter token if ($results["view"][$i] == 'param') { if (isset($this->viewParameters[$results["field"][$i]])) { $replace = $this->viewParameters[$results["field"][$i]]; } else { AppKitLogger::warn("Missing view parameter %s", $results["field"][$i]); $replace = "''"; } $query = str_replace('${' . $token . '}', $replace, $query); continue; } $field = $results["field"][$i]; $view = $results["view"][$i]; AppKitLogger::verbose("View %s requires field %s from view %s", $this->view["name"], $field, $view); $result = $this->getResultFromViewBuffer($view); if ($result === null) { $result = $this->getContext()->getModel("Views.ApiDQLView", "Api", array("view" => $view))->getResult(); } // aggregate values $resultVals = array(); foreach ($result as $entry) { $resultVals[] = is_int($entry[$field]) ? $entry[$field] : "'" . $entry[$field] . "'"; } if (empty($resultVals)) { $resultVals[] = "-99"; } $query = str_replace('${' . $view . '.' . $field . '}', implode(",", $resultVals), $query); } return $query; }
public function isValidFilterElement($jsonEl) { $required = array("label", "value", "operator", "field"); $valid = true; foreach ($required as $type) { $valid = $valid && isset($jsonEl[$type]); if (!$valid) { AppKitLogger::warn("Missing element: {$type} (%s)", $jsonEl); } } if (!$valid) { return false; } $valid = $valid && isset(self::$OPERATOR_TYPES[$jsonEl["operator"]]); if (!$valid) { AppKitLogger::warn("invalid element %s ", $jsonEl); } return $valid; }
/** * Updates the simple role data * @param NsmRole $role * @param AgaviRequestDataHolder $rd * @return boolean * @author Marius Hein */ public function updateRoleData(NsmRole &$role, AgaviRequestDataHolder &$rd) { AppKitDoctrineUtil::updateRecordsetFromArray($role, $rd->getParameters(), self::$editableAttributes); // Checking the principal if (!$role->NsmPrincipal->principal_id) { $role->NsmPrincipal->principal_type = NsmPrincipal::TYPE_ROLE; } if ($role->role_id === null) { // insert a new role $role->save(); } else { // update role $parts = array(); $params = array(); foreach ($role as $property => $value) { if ($property == "role_id" || !in_array($property, self::$editableAttributes)) { continue; } if ($value === null) { $parts[] = "{$property} = NULL"; } else { $parts[] = "{$property} = ? "; $params[] = $value; } } $params[] = $role->role_id; $dql = "UPDATE NsmRole SET " . implode(",", $parts) . " WHERE role_id = ?"; AppKitLogger::warn("Test: %s - %s", $dql, var_export($params, true)); $query = new Doctrine_Query(); $query->setConnection(AppKitDoctrineUtil::getConnection()); $query->parseDqlQuery($dql); $query->execute($params); } return true; }
private function fetchDQLViews(DOMXPath $xpath) { $dqlRoot = $xpath->query('//ae:configuration/node()'); foreach ($dqlRoot as $node) { if ($node->nodeType != XML_ELEMENT_NODE) { continue; } $this->parseDQLPart($node); } foreach ($this->views as $name => &$vals) { if (!$vals["base"]) { continue; } if (!isset($this->views[$vals["base"]])) { AppKitLogger::warn("View %s references to unknown base query %s", $name, $vals["base"]); continue; } $base = $this->views[$vals["base"]]; $vals = AppKitArrayUtil::replaceRecursive($base, $vals); } }
/** * Sets a pref value * @param string $key * @param mixed $val * @param boolean $overwrite * @param boolean $blob * @return unknown_type * @throws AppKitException * @author Marius Hein */ public function setPref($key, $val, $overwrite = true, $blob = false) { $field = "upref_val"; if ($blob == true) { $field = "upref_longval"; } try { $pref = $this->getPrefObject($key, false, true); // DO NOT OVERWRITE if ($overwrite === false) { return false; } Doctrine_Query::create($this->getContext()->getDatabaseConnection("icinga_web"))->update("NsmUserPreference p")->set($field, "?", $val)->where("p.upref_user_id=? and p.upref_key=?", array($this->user_id, $key))->execute(); if (is_array($pref)) { $pref[$field] = $val; } } catch (AppKitDoctrineException $e) { $pref = new NsmUserPreference(); $pref->upref_key = $key; $pref->{$field} = $val; $pref->NsmUser = $this; $pref->save(); AppKitLogger::warn("New: Setting %s => %s", $key, $pref->toArray(false)); } NsmUser::$cachedPreferences = array(); return true; }