|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2010-2011 Steffen Kamper <steffen@typo3.org> 00006 * (c) 2010-2011 Steffen Ritter <info@steffen-ritter.net> 00007 * All rights reserved 00008 * 00009 * This script is part of the TYPO3 project. The TYPO3 project is 00010 * free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * The GNU General Public License can be found at 00016 * http://www.gnu.org/copyleft/gpl.html. 00017 * A copy is found in the textfile GPL.txt and important notices to the license 00018 * from the author is found in LICENSE.txt distributed with these scripts. 00019 * 00020 * 00021 * This script is distributed in the hope that it will be useful, 00022 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00023 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00024 * GNU General Public License for more details. 00025 * 00026 * This copyright notice MUST APPEAR in all copies of the script! 00027 ***************************************************************/ 00028 00029 00030 /** 00031 * Renderer for unordered lists 00032 * 00033 * @author Steffen Kamper <steffen@typo3.org> 00034 * @author Steffen Ritter <info@steffen-ritter.net> 00035 * @package TYPO3 00036 * @subpackage t3lib 00037 */ 00038 class t3lib_tree_Renderer_ExtJsJson extends t3lib_tree_Renderer_Abstract { 00039 /** 00040 * recursion level 00041 * 00042 * @var int 00043 */ 00044 protected $recursionLevel = 0; 00045 00046 /** 00047 * Renders a node recursive or just a single instance 00048 * 00049 * @param t3lib_tree_RepresentationNode $node 00050 * @param bool $recursive 00051 * @return mixed 00052 */ 00053 public function renderNode(t3lib_tree_RepresentationNode $node, $recursive = TRUE) { 00054 $nodeArray = $this->getNodeArray($node); 00055 00056 if ($recursive && $node->hasChildNodes()) { 00057 $this->recursionLevel++; 00058 $children = $this->renderNodeCollection($node->getChildNodes()); 00059 $nodeArray['children'] = $children; 00060 $this->recursionLevel--; 00061 } 00062 00063 return $nodeArray; 00064 } 00065 00066 /** 00067 * 00068 */ 00069 protected function getNodeArray(t3lib_tree_RepresentationNode $node) { 00070 $nodeArray = array( 00071 'iconCls' => $node->getIcon(), 00072 'text' => $node->getLabel(), 00073 'leaf' => !$node->hasChildNodes(), 00074 'id' => $node->getId(), 00075 'uid' => $node->getId() 00076 ); 00077 00078 return $nodeArray; 00079 } 00080 00081 /** 00082 * Renders a node collection recursive or just a single instance 00083 * 00084 * @param t3lib_tree_NodeCollection $node 00085 * @param bool $recursive 00086 * @return mixed 00087 */ 00088 public function renderTree(t3lib_tree_AbstractTree $tree, $recursive = TRUE) { 00089 $this->recursionLevel = 0; 00090 $children = $this->renderNode($tree->getRoot(), $recursive); 00091 00092 return json_encode($children); 00093 } 00094 00095 /** 00096 * Renders an tree recursive or just a single instance 00097 * 00098 * @param t3lib_tree_AbstractTree $node 00099 * @param bool $recursive 00100 * @return mixed 00101 */ 00102 public function renderNodeCollection(t3lib_tree_NodeCollection $collection, $recursive = TRUE) { 00103 foreach ($collection as $node) { 00104 $treeItems[] = $this->renderNode($node, $recursive); 00105 } 00106 return $treeItems; 00107 } 00108 } 00109 00110 ?>
1.8.0