Merged new PageTree (version for TYPO3 4.5 Beta 3)
[Packages/TYPO3.CMS.git] / typo3 / sysext / pagetree / classes / extdirect / class.tx_pagetree_extdirect_commands.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 * Commands for 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_Commands {
36 /**
37 * Visibly the page
38 *
39 * @param stdClass $nodeData
40 * @return array
41 */
42 public function visiblyNode($nodeData) {
43 /** @var $node tx_pagetree_Node */
44 $node = t3lib_div::makeInstance('tx_pagetree_Node', (array) $nodeData);
45
46 /** @var $dataProvider tx_pagetree_DataProvider */
47 $dataProvider = t3lib_div::makeInstance('tx_pagetree_DataProvider');
48
49 try {
50 tx_pagetree_Commands::visiblyNode($node);
51 $newNode = tx_pagetree_Commands::getNode($node->getId());
52 $newNode->setLeaf($node->isLeafNode());
53 $returnValue = $newNode->toArray();
54 } catch (Exception $exception) {
55 $returnValue = array(
56 'success' => FALSE,
57 'error' => $exception->getMessage(),
58 );
59 }
60
61 return $returnValue;
62 }
63
64 /**
65 * Hide the page
66 *
67 * @param stdClass $nodeData
68 * @return array
69 */
70 public function disableNode($nodeData) {
71 /** @var $node tx_pagetree_Node */
72 $node = t3lib_div::makeInstance('tx_pagetree_Node', (array) $nodeData);
73
74 /** @var $dataProvider tx_pagetree_DataProvider */
75 $dataProvider = t3lib_div::makeInstance('tx_pagetree_DataProvider');
76
77 try {
78 tx_pagetree_Commands::disableNode($node);
79 $newNode = tx_pagetree_Commands::getNode($node->getId());
80 $newNode->setLeaf($node->isLeafNode());
81 $returnValue = $newNode->toArray();
82 } catch (Exception $exception) {
83 $returnValue = array(
84 'success' => FALSE,
85 'message' => $exception->getMessage(),
86 );
87 }
88
89 return $returnValue;
90 }
91
92 /**
93 * Delete the page
94 *
95 * @param stdClass $nodeData
96 * @return array
97 */
98 public function deleteNode($nodeData) {
99 /** @var $node tx_pagetree_Node */
100 $node = t3lib_div::makeInstance('tx_pagetree_Node', (array) $nodeData);
101
102 try {
103 tx_pagetree_Commands::deleteNode($node);
104
105 $returnValue = array();
106 if ($GLOBALS['BE_USER']->workspace) {
107 $record = tx_pagetree_Commands::getNodeRecord($node->getId());
108 if ($record['_ORIG_uid']) {
109 $newNode = tx_pagetree_Commands::getNewNode($record);
110 $returnValue = $newNode->toArray();
111 }
112 }
113 } catch (Exception $exception) {
114 $returnValue = array(
115 'success' => FALSE,
116 'message' => $exception->getMessage(),
117 );
118 }
119
120 return $returnValue;
121 }
122
123 /**
124 * Restore the page
125 *
126 * @param stdClass $nodeData
127 * @param int $destination
128 * @return array
129 */
130 public function restoreNode($nodeData, $destination) {
131 /** @var $node tx_pagetree_Node */
132 $node = t3lib_div::makeInstance('tx_pagetree_Node', (array) $nodeData);
133
134 try {
135 tx_pagetree_Commands::restoreNode($node, $destination);
136 $newNode = tx_pagetree_Commands::getNode($node->getId());
137 $returnValue = $newNode->toArray();
138 } catch (Exception $exception) {
139 $returnValue = array(
140 'success' => FALSE,
141 'message' => $exception->getMessage(),
142 );
143 }
144
145 return $returnValue;
146 }
147
148 /**
149 * Updates the given field with a new text value, may be used to inline update
150 * the title field in the new page tree
151 *
152 * @param stdClass $nodeData
153 * @param string $updatedLabel
154 * @return array
155 */
156 public function updateLabel($nodeData, $updatedLabel) {
157 /** @var $node tx_pagetree_Node */
158 $node = t3lib_div::makeInstance('tx_pagetree_Node', (array) $nodeData);
159
160 try {
161 tx_pagetree_Commands::updateNodeLabel($node, $updatedLabel);
162 $returnValue = array();
163 } catch (Exception $exception) {
164 $returnValue = array(
165 'success' => FALSE,
166 'message' => $exception->getMessage(),
167 );
168 }
169
170 return $returnValue;
171 }
172
173 /**
174 * Sets a temporary mount point
175 *
176 * @param stdClass $nodeData
177 * @return array
178 */
179 public static function setTemporaryMountPoint($nodeData) {
180 /** @var $node tx_pagetree_Node */
181 $node = t3lib_div::makeInstance('tx_pagetree_Node', (array) $nodeData);
182 $GLOBALS['BE_USER']->uc['pageTree_temporaryMountPoint'] = $node->getId();
183 $GLOBALS['BE_USER']->writeUC($GLOBALS['BE_USER']->uc);
184
185 return tx_pagetree_Commands::getMountPointPath();
186 }
187
188 /**
189 * Moves the source node directly as the first child of the destination node
190 *
191 * @param stdClass $nodeData
192 * @param int $destination
193 * @return array
194 */
195 public function moveNodeToFirstChildOfDestination($nodeData, $destination) {
196 /** @var $node tx_pagetree_Node */
197 $node = t3lib_div::makeInstance('tx_pagetree_Node', (array) $nodeData);
198
199 try {
200 tx_pagetree_Commands::moveNode($node, $destination);
201 $newNode = tx_pagetree_Commands::getNode($node->getId(), FALSE);
202 $newNode->setLeaf($node->isLeafNode());
203 $returnValue = $newNode->toArray();
204 } catch (Exception $exception) {
205 $returnValue = array(
206 'success' => FALSE,
207 'message' => $exception->getMessage(),
208 );
209 }
210
211 return $returnValue;
212 }
213
214 /**
215 * Moves the source node directly after the destination node
216 *
217 * @param stdClass $nodeData
218 * @param int $destination
219 * @return void
220 */
221 public function moveNodeAfterDestination($nodeData, $destination) {
222 /** @var $node tx_pagetree_Node */
223 $node = t3lib_div::makeInstance('tx_pagetree_Node', (array) $nodeData);
224
225 try {
226 tx_pagetree_Commands::moveNode($node, -$destination);
227 $newNode = tx_pagetree_Commands::getNode($node->getId(), FALSE);
228 $newNode->setLeaf($node->isLeafNode());
229 $returnValue = $newNode->toArray();
230 } catch (Exception $exception) {
231 $returnValue = array(
232 'success' => FALSE,
233 'message' => $exception->getMessage(),
234 );
235 }
236
237 return $returnValue;
238 }
239
240 /**
241 * Copies the source node directly as the first child of the destination node and
242 * returns the created node.
243 *
244 * @param stdClass $nodeData
245 * @param int $destination
246 * @return array
247 */
248 public function copyNodeToFirstChildOfDestination($nodeData, $destination) {
249 /** @var $node tx_pagetree_Node */
250 $node = t3lib_div::makeInstance('tx_pagetree_Node', (array) $nodeData);
251
252 /** @var $dataProvider tx_pagetree_DataProvider */
253 $dataProvider = t3lib_div::makeInstance('tx_pagetree_DataProvider');
254
255 try {
256 $newPageId = tx_pagetree_Commands::copyNode($node, $destination);
257 $newNode = tx_pagetree_Commands::getNode($newPageId);
258 $newNode->setLeaf($node->isLeafNode());
259 $returnValue = $newNode->toArray();
260 } catch (Exception $exception) {
261 $returnValue = array(
262 'success' => FALSE,
263 'message' => $exception->getMessage(),
264 );
265 }
266
267 return $returnValue;
268 }
269
270 /**
271 * Copies the source node directly after the destination node and returns the
272 * created node.
273 *
274 * @param stdClass $nodeData
275 * @param int $destination
276 * @return array
277 */
278 public function copyNodeAfterDestination($nodeData, $destination) {
279 /** @var $node tx_pagetree_Node */
280 $node = t3lib_div::makeInstance('tx_pagetree_Node', (array) $nodeData);
281
282 /** @var $dataProvider tx_pagetree_DataProvider */
283 $dataProvider = t3lib_div::makeInstance('tx_pagetree_DataProvider');
284
285 try {
286 $newPageId = tx_pagetree_Commands::copyNode($node, -$destination);
287 $newNode = tx_pagetree_Commands::getNode($newPageId);
288 $newNode->setLeaf($node->isLeafNode());
289 $returnValue = $newNode->toArray();
290 } catch (Exception $exception) {
291 $returnValue = array(
292 'success' => FALSE,
293 'message' => $exception->getMessage(),
294 );
295 }
296
297 return $returnValue;
298 }
299
300 /**
301 * Inserts a new node as the first child node of the destination node and returns the created node.
302 *
303 * @param stdClass $parentNodeData
304 * @param int $pageType
305 * @return array
306 */
307 public function insertNodeToFirstChildOfDestination($parentNodeData, $pageType) {
308 /** @var $parentNode tx_pagetree_Node */
309 $parentNode = t3lib_div::makeInstance('tx_pagetree_Node', (array) $parentNodeData);
310
311 try {
312 $newPageId = tx_pagetree_Commands::createNode($parentNode, $parentNode->getId(), $pageType);
313 $returnValue = tx_pagetree_Commands::getNode($newPageId)->toArray();
314 } catch (Exception $exception) {
315 $returnValue = array(
316 'success' => FALSE,
317 'message' => $exception->getMessage(),
318 );
319 }
320
321 return $returnValue;
322 }
323
324 /**
325 * Inserts a new node directly after the destination node and returns the created node.
326 *
327 * @param stdClass $parentNodeData
328 * @param int $destination
329 * @param int $pageType
330 * @return array
331 */
332 public function insertNodeAfterDestination($parentNodeData, $destination, $pageType) {
333 /** @var $parentNode tx_pagetree_Node */
334 $parentNode = t3lib_div::makeInstance('tx_pagetree_Node', (array) $parentNodeData);
335
336 try {
337 $newPageId = tx_pagetree_Commands::createNode($parentNode, -$destination, $pageType);
338 $returnValue = tx_pagetree_Commands::getNode($newPageId)->toArray();
339 } catch (Exception $exception) {
340 $returnValue = array(
341 'success' => FALSE,
342 'message' => $exception->getMessage(),
343 );
344 }
345
346 return $returnValue;
347 }
348
349 /**
350 * Returns the view link of a given node
351 *
352 * @param stdClass $nodeData
353 * @return string
354 */
355 public static function getViewLink($nodeData) {
356 /** @var $node tx_pagetree_Node */
357 $node = t3lib_div::makeInstance('tx_pagetree_Node', (array) $nodeData);
358
359 $javascriptLink = t3lib_BEfunc::viewOnClick($node->getId());
360 preg_match('/window\.open\(\'([^\']+)\'/i', $javascriptLink, $match);
361
362 return $match[1];
363 }
364 }
365
366 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/pagetree/classes/extdirect/class.tx_pagetree_extdirect_commands.php'])) {
367 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/pagetree/classes/extdirect/class.tx_pagetree_extdirect_commands.php']);
368 }
369
370 ?>