Code

da9b985084f882b25c048ac7fdce62874a24887e
[gosa.git] / include / class_ObjectListViewport.inc
1 <?php
3 /*! \brief   Exception implementation for ObjectListViewport
4     \author  Cajus Pollmeier <pollmeier@gonicus.de>
5     \version 1.00
6     \date    2007/11/02
8     This class handles the exceptions occuring in ObjectListViewport.
9  */
10 class ObjectListViewportException extends Exception {
11         public function __construct($message, $code = 0) {
12                 parent::__construct($message, $code);
13         }
14 }
15  
17 /*! \brief   Implementation for ObjectListViewport
18     \author  Cajus Pollmeier <pollmeier@gonicus.de>
19     \version 1.00
20     \date    2007/11/02
22     This class handles painting of ObjectList objects.
24     \sa ObjectList
25  */
26 class ObjectListViewport {
28   /* Dummy here ----> */
29   private $headline;
30   private $footer;
31   private $entryFormat;
32   private $attributes= array('cn', '_icon', '_actions', 'dn');
33   /* <---- Dummy here */
35   /*!
36     \brief Container for objects
38     This variable stores the ObjectList object to be displayed.
39    */
40         private $objects;
42   /*!
43     \brief Switch to handle multiselect or not
44    */
45         private $multiselect;
48   /*! \brief ObjectListViewport constructor
50     The ObjectListViewport class renders/handles the ObjectList defined by $config.
52     \param config Config section that is used to configure this ObjectListViewport
53    */
54         public function __construct($config, $multiselect= TRUE){
56         $this->multiselect= $multiselect;
57     /* Dummy here */
58     $cr= Registry::getInstance("ConfigManager");
59     $cr->setSection($config);
60     $this->headline= $cr->getValue("headline");
61     $this->footer= $cr->getValue("footer");
62     $this->entryFormat= $cr->getValue("entryFormat");
64     /* Load and instanciate classes, extract filter, icons, view hooks, etc. */
65     $this->objects= new ObjectList($config);
66   }
68         /*! \brief Handles _POST / _GET events
70             Processes the list of registered plugins to do their eventHandler and adapt
71       internal objectlist according to this.
72          */
73   public function eventHandler(){
74     /* Reloads the list if things have changed interally */
75     $this->objects->reload();
76   }
79         /*! \brief Renders headline into a string
81             Gets the headline description from the ObjectList object and renders it.
83       \return HTML rendered headline
84          */
85   private function renderHeadline(){
86     # Dummy implementation. Use pre-defined headline.
87     $buffer= $this->headline."\n";
89     #TODO: Make $buffer a proper HTML table output
90     return $buffer;
91   }
94         /*! \brief Renders footer into a string
96             Gets the footer description from the ObjectList object and renders it.
98       \return HTML rendered footer
99          */
100   private function renderFooter(){
101     # Dummy implementation. Use pre-defined footer.
102     $buffer= "|".$this->footer."|";
104     #TODO: Make $buffer a proper HTML table output
105     return $buffer."|\n";
106   }
109         /*! \brief Renders entries from the ObjectList iterator into a string
111             Gets the entry descriptions from the ObjectList object and renders them.
113       \return HTML rendered list entries
114          */
115   private function renderEntry($entry){
117     /* Copy template */
118     $buffer= $this->entryFormat;
120     /* Replace set of attributes */
121     foreach ($this->attributes as $attribute){
122       if (!isset($entry[$attribute])){
123         throw new ObjectListViewportException(sprintf(_("Can't locate attribute '%s' to replace in entry!"), $attribute));
124       } else {
125         $buffer= preg_replace('/\{'.$attribute.'\}/', $entry[$attribute],$buffer);
126       }
127     }
129     /* Execute optional filters */
130     preg_match_all ( '/\{_filter\(([^)]+)\)\}/', $buffer, $matches, PREG_SET_ORDER);
131     foreach ($matches as $match){
132       $filterName= preg_replace('/,.+$/', '', $match[1]);
133       $filterParameter= preg_replace('/^[^,]+,/', '', $match[1]);
134       $buffer= preg_replace('/\{_filter\('.$match[1].'\)\}/', $this->applyEntryFilter($filterName, $filterParameter), $buffer);
135     }
137     #TODO: Make $buffer a proper HTML table output
139     return $buffer."\n";
140   }
143         /*! \brief Applies filter to the given entry format string.
145             Instanciates the given ObjectListEntryFilter and calls the method.
147       \return rendered output
148       \sa ObjectListEntryFilter
149          */
150   private function applyEntryFilter($filterName, $string){
151     $className= "ObjectListEntryFilter_".$filterName;
152     $cl= new $className;
153     return $cl->filter("$string");
154   }
157         /*! \brief Renders complete ObjectList into a string
159       \return HTML rendered list
160          */
161   public function render() {
162     /* Generate fixed headline */
163     $buffer= $this->renderHeadline();
165     /* Apply current filter */
166     $objects= new ObjectListFilterIterator($this->objects->getIterator());
167     foreach ($objects as $value){
168       $buffer.= $this->renderEntry($value);
169     }
171     /* Generate footer */
172     $buffer.= $this->renderFooter();
174     return ($buffer);
175   }
179 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
180 ?>