TYPO3 CMS  TYPO3_6-2
ExtJsJsonTreeRenderer.php
Go to the documentation of this file.
1 <?php
3 
23 
29  protected $recursionLevel = 0;
30 
38  public function renderNode(\TYPO3\CMS\Backend\Tree\TreeRepresentationNode $node, $recursive = TRUE) {
39  $nodeArray = $this->getNodeArray($node);
40  if ($recursive && $node->hasChildNodes()) {
41  $this->recursionLevel++;
42  $children = $this->renderNodeCollection($node->getChildNodes());
43  $nodeArray['children'] = $children;
44  $this->recursionLevel--;
45  }
46  return $nodeArray;
47  }
48 
55  protected function getNodeArray(\TYPO3\CMS\Backend\Tree\TreeRepresentationNode $node) {
56  $nodeArray = array(
57  'iconCls' => $node->getIcon(),
58  'text' => $node->getLabel(),
59  'leaf' => !$node->hasChildNodes(),
60  'id' => $node->getId(),
61  'uid' => $node->getId()
62  );
63 
64  foreach ($nodeArray as &$nodeItem) {
65  if (is_string($nodeItem)) {
66  $nodeItem = htmlspecialchars($nodeItem);
67  }
68  }
69 
70  return $nodeArray;
71  }
72 
80  public function renderTree(\TYPO3\CMS\Backend\Tree\AbstractTree $tree, $recursive = TRUE) {
81  $this->recursionLevel = 0;
82  $children = $this->renderNode($tree->getRoot(), $recursive);
83  return json_encode($children);
84  }
85 
93  public function renderNodeCollection(\TYPO3\CMS\Backend\Tree\TreeNodeCollection $collection, $recursive = TRUE) {
94  foreach ($collection as $node) {
95  $treeItems[] = $this->renderNode($node, $recursive);
96  }
97  return $treeItems;
98  }
99 
100 }
renderNodeCollection(\TYPO3\CMS\Backend\Tree\TreeNodeCollection $collection, $recursive=TRUE)
renderTree(\TYPO3\CMS\Backend\Tree\AbstractTree $tree, $recursive=TRUE)
getNodeArray(\TYPO3\CMS\Backend\Tree\TreeRepresentationNode $node)
renderNode(\TYPO3\CMS\Backend\Tree\TreeRepresentationNode $node, $recursive=TRUE)