wCMF  3.6
 All Classes Namespaces Files Functions Variables Groups Pages
class.TreeViewOutputStrategy.php
Go to the documentation of this file.
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2014 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of any of the following licenses
7  * at your choice:
8  *
9  * - GNU Lesser General Public License (LGPL)
10  * http://www.gnu.org/licenses/lgpl.html
11  * - Eclipse Public License (EPL)
12  * http://www.eclipse.org/org/documents/epl-v10.php
13  *
14  * See the license.txt file distributed with this work for
15  * additional information.
16  *
17  * $Id: class.TreeViewOutputStrategy.php 1462 2014-02-04 23:52:27Z iherwig $
18  */
19 require_once(BASE."wcmf/lib/output/class.OutputStrategy.php");
20 /**
21  * @class TreeViewOutputStrategy
22  * @ingroup Output
23  * @brief This OutputStrategy outputs the object's content in a DHTML Treeview
24  *
25  * @note This OutputStrategy expects the images 'treeview_leaf.gif', 'treeview_minus.gif', 'treeview_plus.gif'
26  * in the directory 'images'
27  * @author ingo herwig <ingo@wemove.com>
28  */
30 {
31  var $_leafOpenTag = '<table border="0"><tr><td width="10"></td><td><img src="images/treeview_leaf.gif" alt="tree leaf" /><a href="javascript:if (nodeClicked) nodeClicked(\'RPL_NODEOID\')"><span> RPL_NODETYPE</span></a><div>';
32  var $_leafCloseTag = '</div></td></tr></table>';
33  var $_nodeOpenTag = '<table border="0"><tr><td width="10"></td><td><a onclick="javascript:toggle(this)" name="toggleButton"><img src="images/treeview_minus.gif" alt="folder closed" /></a><a href="javascript:if (nodeClicked) nodeClicked(\'RPL_NODEOID\')"><span> RPL_NODETYPE</span></a><div>';
34  var $_nodeCloseTag = '</div></td></tr></table>';
35 
36  var $_indent = '';
37  var $_linebreak = "\n";
38  var $_tagsToClose = null;
39  var $_lastIndent = -1;
40 
41  var $_output = '';
42 
43  /**
44  * Constructor.
45  * @param indent The number of spaces to indent.
46  * @param linebreak The linebreak char to use.
47  */
48  function TreeViewOutputStrategy($indent=2, $linebreak="\n")
49  {
50  $this->_indent = str_repeat(' ', $indent);
51  $this->_linebreak = $linebreak;
52  $this->_tagsToClose = array();
53  }
54  /**
55  * Write the treeview header.
56  */
57  function writeHeader()
58  {
59  $this->write('<table border="0"><tr><td>'.$this->_linebreak);
60  }
61  /**
62  * Write the treeview footer.
63  */
64  function writeFooter()
65  {
66  // print remaining open tags
67  $text = '';
68  for ($i=0;$i<sizeOf($this->_tagsToClose);$i++)
69  {
70  $closeTag = $this->_tagsToClose[$i];
71  $text .= str_repeat($this->_indent, $closeTag["indent"]).$closeTag["name"].$this->_linebreak;
72  }
73  $text .= '</tr></td></table>'.$this->_linebreak;
74  $this->write($text);
75  }
76  /**
77  * Write the object's content.
78  * @param obj The object to write.
79  */
80  function writeObject(&$obj)
81  {
82  $text = '';
83  $numChildren = $obj->getNumChildren();
84 
85  $curIndent = $obj->getDepth();
86  if ($curIndent < $this->_lastIndent)
87  {
88  // write last opened and not closed tags
89  for ($i=$this->_lastIndent-$curIndent;$i>0;$i--)
90  {
91  $closeTag = array_shift($this->_tagsToClose);
92  $text .= str_repeat($this->_indent, $closeTag["indent"]).$closeTag["name"].$this->_linebreak;
93  }
94  }
95  // write object's content
96  // make replacement variables for htmltags
97  $title = $obj->getValue('title');
98  if ($title)
99  $title = ": ".$title." ";
100  else
101  $title = " ";
102  $replace = $obj->getType().$title;
103 
104  if ($numChildren == 0)
105  {
106  $openTag = $this->_leafOpenTag;
107  $openTag = ereg_replace("RPL_NODETYPE",$replace,$openTag);
108  $openTag = ereg_replace("RPL_NODEOID",$obj->getOID(),$openTag);
109 
110  $text .= str_repeat($this->_indent, $curIndent).$openTag.$this->_linebreak;
111  $text .= str_repeat($this->_indent, $curIndent).$this->_leafCloseTag.$this->_linebreak;
112  }
113  else
114  {
115  $openTag = $this->_nodeOpenTag;
116  $openTag = ereg_replace("RPL_NODETYPE",$replace,$openTag);
117  $openTag = ereg_replace("RPL_NODEOID",$obj->getOID(),$openTag);
118 
119  $text .= str_repeat($this->_indent, $curIndent).$openTag.$this->_linebreak;
120  $closeTag = array("name" => $this->_nodeCloseTag, "indent" => $curIndent);
121  array_unshift($this->_tagsToClose, $closeTag);
122  }
123  // remember current indent
124  $this->_lastIndent = $curIndent;
125  $this->write($text);
126  }
127  /*
128  * Get the result.
129  */
130  function getResult()
131  {
132  return $this->_output;
133  }
134  /*
135  * Append text to internal variable.
136  */
137  function write($text)
138  {
139  $this->_output .= $text;
140  }
141 }
142 ?>
143 
OutputStrategy is used to write an object's content to a destination (called 'document') using a spec...
TreeViewOutputStrategy($indent=2, $linebreak="\n")
This OutputStrategy outputs the object's content in a DHTML Treeview.