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 }
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 values ---->
29 private $headline= "|{16px}|{90%}Name|{64px:R}Actions|";
30 private $footer= "Statistics with no information currently";
31 private $entryFormat= "|{_icon}|{cn} ({_filter(uppercase,{cn})})|{_actions}|";
32 private $attributes= array('cn', '_icon', '_actions', 'dn');
33 # <--- DUMMY values.
35 /*!
36 \brief Container for objects
38 This variable stores the ObjectList object to be displayed.
39 */
40 private $objects;
43 /*! \brief ObjectListViewport constructor
45 The ObjectListViewport class renders/handles the ObjectList defined by $config.
47 \param config Config section that is used to configure this ObjectListViewport
48 */
49 public function __construct($config){
51 /* Load and instanciate classes, extract filter, icons, view hooks, etc. */
52 $this->objects= new ObjectList($config);
53 }
55 /*! \brief Handles _POST / _GET events
57 Processes the list of registered plugins to do their eventHandler and adapt
58 internal objectlist according to this.
59 */
60 public function eventHandler(){
61 /* Reloads the list if things have changed interally */
62 $this->objects->reload();
63 }
66 /*! \brief Renders headline into a string
68 Gets the headline description from the ObjectList object and renders it.
70 \return HTML rendered headline
71 */
72 private function renderHeadline(){
73 # Dummy implementation. Use pre-defined headline.
74 $buffer= $this->headline."\n";
76 #TODO: Make $buffer a proper HTML table output
77 return $buffer;
78 }
81 /*! \brief Renders footer into a string
83 Gets the footer description from the ObjectList object and renders it.
85 \return HTML rendered footer
86 */
87 private function renderFooter(){
88 # Dummy implementation. Use pre-defined footer.
89 $buffer= "|".$this->footer."|";
91 #TODO: Make $buffer a proper HTML table output
92 return $buffer."|\n";
93 }
96 /*! \brief Renders entries from the ObjectList iterator into a string
98 Gets the entry descriptions from the ObjectList object and renders them.
100 \return HTML rendered list entries
101 */
102 private function renderEntry($entry){
104 /* Copy template */
105 $buffer= $this->entryFormat;
107 /* Replace set of attributes */
108 foreach ($this->attributes as $attribute){
109 if (!isset($entry[$attribute])){
110 throw new ObjectListViewportException(sprintf(_("Can't locate attribute '%s' to replace in entry!"), $attribute));
111 } else {
112 $buffer= preg_replace('/\{'.$attribute.'\}/', $entry[$attribute],$buffer);
113 }
114 }
116 /* Execute optional filters */
117 preg_match_all ( '/\{_filter\(([^)]+)\)\}/', $buffer, $matches, PREG_SET_ORDER);
118 foreach ($matches as $match){
119 $filterName= preg_replace('/,.+$/', '', $match[1]);
120 $filterParameter= preg_replace('/^[^,]+,/', '', $match[1]);
121 $buffer= preg_replace('/\{_filter\('.$match[1].'\)\}/', $this->applyEntryFilter($filterName, $filterParameter), $buffer);
122 }
124 #TODO: Make $buffer a proper HTML table output
126 return $buffer."\n";
127 }
130 /*! \brief Applies filter to the given entry format string.
132 Instanciates the given ObjectListEntryFilter and calls the method.
134 \return rendered output
135 \sa ObjectListEntryFilter
136 */
137 private function applyEntryFilter($filterName, $string){
138 $className= "ObjectListEntryFilter_".$filterName;
139 $cl= new $className;
140 return $cl->filter("$string");
141 }
144 /*! \brief Renders complete ObjectList into a string
146 \return HTML rendered list
147 */
148 public function render() {
149 /* Generate fixed headline */
150 $buffer= $this->renderHeadline();
152 /* Apply current filter */
153 $objects= new ObjectListFilterIterator($this->objects->getIterator());
154 foreach ($objects as $value){
155 $buffer.= $this->renderEntry($value);
156 }
158 /* Generate footer */
159 $buffer.= $this->renderFooter();
161 return ($buffer);
162 }
164 }
166 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
167 ?>