index 693e424c187ace3e761b94494359dd80c0ef5f72..4bf3f5bc89ef52c94cd63fda5580df9f84bc26cb 100644 (file)
\sa ObjectList
*/
-class ObjectListViewport {
+class ObjectListViewport extends GOsaGuiElement {
+
+ /* Internal variable for color alternation */
+ private $colorAlternator= 0;
+
+ protected $headline;
+ protected $footer;
+ protected $entryFormat;
/* Dummy here ----> */
- private $headline;
- private $footer;
- private $entryFormat;
private $attributes= array('cn', '_icon', '_actions', 'dn');
-
/* <---- Dummy here */
+ protected $displayHeaderFlag= TRUE;
+ protected $displayFooterFlag= TRUE;
+ private $numberOfColumns= 0;
+
/*!
\brief Container for objects
This variable stores the ObjectList object to be displayed.
*/
- private $objects;
+ protected $objects;
/*!
\brief Switch to handle multiselect or not
*/
- private $multiselect;
+ protected $multiselect;
- /*! \brief ID used to identify objects of same list */
- private $id = "";
-
/*! \brief ObjectListViewport constructor
The ObjectListViewport class renders/handles the ObjectList defined by $config.
\param config Config section that is used to configure this ObjectListViewport
*/
- public function __construct($config, $multiselect= TRUE){
+ public function __construct($config, $multiselect= TRUE, $displayHeader= TRUE, $displayFooter= FALSE){
+
+ /* Initialize from parents method */
+ parent::__construct();
- $this->multiselect= $multiselect;
- /* Dummy here */
+ /* Transfer initialization values */
+ $this->displayFooterFlag= $displayFooter;
+ $this->displayHeaderFlag= $displayHeader;
+ $this->multiselect= $multiselect;
+
+ /* Load list configuration from ConfigManager */
$cr= Registry::getInstance("ConfigManager");
$cr->setSection($config);
- $this->headline= $this->parseHeadline($cr->getValue("headline"));
+ $this->parseHeadline($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);
-
- /* generate an unique id */
- $this->id = preg_replace("/[^0-9]/","",microtime());
- }
-
- /*! \brief Handles _POST / _GET events
-
- Processes the list of registered plugins to do their eventHandler and adapt
- internal objectlist according to this.
- */
- public function eventHandler(){
- /* Reloads the list if things have changed interally */
- $this->objects->reload();
}
- /*! \brief Renders headline into a string
+ /*! \brief Processes post events
- Gets the headline description from the ObjectList object and renders it.
+ Processes all post events and acts as needed.
- \return HTML rendered headline
+ \return bool for if changes are present or not
*/
- private function renderHeadline(){
- $buffer ="<table class='ObjectListViewport_Header_Table'>\n";
- $buffer.="<tr>\n";
- foreach($this->headline as $key => $value){
- $buffer .= "<td class='ObjectListViewport_Header_Cell' style='".$value['style']."'>".$value['name']."</td>\n";
- }
- $buffer.="<td class='ObjectListViewport_Header_Cell' style='border-right:0px;width:14px;'> </td>";
- $buffer.="</tr>\n";
- $buffer.="</table>\n";
- return $buffer;
- }
-
-
- /*! \brief Renders footer into a string
-
- Gets the footer description from the ObjectList object and renders it.
-
- \return HTML rendered footer
- */
- private function renderFooter(){
- $buffer ="<table class='ObjectListViewport_Footer_Table'>\n";
- $buffer.="<tr>\n";
- $buffer.= "<td class='ObjectListViewport_Footer_Cell' colspan='".count($this->headline)."'>".$this->footer."</td>\n";
- $buffer.="</tr>\n";
- $buffer.="</table>\n";
- return $buffer;
- }
+ protected function __process(){
+ /* FIXME: Dummy Action*/
+ $this->objects->reload();
- private function getEntryIcon($entry,$alt = ""){
- return("<img src='images/".$entry['_icon']."' alt='".$alt."' class='center'>");
+ /* TODO: process input */
+ return FALSE;
}
if (!isset($entry[$attribute])){
throw new ObjectListViewportException(sprintf(_("Can't locate attribute '%s' to replace in entry!"), $attribute));
} else {
-
- if(preg_match("/_icon/i",$attribute)){
- $buffer= preg_replace('/\{'.$attribute.'\}/', $this->getEntryIcon($entry),$buffer);
- }else{
- $buffer= preg_replace('/\{'.$attribute.'\}/', $entry[$attribute],$buffer);
- }
+ $buffer= preg_replace('/\{'.$attribute.'\}/', $entry[$attribute],$buffer);
}
}
foreach ($matches as $match){
$filterName= preg_replace('/,.+$/', '', $match[1]);
$filterParameter= preg_replace('/^[^,]+,/', '', $match[1]);
- $buffer= preg_replace('/\{_filter\('.normalizePreg($match[1]).'\)\}/', $this->applyEntryFilter($filterName, $filterParameter), $buffer);
+ $buffer= preg_replace('/\{_filter\('.normalizePreg($match[1]).'\)\}/',
+ $this->applyEntryFilter($filterName, $filterParameter),
+ $buffer);
}
#TODO: Make $buffer a proper HTML table output
-
$tmp = split("\|",trim($buffer,"|"));
+ $cols = array();
+
+ for($i= 0; $i < $this->numberOfColumns; $i++){
+
+ /* If current entry is the last to appen, then skip adding styles */
+ if($i == ($this->numberOfColumns-1)){
+ $cols[$i]['style1'] = $this->columnInformation[$i]['style'];
+ $cols[$i]['style2'] = "width:100%;overflow:hidden;";
+ $cols[$i]['value'] = $tmp[$i];
+ }else{
+ $cols[$i]['style1'] = $this->columnInformation[$i]['style'];
+ $cols[$i]['style2'] = "width:100%;overflow:hidden;".$this->columnInformation[$i]['style'];
+ $cols[$i]['value'] = $tmp[$i];
+ }
+ }
-
- $buffer="<tr>\n";
- foreach($tmp as $key => $value){
- $buffer .= "<td class='ObjectListViewport_Entry_Cell' style='".$this->headline[$key]['style']."'>".
- "<div style='width:100%;overflow:hidden;".$this->headline[$key]['style']."'>".
- $value.
- "</div>".
- "</td>\n";
+ /* Add class depending on given id, to alternate background colors */
+ if($this->colorAlternator++ & 1){
+ $data['row']['class'] = "ObjectListViewport_Entry_Row1";
+ }else{
+ $data['row']['class'] = "ObjectListViewport_Entry_Row2";
}
- $buffer.="</tr>\n";
- return $buffer."\n";
+ $data['cols'] = $cols;
+ return($data);
}
\return HTML rendered list
*/
- public function render() {
-
- $header = $this->renderHeadline();
- $footer = $this->renderFooter();
+ protected function __render() {
/* Apply current filter */
$entries = "";
$objects= new ObjectListFilterIterator($this->objects->getIterator());
- foreach ($objects as $value){
- $entries .= $this->renderEntry($value);
+ foreach ($objects as $key => $value){
+ $entries[$key] = $this->renderEntry($value);
+ $this->createVariable("OLV_Entry_".$key);
}
- /* Generate fixed headline */
- $buffer = "
- <table class='ObjectListViewport' id='ObjectListViewport".$this->id."' cellspacing=0 cellpadding=0>
- <tr>
- <td>
- <table class='ObjectListViewport_Table' id='ObjectListViewport_Table".$this->id."' cellpadding=0 cellspacing=0 >
- <tr>
- <td class='ObjectListViewport_TD_Header' id='ObjectListViewport_TD_Header".$this->id."'>
- ".$header."
- </td>
- </tr>
- <tr>
- <td class='ObjectListViewport_TD_Entries' id='ObjectListViewport_TD_Entries".$this->id."'>
- <div class='ObjectListViewport_Entry_Cover' id='ObjectListViewport_Entry_Cover".$this->id."'>
- <table class='ObjectListViewport_Entry_Table' id='ObjectListViewport_Entry_Table".$this->id."'>
- ".$entries."
- </table>
- </div>
- </td>
- </tr>
- <tr>
- <td class='ObjectListViewport_TD_Footer' id='ObjectListViewport_TD_Footer".$this->id."'>
- ".$footer."
- </td>
- </tr>
- </table>
-
- </td>
- </tr>
- </table>
-";
-
- return ($buffer);
+ #Fabian: _POST/_GET Variablen bitte mit $this->createVariable('name');
+ # erstellen.
+ # Damit kann das von der übergreifenden Funktion extrahiert werden
+ # und wir haben keinen doppelten Code dafür.
+ #
+ # Wurde z.B. eine Variable via $this->createVariable('cn') erzeugt und via
+ # smarty eingebunden, dann kann Sie nach einem _POST oder _GET via
+ # $this->getRequestVariable_cn() wieder abgefragt werden.
+
+ $smarty = get_smarty();
+ $smarty->assign("OLV_Entries",$entries);
+ $smarty->assign("OLV_List_Id",$this->id);
+ $smarty->assign("OLV_Multiselect_Enabled",$this->multiselect);
+
+ /* Footer variables */
+ $smarty->assign("OLV_Footer_Enabled",$this->displayFooterFlag);
+ $smarty->assign("OLV_Footer_Message",$this->footer);
+ $smarty->assign("OLV_Num_Cols",$this->numberOfColumns);
+
+ /* Assign Headline values */
+ $smarty->assign("OLV_Header_Enabled",$this->displayHeaderFlag);
+ $smarty->assign("OLV_Header",$this->columnInformation);
+
+ return($smarty->fetch("ObjectListViewport.tpl"));
}
/* Each cell definition is seperated by |
* split by and go through each definition
*/
- $tmp = split("\|",trim($data,"|"));
- $cell_formats = array();
- foreach($tmp as $key => $data){
-
- $s_width = "";
- $s_alignment= "";
- $s_name = preg_replace("/\{[^\}]*+\}/","",$data);
- $s_style = "";
+ $this->columnInformation= array();
+ $this->numberOfColumns= 0;
+ $tmp= split("\|", trim($data, "|"));
+ $cell_formats= array();
+
+ foreach($tmp as $key => $dta){
+
+ $width= "";
+ $alignment= "";
+ $name= preg_replace("/\{[^\}]*+\}/", "", $dta);
+ $style= "";
/* Parse format string and detect width & alignment */
- if(preg_match("/\{.*\}/",$data)){
- $s_format= preg_replace("/^[^\{]*+\{([^\}]*).*$/","\\1",$data);
+ if(preg_match("/\{.*\}/", $dta)){
+ $format= preg_replace("/^[^\{]*+\{([^\}]*).*$/", "\\1", $dta);
/* Get aligment */
- if(preg_match("/:/",$s_format)){
- $s_al = preg_replace("/^[^:]*+:([a-z]*).*$/i","\\1",$s_format);
+ if(preg_match("/:/",$format)){
+ $al= preg_replace("/^[^:]*+:([a-z]*).*$/i", "\\1", $format);
- if(preg_match("/T/i",$s_al)){
- $s_alignment.= "top-" ;
- $s_style.= "vertical-align: top;";
+ if(preg_match("/T/i", $al)){
+ $alignment.= "top-";
+ $style.= "vertical-align: top;";
}
- if(preg_match("/B/i",$s_al)){
- $s_alignment.= "bottom-" ;
- $s_style.= "vertical-align: bottom;";
+
+ if(preg_match("/B/i", $al)){
+ $alignment.= "bottom-";
+ $style.= "vertical-align: bottom;";
}
- if(preg_match("/R/i",$s_al)){
- $s_alignment.= "right" ;
- $s_style.= "text-align: right;";
- }elseif(preg_match("/L/i",$s_al)){
- $s_alignment.= "left" ;
- $s_style.= "text-align: left;";
- }elseif(preg_match("/C/i",$s_al) || preg_match("/M/i",$s_al) ){
- $s_alignment.= "center" ;
- $s_style.= "text-align: center;";
+
+ if(preg_match("/R/i", $al)){
+ $alignment.= "right";
+ $style.= "text-align: right;";
+ }elseif(preg_match("/L/i", $al)){
+ $alignment.= "left";
+ $style.= "text-align: left;";
+ }elseif(preg_match("/C/i", $al) || preg_match("/M/i", $al) ){
+ $alignment.= "center";
+ $style.= "text-align: center;";
}
}
/* Get width */
- $s_width = preg_replace("/^([^:]*).*$/","\\1",$s_format);
- if(!empty($s_width)){
- $s_style.= "width: ".$s_width.";";
+ $width = preg_replace("/^([^:]*).*$/","\\1", $format);
+ if(!empty($width)){
+ $style.= "width: ".$width.";";
}
}
- $cell_formats[$key] = array("name" => $s_name, "width" => $s_width, "alignment" => $s_alignment,"style" => $s_style);
+
+ $cell_formats[$key]= array("name" => $name, "width" => $width, "alignment" => $alignment, "style" => $style);
+ $this->numberOfColumns++;
}
- return($cell_formats);
+ $this->columnInformation= $cell_formats;
}
-
-
}
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: