Code

Updated methods to have filter instances and attribute replacements
authorcajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 2 Nov 2007 16:53:33 +0000 (16:53 +0000)
committercajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 2 Nov 2007 16:53:33 +0000 (16:53 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.6-playground@7722 594d385d-05f5-0310-b6e9-bd551577e9d8

include/autoload-data.inc
include/class_ObjectList.inc
include/class_ObjectListFilterIterator.inc
include/class_ObjectListViewport.inc
include/class_objectListEntryFilter.inc [new file with mode: 0644]
include/class_objectListEntryFilter_uppercase.inc [new file with mode: 0644]

index 38a3268358d9cc013ab7837c58baa72badc506a7..b08c3f543b3266e57b7e00aa1caff30694f6a46f 100644 (file)
@@ -6,9 +6,11 @@ $class_mapping= array(
                 "AutoloadException" => "include/autoload.inc",
                 "ObjectListException" => "include/class_ObjectList.inc",
                 "ObjectList" => "include/class_ObjectList.inc",
+                "ObjectListEntryFilter" => "include/class_objectListEntryFilter.inc",
+                "ObjectListEntryFilter_uppercase" => "include/class_objectListEntryFilter_uppercase.inc",
                 "ObjectListFilterIterator" => "include/class_ObjectListFilterIterator.inc",
                 "ObjectListViewportException" => "include/class_ObjectListViewport.inc",
                 "ObjectListViewport" => "include/class_ObjectListViewport.inc",
                 "ObjectListIterator" => "include/class_ObjectListIterator.inc",
 );
-?>
\ No newline at end of file
+?>
index a0ca9e4c9ecbf9da8cb350f1dca2ee2ce247c4c2..9185c7b42713f98af0b0c5ce2456180c3318fdc3 100644 (file)
@@ -70,10 +70,10 @@ class ObjectList implements IteratorAggregate {
        private function load(){
     # Crap filling
     $this->objects= array(
-                            array("dn" => "cn=Demo client,ou=systems,dc=gonicus,dc=de", "cn" => "Demo client", "_icon" => "s_terminal.png", "_actions" => "ED"),
-                            array("dn" => "cn=Demo client2,ou=systems,dc=gonicus,dc=de", "cn" => "Demo client2", "_icon" => "s_terminal.png", "_actions" => "ED"),
-                            array("dn" => "cn=Printer,ou=systems,dc=gonicus,dc=de", "cn" => "Printer", "_icon" => "s_printer.png", "_actions" => "ED"),
-                            array("dn" => "cn=Server,ou=systems,dc=gonicus,dc=de", "cn" => "Server", "_icon" => "s_server.png", "_actions" => "ED"),
+                            array("dn" => "cn=Demo client,ou=systems,dc=gonicus,dc=de", "cn" => "Demo client", "_icon" => "s_terminal.png", "_actions" => "ED", "objectClass" => array('gotoWorkstation')),
+                            array("dn" => "cn=Demo client2,ou=systems,dc=gonicus,dc=de", "cn" => "Demo client2", "_icon" => "s_terminal.png", "_actions" => "ED", "objectClass" => array('gotoWorkstation')),
+                            array("dn" => "cn=Printer,ou=systems,dc=gonicus,dc=de", "cn" => "Printer", "_icon" => "s_printer.png", "_actions" => "ED", "objectClass" => array('gotoPrinter')),
+                            array("dn" => "cn=Server,ou=systems,dc=gonicus,dc=de", "cn" => "Server", "_icon" => "s_server.png", "_actions" => "ED", "objectClass" => array("goServer")),
                            );
        }
 
index c71bcda9142e6555185a31e99db72bbde9047f1c..91cf5b19d5e8afde619b202c5861cc5829cf5a70 100644 (file)
@@ -8,16 +8,15 @@
     This class handles filtering of ObjectList iterators.
  */
 class ObjectListFilterIterator extends FilterIterator {
-  private $filter;
  
-  public function __construct(ObjectListIterator $objectListIterator, $filter) {
+  public function __construct(ObjectListIterator $objectListIterator) {
     parent::__construct($objectListIterator);
-    $this->filter = $filter;
   }
  
   public function accept() {
     $current = $this->getInnerIterator()->current();
+
+    /* This is a dummy, currently. Accept everything. */
     return TRUE;
   }
 }
index 568ea0477b707e157780f4b9eb6e5d48f96fcf96..330dbfc6c6cc416a7e8285531476e60809a5fd1c 100644 (file)
@@ -26,8 +26,10 @@ class ObjectListViewportException extends Exception {
 class ObjectListViewport {
 
   # DUMMY values ---->
-  private $headline= "|{16px}|{90%}Name|{64px}Actions|";
+  private $headline= "|{16px}|{90%}Name|{64px:R}Actions|";
   private $footer= "Statistics with no information currently";
+  private $entryFormat= "|{_icon}|{cn} ({_filter(uppercase,{cn})})|{_actions}|";
+  private $attributes= array('cn', '_icon', '_actions', 'dn');
   # <--- DUMMY values.
 
   /*!
@@ -71,6 +73,7 @@ class ObjectListViewport {
     # Dummy implementation. Use pre-defined headline.
     $buffer= $this->headline."\n";
 
+    #TODO: Make $buffer a proper HTML table output
     return $buffer;
   }
 
@@ -83,8 +86,10 @@ class ObjectListViewport {
         */
   private function renderFooter(){
     # Dummy implementation. Use pre-defined footer.
-    $buffer= $this->footer;
-    return "|".$buffer."|\n";
+    $buffer= "|".$this->footer."|";
+
+    #TODO: Make $buffer a proper HTML table output
+    return $buffer."|\n";
   }
 
 
@@ -96,13 +101,46 @@ class ObjectListViewport {
         */
   private function renderEntry($entry){
 
-    # Dummy implenetation. It is interested in icon, cn and action
-    $buffer= "|".$entry['_icon']."|".$entry['cn']."|".$entry['_actions']."|";
+    /* Copy template */
+    $buffer= $this->entryFormat;
+
+    /* Replace set of attributes */
+    foreach ($this->attributes as $attribute){
+      if (!isset($entry[$attribute])){
+        throw new ObjectListViewportException(sprintf(_("Can't locate attribute '%s' to replace in entry!"), $attribute));
+      } else {
+        $buffer= preg_replace('/\{'.$attribute.'\}/', $entry[$attribute],$buffer);
+      }
+    }
+
+    /* Execute optional filters */
+    preg_match_all ( '/\{_filter\(([^)]+)\)\}/', $buffer, $matches, PREG_SET_ORDER);
+    foreach ($matches as $match){
+      $filterName= preg_replace('/,.+$/', '', $match[1]);
+      $filterParameter= preg_replace('/^[^,]+,/', '', $match[1]);
+      $buffer= preg_replace('/\{_filter\('.$match[1].'\)\}/', $this->applyEntryFilter($filterName, $filterParameter), $buffer);
+    }
+
+    #TODO: Make $buffer a proper HTML table output
 
     return $buffer."\n";
   }
 
 
+       /*! \brief Applies filter to the given entry format string.
+
+           Instanciates the given ObjectListEntryFilter and calls the method.
+
+      \return rendered output
+      \sa ObjectListEntryFilter
+        */
+  private function applyEntryFilter($filterName, $string){
+    $className= "ObjectListEntryFilter_".$filterName;
+    $cl= new $className;
+    return $cl->filter("$string");
+  }
+
+
        /*! \brief Renders complete ObjectList into a string
 
       \return HTML rendered list
@@ -112,8 +150,8 @@ class ObjectListViewport {
     $buffer= $this->renderHeadline();
 
     /* Apply current filter */
-    $filterIterator = new ObjectListFilterIterator($this->objects->getIterator(), 'dummy');
-    foreach ($this->objects as $value){
+    $objects= new ObjectListFilterIterator($this->objects->getIterator());
+    foreach ($objects as $value){
       $buffer.= $this->renderEntry($value);
     }
 
diff --git a/include/class_objectListEntryFilter.inc b/include/class_objectListEntryFilter.inc
new file mode 100644 (file)
index 0000000..2188142
--- /dev/null
@@ -0,0 +1,16 @@
+<?php
+
+/*! \brief   Interface for ObjectListEntryFilter objects.
+    \author  Cajus Pollmeier <pollmeier@gonicus.de>
+    \version 1.00
+    \date    2007/11/02
+
+    This interface describes what we need to filter a string
+    for use with list objects.
+ */
+interface ObjectListEntryFilter {
+  static public function filter($string);
+}
+
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
diff --git a/include/class_objectListEntryFilter_uppercase.inc b/include/class_objectListEntryFilter_uppercase.inc
new file mode 100644 (file)
index 0000000..b538dc9
--- /dev/null
@@ -0,0 +1,17 @@
+<?php
+
+/*! \brief   Implements a sample ObjectListEntryFilter interface.
+    \author  Cajus Pollmeier <pollmeier@gonicus.de>
+    \version 1.00
+    \date    2007/11/02
+
+    This class converts entries in lists to upper case.
+ */
+class ObjectListEntryFilter_uppercase implements ObjectListEntryFilter {
+  static public function filter($string) {
+    return strtoupper($string);
+  }
+}
+
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>