[icinga-checkins] icinga.org: icinga-web/mhein/extlayout: * Added multiple filter columns for static content templates

git at icinga.org git at icinga.org
Fri Apr 23 12:24:13 CEST 2010


Module: icinga-web
Branch: mhein/extlayout
Commit: f9164550b64b93e1c60cb56f491acb499d836793
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=f9164550b64b93e1c60cb56f491acb499d836793

Author: Marius Hein <marius.hein at netways.de>
Date:   Fri Apr 23 12:24:03 2010 +0200

* Added multiple filter columns for static content templates

* Rewritten the dom parser for node index creation

---

 .../models/System/StaticContentModel.class.php     |   68 ++++++++++++++++---
 1 files changed, 57 insertions(+), 11 deletions(-)

diff --git a/app/modules/Cronks/models/System/StaticContentModel.class.php b/app/modules/Cronks/models/System/StaticContentModel.class.php
index 80a9468..4efb2ac 100644
--- a/app/modules/Cronks/models/System/StaticContentModel.class.php
+++ b/app/modules/Cronks/models/System/StaticContentModel.class.php
@@ -22,6 +22,9 @@ class Cronks_System_StaticContentModel extends ICINGACronksBaseModel
 	 */
 	private $dom = false;
 	private $xmlData = array();
+	
+	private static $arrayNodes		= array('filter');
+	private static $indexAttributes	= array('id', 'name');
 
 	public function initialize (AgaviContext $c, array $p=array()) {
 		parent::initialize($c, $p);
@@ -79,6 +82,53 @@ class Cronks_System_StaticContentModel extends ICINGACronksBaseModel
 
 		return $hasChildren;
 	}
+	
+	/**
+	 * Tests if the node contains array to provide an
+	 * array like index
+	 * @param DOMElement $element
+	 * @return boolean
+	 * @author mhein
+	 */
+	private function arrayNode(DOMElement &$element) {
+		return in_array($element->parentNode->nodeName, self::$arrayNodes);
+	}
+	
+	/**
+	 * Returns an index of the dom element
+	 * @param DOMElement $element
+	 * @return mixed
+	 * @author mhein
+	 */
+	private function namedIndex(DOMElement &$element) {
+		foreach (self::$indexAttributes as $attr) {
+			if ($element->hasAttribute($attr)) {
+				return $element->getAttribute($attr);
+			}
+		}
+		return false;
+	}
+	
+	/**
+	 * Returns index value from the dom element
+	 * @param DOMElement $element
+	 * @param integer $fake Fake array counter for loop sequence
+	 * @return mixed
+	 * @author mhein
+	 */
+	private function getDomIndex(DOMElement &$element, &$fake=0) {
+		static $c = 0;
+		
+		$index = $this->namedIndex($element);
+		
+		if (!$index && $this->arrayNode($element)) {
+			$index = $fake++;
+		}
+		elseif (!$index) {
+			$index = $element->nodeName;
+		}	
+		return $index;
+	}
 
 	/**
 	 * converts XML into an associative array
@@ -90,17 +140,12 @@ class Cronks_System_StaticContentModel extends ICINGACronksBaseModel
 		$data = array();
 
 		if ($element->hasChildNodes()) {
+			$count = 0;
 			foreach ($element->childNodes as $child) {
 				if ($child->nodeType == XML_ELEMENT_NODE) {
-					$index = '__BAD_INDEX__';
-					if ($child->hasAttribute('name')) {
-						$index = $child->getAttribute('name');
-					} elseif ($child->nodeName == 'datasource') {
-						$index = $child->getAttribute('id');
-					} else {
-						$index = $child->nodeName;
-					}
-
+					
+					$index = $this->getDomIndex($child, $count);
+					
 					if ($this->hasChildren($child)) {
 						$data[$index] = $this->convertDom($child);
 					} else {
@@ -247,10 +292,11 @@ class Cronks_System_StaticContentModel extends ICINGACronksBaseModel
 			if (array_key_exists('search_type', $dataSource)) {
 				$apiSearch->setSearchType(constant($dataSource['search_type']));
 			}
-
+			
 			// set search filter
-			if (array_key_exists('filter', $dataSource) && array_key_exists('columns', $dataSource['filter'])) {
+			if (array_key_exists('filter', $dataSource) && is_array($dataSource['filter'])) {
 				foreach ($dataSource['filter'] as $filter) {
+					
 					if (!array_key_exists('column', $filter)) {
 						throw new Cronks_System_StaticContentModelException('fetchTemplateValues(): no column defined in filter definition!');
 						$success = false;





More information about the icinga-checkins mailing list