09cdc47f852e714cacfc4e82248e3b1d30e2be9f
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 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;
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 /* Dummy here */
52 $cr= Registry::getInstance("ConfigManager");
53 $cr->setSection($config);
54 $this->headline= $cr->getValue("headline");
55 $this->footer= $cr->getValue("footer");
56 $this->entryFormat= $cr->getValue("entryFormat");
58 /* Load and instanciate classes, extract filter, icons, view hooks, etc. */
59 $this->objects= new ObjectList($config);
60 }
62 /*! \brief Handles _POST / _GET events
64 Processes the list of registered plugins to do their eventHandler and adapt
65 internal objectlist according to this.
66 */
67 public function eventHandler(){
68 /* Reloads the list if things have changed interally */
69 $this->objects->reload();
70 }
73 /*! \brief Renders headline into a string
75 Gets the headline description from the ObjectList object and renders it.
77 \return HTML rendered headline
78 */
79 private function renderHeadline(){
80 # Dummy implementation. Use pre-defined headline.
81 $buffer= $this->headline."\n";
83 #TODO: Make $buffer a proper HTML table output
84 return $buffer;
85 }
88 /*! \brief Renders footer into a string
90 Gets the footer description from the ObjectList object and renders it.
92 \return HTML rendered footer
93 */
94 private function renderFooter(){
95 # Dummy implementation. Use pre-defined footer.
96 $buffer= "|".$this->footer."|";
98 #TODO: Make $buffer a proper HTML table output
99 return $buffer."|\n";
100 }
103 /*! \brief Renders entries from the ObjectList iterator into a string
105 Gets the entry descriptions from the ObjectList object and renders them.
107 \return HTML rendered list entries
108 */
109 private function renderEntry($entry){
111 /* Copy template */
112 $buffer= $this->entryFormat;
114 /* Replace set of attributes */
115 foreach ($this->attributes as $attribute){
116 if (!isset($entry[$attribute])){
117 throw new ObjectListViewportException(sprintf(_("Can't locate attribute '%s' to replace in entry!"), $attribute));
118 } else {
119 $buffer= preg_replace('/\{'.$attribute.'\}/', $entry[$attribute],$buffer);
120 }
121 }
123 /* Execute optional filters */
124 preg_match_all ( '/\{_filter\(([^)]+)\)\}/', $buffer, $matches, PREG_SET_ORDER);
125 foreach ($matches as $match){
126 $filterName= preg_replace('/,.+$/', '', $match[1]);
127 $filterParameter= preg_replace('/^[^,]+,/', '', $match[1]);
128 $buffer= preg_replace('/\{_filter\('.$match[1].'\)\}/', $this->applyEntryFilter($filterName, $filterParameter), $buffer);
129 }
131 #TODO: Make $buffer a proper HTML table output
133 return $buffer."\n";
134 }
137 /*! \brief Applies filter to the given entry format string.
139 Instanciates the given ObjectListEntryFilter and calls the method.
141 \return rendered output
142 \sa ObjectListEntryFilter
143 */
144 private function applyEntryFilter($filterName, $string){
145 $className= "ObjectListEntryFilter_".$filterName;
146 $cl= new $className;
147 return $cl->filter("$string");
148 }
151 /*! \brief Renders complete ObjectList into a string
153 \return HTML rendered list
154 */
155 public function render() {
156 /* Generate fixed headline */
157 $buffer= $this->renderHeadline();
159 /* Apply current filter */
160 $objects= new ObjectListFilterIterator($this->objects->getIterator());
161 foreach ($objects as $value){
162 $buffer.= $this->renderEntry($value);
163 }
165 /* Generate footer */
166 $buffer.= $this->renderFooter();
168 return ($buffer);
169 }
171 }
173 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
174 ?>