From: cajus Date: Wed, 12 Aug 2009 13:13:02 +0000 (+0000) Subject: Updated listing X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=4e0898b471ddafacb43f437f06a596bd3559c28d;p=gosa.git Updated listing git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14038 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-core/include/class_listing.inc b/gosa-core/include/class_listing.inc index aab36da18..f4b6913ac 100644 --- a/gosa-core/include/class_listing.inc +++ b/gosa-core/include/class_listing.inc @@ -11,12 +11,31 @@ class listing { var $summary; var $header= array(); var $colprops= array(); + var $filters= array(); + static $objectTypes; + function listing($filename) { if (!$this->load($filename)) { die("Cannot parse $filename!"); } + + // Register build in filters + $this->registerFilter("objectType", "listing::filterObjectType"); + $this->registerFilter("link", "listing::filterLink"); + $this->registerFilter("actions", "listing::filterActions"); + } + + + function registerFilter($name, $call) + { + if (!isset($this->filters[$name])) { + $this->filters[$name]= $call; + return true; + } + + return false; } @@ -39,6 +58,13 @@ class listing { } } + // Fill objectTypes + if (isset($this->xmlData['definition']['objectType'])) { + foreach ($this->xmlData['definition']['objectType'] as $index => $otype) { + listing::$objectTypes[$otype['objectClass']]= $this->xmlData['definition']['objectType'][$index]; + } + } + // Parse layout per column $this->colprops= $this->parseLayout($this->xmlData['table']['layout']); @@ -60,9 +86,7 @@ class listing { function render() { - #print_a($this->xmlData); - #print_a($this->entries); -echo "Fill summary, handle empty lists differently, alternating
"; +echo "Fill summary, handle empty lists differently, alternating, sorting, post_id
"; $summary= "empty"; // Initialize list @@ -83,29 +107,22 @@ echo "Fill summary, handle empty lists differently, alternating
"; $result.= " "; // New table for the real list contents - $result.= "
"; + $result.= "
"; // Fill with contents - $first= true; - foreach ($this->entries as $entry){ - $result.=""; - foreach ($this->xmlData['table']['column'] as $config) { - if ($first) { - - } else { - } + foreach ($this->entries as $row => $entry){ + $result.=""; + + // Render multi select if needed + if ($this->multiSelect) { + $result.=""; } - $first= false; - } -# for ($i= 0; $i<10; $i++) { -# $result.=""; -# $result.=""; -# $result.=""; -# $result.=""; -# $result.=""; -# $result.=""; -# $result.=""; -# } + + foreach ($this->xmlData['table']['column'] as $index => $config) { + $result.=""; + } + $result.=""; + } // Need to fill the list if it's not full (nobody knows why this is 22 ;-)) if (count($this->entries) < 22) { @@ -174,6 +191,133 @@ echo "Fill summary, handle empty lists differently, alternating
"; return $result; } + + function renderCell($data, $config, $row) + { + // Replace flat attributes in data string + for ($i= 0; $i<$config['count']; $i++) { + $attr= $config[$i]; + $value= ""; + if (is_array($config[$attr])) { + $value= $config[$attr][0]; + } else { + $value= $config[$attr]; + } + $data= preg_replace("/%\{$attr\}/", $value, $data); + } + + // Watch out for filters and prepare to execute them + preg_match_all("/%\{filter:([^(]+)\((.*)\)\}/", $data, $matches, PREG_SET_ORDER); + + foreach ($matches as $match) { + if (!isset($this->filters[$match[1]])) { + continue; + } + $cl= preg_replace('/::.*$/', '', $this->filters[$match[1]]); + $method= preg_replace('/^.*::/', '', $this->filters[$match[1]]); + + // Prepare params for function call + $params= array(); + preg_match_all('/"[^"]+"|[^,]+/', $match[2], $parts); + foreach ($parts[0] as $param) { + + // Row is replaced by the row number + if ($param == "row") { + $params[]= $row; + } + + // pid is replaced by the current post_id + if ($param == "pid") { + #TODO: get post_id + $params[]= "99"; + } + + // Fixie with "" is passed directly + if (preg_match('/^".*"$/', $param)){ + $params[]= preg_replace('/"/', '', $param); + } + + // LDAP variables get replaced by their objects + for ($i= 0; $i<$config['count']; $i++) { + if ($param == $config[$i]) { + $values= $config[$config[$i]]; + if (is_array($values)){ + unset($values['count']); + } + $params[]= $values; + } + } + + // Move dn if needed + if ($param == "dn") { + $params[]= $config["dn"]; + } + } + + // Replace information + $data= preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($cl, $method), $params), $data); + } + + return $data; + } + + + static function filterObjectType($dn, $classes) + { + // Walk thru classes and return on first match + $result= " "; + $prio= 99; + foreach ($classes as $objectClass) { + if (isset(listing::$objectTypes[$objectClass])){ + if (!isset(listing::$objectTypes[$objectClass]["priority"])){ + $result= ""; + return $result; + } + + if (listing::$objectTypes[$objectClass]["priority"] < $prio){ + $prio= listing::$objectTypes[$objectClass]["priority"]; + $result= ""; + } + } + } + + return $result; + } + + + static function filterLink() + { + $result= " "; + + $row= func_get_arg(0); + $pid= func_get_arg(1); + $dn= func_get_arg(2); + $params= array(func_get_arg(3)); + + // Collect sprintf params + for ($i = 4;$i < func_num_args();$i++) { + $val= func_get_arg($i); + if (is_array($val)){ + $params[]= $val[0]; + continue; + } + $params[]= $val; + } + + $result= " "; + $trans= call_user_func_array("sprintf", $params); + if ($trans != "") { + return("$trans"); + } + + return $result; + } + + + static function filterActions() + { + return "TBD"; + } } ?>
 
 Administrativa - [Funktionelle Daten]  
colprops[$index]." class='list0'>".$this->renderCell($config['value'], $entry, $row)."