[TASK] Drag&Drop of Content-Elements in Page-Module
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / View / PageLayout / Extdirect / ExtdirectPageCommands.php
1 <?php
2 namespace TYPO3\CMS\Backend\View\PageLayout\ExtDirect;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2012 Jigal van Hemert <jigal.van.hemert@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29 /**
30 * Commands for the Page module
31 *
32 * @author Jigal van Hemert <jigal.van.hemert@typo3.org>
33 * @package TYPO3
34 */
35 class ExtdirectPageCommands {
36
37 /**
38 * Move content element to a position and/or column.
39 *
40 * Function is called from the Page module javascript.
41 *
42 * @param integer $sourceElement Id attribute of content element which must be moved
43 * @param string $destinationColumn Column to move the content element to
44 * @param integer $destinationElement Id attribute of the element it was dropped on
45 * @return array
46 */
47 public function moveContentElement($sourceElement, $destinationColumn, $destinationElement) {
48 $moveElementUid = 0;
49 $afterElementUid = -1;
50 $targetColumn = 0;
51 $targetPage = 0;
52 list($_, $table, $uid) = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode('-', $sourceElement);
53 if ($table === 'tt_content' && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($uid)) {
54 $moveElementUid = intval($uid);
55 }
56 list($_, $table, $uid) = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode('-', $destinationElement);
57 if ($table === 'tt_content' && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($uid)) {
58 $afterElementUid = intval($uid);
59 } else {
60 // it's dropped in an empty column
61 $afterElementUid = -1;
62 }
63 list($prefix, $column, $prefix2, $page, $_) = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode('-', $destinationColumn);
64 if ($prefix === 'colpos' && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($column) &&
65 $prefix2 === 'page' && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($page)
66 ) {
67 $targetColumn = intval($column);
68 $targetPage = intval($page);
69 }
70 // move to empty column
71 if ($afterElementUid === -1) {
72 $action['cmd']['tt_content'][$moveElementUid]['move'] = $targetPage;
73 } else {
74 $action['cmd']['tt_content'][$moveElementUid]['move'] = -$afterElementUid;
75 }
76
77 $action['data']['tt_content'][$moveElementUid]['colPos'] = $targetColumn;
78
79 \TYPO3\CMS\Core\Utility\GeneralUtility::devLog(
80 'Dragdrop',
81 'core',
82 -1,
83 array (
84 'action' => $action,
85 'sourceElement' => $sourceElement,
86 'destinationColumn' => $destinationColumn,
87 'destinationElement' => $destinationElement,
88 )
89 );
90 /** @var $tce \TYPO3\CMS\Core\DataHandling\DataHandler */
91 $tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
92 $tce->stripslashes_values = 0;
93 $tce->start($action['data'], $action['cmd']);
94 $tce->process_datamap();
95 $tce->process_cmdmap();
96
97 return array('success' => TRUE);
98 }
99 }
100 ?>