From dcf5368fe18663956aa28fa3ba398e6a40abebc7 Mon Sep 17 00:00:00 2001 From: cajus Date: Fri, 2 Nov 2007 16:53:33 +0000 Subject: [PATCH] Updated methods to have filter instances and attribute replacements git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.6-playground@7722 594d385d-05f5-0310-b6e9-bd551577e9d8 --- include/autoload-data.inc | 4 +- include/class_ObjectList.inc | 8 +-- include/class_ObjectListFilterIterator.inc | 7 ++- include/class_ObjectListViewport.inc | 52 ++++++++++++++++--- include/class_objectListEntryFilter.inc | 16 ++++++ .../class_objectListEntryFilter_uppercase.inc | 17 ++++++ 6 files changed, 88 insertions(+), 16 deletions(-) create mode 100644 include/class_objectListEntryFilter.inc create mode 100644 include/class_objectListEntryFilter_uppercase.inc diff --git a/include/autoload-data.inc b/include/autoload-data.inc index 38a326835..b08c3f543 100644 --- a/include/autoload-data.inc +++ b/include/autoload-data.inc @@ -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 +?> diff --git a/include/class_ObjectList.inc b/include/class_ObjectList.inc index a0ca9e4c9..9185c7b42 100644 --- a/include/class_ObjectList.inc +++ b/include/class_ObjectList.inc @@ -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")), ); } diff --git a/include/class_ObjectListFilterIterator.inc b/include/class_ObjectListFilterIterator.inc index c71bcda91..91cf5b19d 100644 --- a/include/class_ObjectListFilterIterator.inc +++ b/include/class_ObjectListFilterIterator.inc @@ -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; } } diff --git a/include/class_ObjectListViewport.inc b/include/class_ObjectListViewport.inc index 568ea0477..330dbfc6c 100644 --- a/include/class_ObjectListViewport.inc +++ b/include/class_ObjectListViewport.inc @@ -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 index 000000000..218814250 --- /dev/null +++ b/include/class_objectListEntryFilter.inc @@ -0,0 +1,16 @@ + + \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 index 000000000..b538dc912 --- /dev/null +++ b/include/class_objectListEntryFilter_uppercase.inc @@ -0,0 +1,17 @@ + + \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: +?> -- 2.30.2