[TASK] Clean up the phpDoc of t3lib/tree/
[Packages/TYPO3.CMS.git] / t3lib / tree / renderer / class.t3lib_tree_renderer_extjsjson.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010-2011 Steffen Kamper <steffen@typo3.org>
6 * (c) 2010-2011 Steffen Ritter <info@steffen-ritter.net>
7 * All rights reserved
8 *
9 * This script is part of the TYPO3 project. The TYPO3 project is
10 * free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * The GNU General Public License can be found at
16 * http://www.gnu.org/copyleft/gpl.html.
17 * A copy is found in the textfile GPL.txt and important notices to the license
18 * from the author is found in LICENSE.txt distributed with these scripts.
19 *
20 *
21 * This script is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * This copyright notice MUST APPEAR in all copies of the script!
27 ***************************************************************/
28
29
30 /**
31 * Renderer for unordered lists
32 *
33 * @author Steffen Kamper <steffen@typo3.org>
34 * @author Steffen Ritter <info@steffen-ritter.net>
35 * @package TYPO3
36 * @subpackage t3lib
37 */
38 class t3lib_tree_Renderer_ExtJsJson extends t3lib_tree_Renderer_Abstract {
39 /**
40 * recursion level
41 *
42 * @var integer
43 */
44 protected $recursionLevel = 0;
45
46 /**
47 * Renders a node recursive or just a single instance
48 *
49 * @param t3lib_tree_RepresentationNode $node
50 * @param boolean $recursive
51 * @return array
52 */
53 public function renderNode(t3lib_tree_RepresentationNode $node, $recursive = TRUE) {
54 $nodeArray = $this->getNodeArray($node);
55
56 if ($recursive && $node->hasChildNodes()) {
57 $this->recursionLevel++;
58 $children = $this->renderNodeCollection($node->getChildNodes());
59 $nodeArray['children'] = $children;
60 $this->recursionLevel--;
61 }
62
63 return $nodeArray;
64 }
65
66 /**
67 * Get node array
68 *
69 * @param t3lib_tree_RepresentationNode $node
70 * @return array
71 */
72 protected function getNodeArray(t3lib_tree_RepresentationNode $node) {
73 $nodeArray = array(
74 'iconCls' => $node->getIcon(),
75 'text' => $node->getLabel(),
76 'leaf' => !$node->hasChildNodes(),
77 'id' => $node->getId(),
78 'uid' => $node->getId()
79 );
80
81 return $nodeArray;
82 }
83
84 /**
85 * Renders a node collection recursive or just a single instance
86 *
87 * @param t3lib_tree_NodeCollection $node
88 * @param boolean $recursive
89 * @return string
90 */
91 public function renderTree(t3lib_tree_AbstractTree $tree, $recursive = TRUE) {
92 $this->recursionLevel = 0;
93 $children = $this->renderNode($tree->getRoot(), $recursive);
94
95 return json_encode($children);
96 }
97
98 /**
99 * Renders an tree recursive or just a single instance
100 *
101 * @param t3lib_tree_AbstractTree $node
102 * @param boolean $recursive
103 * @return array
104 */
105 public function renderNodeCollection(t3lib_tree_NodeCollection $collection, $recursive = TRUE) {
106 foreach ($collection as $node) {
107 $treeItems[] = $this->renderNode($node, $recursive);
108 }
109 return $treeItems;
110 }
111 }
112
113 ?>