TYPO3 CMS  TYPO3_7-6
ExtJsJsonTreeRenderer.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
21 {
27  protected $recursionLevel = 0;
28 
36  public function renderNode(\TYPO3\CMS\Backend\Tree\TreeRepresentationNode $node, $recursive = true)
37  {
38  $nodeArray = $this->getNodeArray($node);
39  if ($recursive && $node->hasChildNodes()) {
40  $this->recursionLevel++;
41  $children = $this->renderNodeCollection($node->getChildNodes());
42  $nodeArray['children'] = $children;
43  $this->recursionLevel--;
44  }
45  return $nodeArray;
46  }
47 
54  protected function getNodeArray(\TYPO3\CMS\Backend\Tree\TreeRepresentationNode $node)
55  {
56  $nodeArray = [
57  'iconTag' => $node->getIcon(),
58  'text' => htmlspecialchars($node->getLabel()),
59  'leaf' => !$node->hasChildNodes(),
60  'id' => htmlspecialchars($node->getId()),
61  'uid' => htmlspecialchars($node->getId())
62  ];
63 
64  return $nodeArray;
65  }
66 
74  public function renderTree(\TYPO3\CMS\Backend\Tree\AbstractTree $tree, $recursive = true)
75  {
76  $this->recursionLevel = 0;
77  $children = $this->renderNode($tree->getRoot(), $recursive);
78  return json_encode($children);
79  }
80 
88  public function renderNodeCollection(\TYPO3\CMS\Backend\Tree\TreeNodeCollection $collection, $recursive = true)
89  {
90  foreach ($collection as $node) {
91  $treeItems[] = $this->renderNode($node, $recursive);
92  }
93  return $treeItems;
94  }
95 }
renderNodeCollection(\TYPO3\CMS\Backend\Tree\TreeNodeCollection $collection, $recursive=true)
renderNode(\TYPO3\CMS\Backend\Tree\TreeRepresentationNode $node, $recursive=true)
getNodeArray(\TYPO3\CMS\Backend\Tree\TreeRepresentationNode $node)
renderTree(\TYPO3\CMS\Backend\Tree\AbstractTree $tree, $recursive=true)