[TASK] Clean up the phpDoc of t3lib/tree/
[Packages/TYPO3.CMS.git] / t3lib / tree / pagetree / extdirect / class.t3lib_tree_pagetree_extdirect_tree.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010-2011 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 t3lib
34 */
35 class t3lib_tree_pagetree_extdirect_Tree extends t3lib_tree_ExtDirect_AbstractExtJsTree {
36 /**
37 * Data Provider
38 *
39 * @var t3lib_tree_pagetree_DataProvider
40 */
41 protected $dataProvider = NULL;
42
43 /**
44 * Sets the data provider
45 *
46 * @return void
47 */
48 protected function initDataProvider() {
49 /** @var $dataProvider t3lib_tree_pagetree_DataProvider */
50 $dataProvider = t3lib_div::makeInstance('t3lib_tree_pagetree_DataProvider');
51 $this->setDataProvider($dataProvider);
52 }
53
54 /**
55 * Returns the root node of the tree
56 *
57 * @return array
58 */
59 public function getRoot() {
60 $this->initDataProvider();
61 $node = $this->dataProvider->getRoot();
62
63 return $node->toArray();
64 }
65
66 /**
67 * Fetches the next tree level
68 *
69 * @param integer $nodeId
70 * @param stdClass $nodeData
71 * @return array
72 */
73 public function getNextTreeLevel($nodeId, $nodeData) {
74 $this->initDataProvider();
75
76 /** @var $node t3lib_tree_pagetree_Node */
77 $node = t3lib_div::makeInstance('t3lib_tree_pagetree_Node', (array) $nodeData);
78
79 if ($nodeId === 'root') {
80 $nodeCollection = $this->dataProvider->getTreeMounts();
81 } else {
82 $nodeCollection = $this->dataProvider->getNodes($node, $node->getMountPoint());
83 }
84
85 return $nodeCollection->toArray();
86 }
87
88 /**
89 * Returns a tree that only contains elements that match the given search string
90 *
91 * @param integer $nodeId
92 * @param stdClass $nodeData
93 * @param string $searchFilter
94 * @return array
95 */
96 public function getFilteredTree($nodeId, $nodeData, $searchFilter) {
97 if (strval($searchFilter) === '') {
98 return array();
99 }
100
101 /** @var $node t3lib_tree_pagetree_Node */
102 $node = t3lib_div::makeInstance('t3lib_tree_pagetree_Node', (array) $nodeData);
103
104 $this->initDataProvider();
105 if ($nodeId === 'root') {
106 $nodeCollection = $this->dataProvider->getTreeMounts($searchFilter);
107 } else {
108 $nodeCollection = $this->dataProvider->getFilteredNodes($node, $searchFilter, $node->getMountPoint());
109 }
110
111 return $nodeCollection->toArray();
112 }
113
114 /**
115 * Returns the localized list of doktypes to display
116 *
117 * Note: The list can be filtered by the user typoscript
118 * option "options.pageTree.doktypesToShowInNewPageDragArea".
119 *
120 * @return array
121 */
122 public function getNodeTypes() {
123 $map = array(
124 1 => 'LLL:EXT:lang/locallang_tca.php:doktype.I.0',
125 3 => 'LLL:EXT:cms/locallang_tca.php:pages.doktype.I.8',
126 4 => 'LLL:EXT:cms/locallang_tca.php:pages.doktype.I.2',
127 6 => 'LLL:EXT:cms/locallang_tca.php:pages.doktype.I.4',
128 7 => 'LLL:EXT:cms/locallang_tca.php:pages.doktype.I.5',
129 199 => 'LLL:EXT:cms/locallang_tca.php:pages.doktype.I.7',
130 254 => 'LLL:EXT:lang/locallang_tca.php:doktype.I.folder',
131 255 => 'LLL:EXT:lang/locallang_tca.php:doktype.I.2'
132 );
133
134 $doktypes = t3lib_div::trimExplode(
135 ',', $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.doktypesToShowInNewPageDragArea')
136 );
137
138 $output = array();
139 $allowedDoktypes = t3lib_div::trimExplode(',', $GLOBALS['BE_USER']->groupData['pagetypes_select']);
140 $isAdmin = $GLOBALS['BE_USER']->isAdmin();
141 foreach ($doktypes as $doktype) {
142 if (!$isAdmin && !in_array($doktype, $allowedDoktypes)) {
143 continue;
144 }
145
146 $label = $GLOBALS['LANG']->sL($map[$doktype], TRUE);
147 $spriteIcon = t3lib_iconWorks::getSpriteIconClasses(
148 $GLOBALS['TCA']['pages']['ctrl']['typeicon_classes'][$doktype]
149 );
150
151 $output[] = array(
152 'nodeType' => $doktype,
153 'cls' => 'typo3-pagetree-topPanel-button',
154 'iconCls' => $spriteIcon,
155 'title' => $label,
156 'tooltip' => $label,
157 );
158 }
159
160 return $output;
161 }
162
163 /**
164 * Returns
165 *
166 * @return array
167 */
168 public function getIndicators() {
169 /** @var $indicatorProvider t3lib_tree_pagetree_Indicator */
170 $indicatorProvider = t3lib_div::makeInstance('t3lib_tree_pagetree_Indicator');
171 $indicatorHtmlArr = $indicatorProvider->getAllIndicators();
172 $indicator = array(
173 'html' => implode(' ', $indicatorHtmlArr),
174 '_COUNT' => count($indicatorHtmlArr)
175 );
176
177 return $indicator;
178 }
179
180 /**
181 * Returns the language labels, sprites and configuration options for the pagetree
182 *
183 * @return void
184 */
185 public function loadResources() {
186 $file = 'LLL:EXT:lang/locallang_core.xml:';
187 $indicators = $this->getIndicators();
188 $configuration = array(
189 'LLL' => array(
190 'copyHint' => $GLOBALS['LANG']->sL($file . 'tree.copyHint', TRUE),
191 'fakeNodeHint' => $GLOBALS['LANG']->sL($file . 'mess.please_wait', TRUE),
192 'activeFilterMode' => $GLOBALS['LANG']->sL($file . 'tree.activeFilterMode', TRUE),
193 'dropToRemove' => $GLOBALS['LANG']->sL($file . 'tree.dropToRemove', TRUE),
194 'buttonRefresh' => $GLOBALS['LANG']->sL($file . 'labels.refresh', TRUE),
195 'buttonNewNode' => $GLOBALS['LANG']->sL($file . 'tree.buttonNewNode', TRUE),
196 'buttonFilter' => $GLOBALS['LANG']->sL($file . 'tree.buttonFilter', TRUE),
197 'dropZoneElementRemoved' => $GLOBALS['LANG']->sL($file . 'tree.dropZoneElementRemoved', TRUE),
198 'dropZoneElementRestored' => $GLOBALS['LANG']->sL($file . 'tree.dropZoneElementRestored', TRUE),
199 'searchTermInfo' => $GLOBALS['LANG']->sL($file . 'tree.searchTermInfo', TRUE),
200 'temporaryMountPointIndicatorInfo' => $GLOBALS['LANG']->sl($file . 'labels.temporaryDBmount', TRUE),
201 'deleteDialogTitle' => $GLOBALS['LANG']->sL('LLL:EXT:cms/layout/locallang.xml:deleteItem', TRUE),
202 'deleteDialogMessage' => $GLOBALS['LANG']->sL('LLL:EXT:cms/layout/locallang.xml:deleteWarning', TRUE),
203 'recursiveDeleteDialogMessage' => $GLOBALS['LANG']->sL('LLL:EXT:cms/layout/locallang.xml:recursiveDeleteWarning', TRUE),
204 ),
205
206 'Configuration' => array(
207 'hideFilter' => $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.hideFilter'),
208 'displayDeleteConfirmation' => $GLOBALS['BE_USER']->jsConfirmation(4),
209 'canDeleteRecursivly' => $GLOBALS['BE_USER']->uc['recursiveDelete'] == TRUE,
210 'disableIconLinkToContextmenu' => $GLOBALS['BE_USER']->getTSConfigVal(
211 'options.pageTree.disableIconLinkToContextmenu'
212 ),
213 'indicator' => $indicators['html'],
214 'temporaryMountPoint' => t3lib_tree_pagetree_Commands::getMountPointPath(),
215 ),
216
217 'Sprites' => array(
218 'Filter' => t3lib_iconWorks::getSpriteIconClasses('actions-system-tree-search-open'),
219 'NewNode' => t3lib_iconWorks::getSpriteIconClasses('actions-page-new'),
220 'Refresh' => t3lib_iconWorks::getSpriteIconClasses('actions-system-refresh'),
221 'InputClear' => t3lib_iconWorks::getSpriteIconClasses('actions-input-clear'),
222 'TrashCan' => t3lib_iconWorks::getSpriteIconClasses('actions-edit-delete'),
223 'TrashCanRestore' => t3lib_iconWorks::getSpriteIconClasses('actions-edit-restore'),
224 'Info' => t3lib_iconWorks::getSpriteIconClasses('actions-document-info'),
225 )
226 );
227
228 return $configuration;
229 }
230 }
231
232 ?>