Code

Added multiselect
[gosa.git] / include / class_ObjectListViewport.inc
index 568ea0477b707e157780f4b9eb6e5d48f96fcf96..da9b985084f882b25c048ac7fdce62874a24887e 100644 (file)
@@ -25,10 +25,12 @@ class ObjectListViewportException extends Exception {
  */
 class ObjectListViewport {
 
-  # DUMMY values ---->
-  private $headline= "|{16px}|{90%}Name|{64px}Actions|";
-  private $footer= "Statistics with no information currently";
-  # <--- DUMMY values.
+  /* Dummy here ----> */
+  private $headline;
+  private $footer;
+  private $entryFormat;
+  private $attributes= array('cn', '_icon', '_actions', 'dn');
+  /* <---- Dummy here */
 
   /*!
     \brief Container for objects
@@ -37,6 +39,11 @@ class ObjectListViewport {
    */
        private $objects;
 
+  /*!
+    \brief Switch to handle multiselect or not
+   */
+       private $multiselect;
+
 
   /*! \brief ObjectListViewport constructor
 
@@ -44,7 +51,15 @@ class ObjectListViewport {
 
     \param config Config section that is used to configure this ObjectListViewport
    */
-       public function __construct($config){
+       public function __construct($config, $multiselect= TRUE){
+
+       $this->multiselect= $multiselect;
+    /* Dummy here */
+    $cr= Registry::getInstance("ConfigManager");
+    $cr->setSection($config);
+    $this->headline= $cr->getValue("headline");
+    $this->footer= $cr->getValue("footer");
+    $this->entryFormat= $cr->getValue("entryFormat");
 
     /* Load and instanciate classes, extract filter, icons, view hooks, etc. */
     $this->objects= new ObjectList($config);
@@ -71,6 +86,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 +99,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 +114,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 +163,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);
     }