170bb002702fd2fb67e9f71be51d5fd52dd1a15c
[Packages/TYPO3.CMS.git] / typo3 / sysext / pagetree / classes / extdirect / class.tx_pagetree_extdirect_tree.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010 TYPO3 Tree Team <http://forge.typo3.org/projects/typo3v4-extjstrees>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 /**
29 * Data Provider of the Page Tree
30 *
31 * @author Stefan Galinski <stefan.galinski@gmail.com>
32 * @package TYPO3
33 * @subpackage tx_pagetree
34 */
35 class tx_pagetree_ExtDirect_Tree extends t3lib_tree_ExtDirect_AbstractExtJsTree {
36 /**
37 * Sets the data provider
38 *
39 * @return void
40 */
41 protected function initDataProvider() {
42 /** @var $dataProvider tx_pagetree_DataProvider */
43 $dataProvider = t3lib_div::makeInstance('tx_pagetree_DataProvider');
44 $this->setDataProvider($dataProvider);
45 }
46
47 /**
48 * Data Provider
49 *
50 * @return tx_pagetree_DataProvider
51 */
52 protected $dataProvider = NULL;
53
54 /**
55 * Returns the root node of the tree
56 *
57 * Not used for the page tree, because the multiple domains/roots feature
58 *
59 * @return array
60 */
61 public function getRoot() {
62 return array();
63 }
64
65 /**
66 * Fetches the next tree level
67 *
68 * @param int $nodeId
69 * @param stdClass $nodeData
70 * @return array
71 */
72 public function getNextTreeLevel($nodeId, $nodeData) {
73 $this->initDataProvider();
74
75 /** @var $node tx_pagetree_Node */
76 $node = t3lib_div::makeInstance('tx_pagetree_Node', (array) $nodeData);
77
78 if ($nodeId === 'root') {
79 $nodeCollection = $this->dataProvider->getTreeMounts();
80 } else {
81 $nodeCollection = $this->dataProvider->getNodes($node);
82 }
83
84 return $nodeCollection->toArray();
85 }
86
87 /**
88 * Returns a tree that only contains elements that match the given search string
89 *
90 * @param string $searchFilter
91 * @return array
92 */
93 public function getFilteredTree($searchFilter) {
94 $this->initDataProvider();
95
96 $nodeCollection = $this->dataProvider->getFilteredNodes($searchFilter);
97
98 return $nodeCollection->toArray();
99 }
100
101 /**
102 * Returns the localized list of doktypes to display
103 *
104 * Note: The list can be filtered by the user typoscript
105 * option "options.pageTree.doktypesToShowInNewPageDragArea".
106 *
107 * @return array
108 */
109 public function getNodeTypes() {
110 $doktypes = t3lib_div::trimExplode(
111 ',', $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.doktypesToShowInNewPageDragArea')
112 );
113
114 $output = array();
115 foreach ($doktypes as $doktype) {
116 $label = $GLOBALS['LANG']->sL('LLL:EXT:pagetree/locallang_pagetree.xml:page.doktype.' . $doktype, TRUE);
117 $spriteIcon = $this->getSpriteIconClasses($GLOBALS['TCA']['pages']['ctrl']['typeicon_classes'][$doktype]);
118
119 $output[] = array(
120 'nodeType' => $doktype,
121 'cls' => 'topPanel-button ' . $spriteIcon,
122 'title' => $label,
123 'tooltip' => $label,
124 );
125 }
126
127 return $output;
128 }
129
130 /**
131 * Returns the sprite icon classes for a given icon
132 *
133 * @param string $icon
134 * @return string
135 */
136 public function getSpriteIconClasses($icon) {
137 return t3lib_iconWorks::getSpriteIconClasses($icon);
138 }
139 }
140
141 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/sysext/pagetree/classes/extdirect/class.tx_pagetree_extdirect_tree.php']) {
142 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/sysext/pagetree/classes/extdirect/class.tx_pagetree_extdirect_tree.php']);
143 }
144
145 ?>