[TASK] Re-work/simplify copyright header in PHP files - Part 8
[Packages/TYPO3.CMS.git] / typo3 / sysext / recycler / Classes / Controller / RecyclerAjaxController.php
1 <?php
2 namespace TYPO3\CMS\Recycler\Controller;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Utility\GeneralUtility;
18
19 /**
20 * Controller class for the 'recycler' extension. Handles the AJAX Requests
21 *
22 * @author Julian Kleinhans <typo3@kj187.de>
23 * @author Erik Frister <erik_frister@otq-solutions.com>
24 */
25 class RecyclerAjaxController {
26
27 /**
28 * Stores the content for the ajax output
29 *
30 * @var string
31 */
32 protected $content;
33
34 /**
35 * Command to be processed
36 *
37 * @var string
38 */
39 protected $command;
40
41 /**
42 * Stores relevant data from extJS
43 * Example: Json format
44 * [ ["pages",1],["pages",2],["tt_content",34] ]
45 *
46 * @var string
47 */
48 protected $data;
49
50 /**
51 * Initialize method
52 *
53 * @return void
54 */
55 public function init() {
56 $this->mapCommand();
57 $this->getContent();
58 }
59
60 /**
61 * Maps the command to the correct Model and View
62 *
63 * @return void
64 */
65 public function mapCommand() {
66 $this->command = GeneralUtility::_GP('cmd');
67 $this->data = GeneralUtility::_GP('data');
68 // check params
69 if (!is_string($this->command)) {
70 // @TODO make devlog output
71 return FALSE;
72 }
73 // Create content
74 $this->createContent();
75 }
76
77 /**
78 * Creates the content
79 *
80 * @return void
81 */
82 protected function createContent() {
83 $str = '';
84 switch ($this->command) {
85 case 'getDeletedRecords':
86 $table = GeneralUtility::_GP('table') ? GeneralUtility::_GP('table') : GeneralUtility::_GP('tableDefault');
87 $limit = GeneralUtility::_GP('limit') ? (int)GeneralUtility::_GP('limit') : (int)GeneralUtility::_GP('pagingSizeDefault');
88 $start = GeneralUtility::_GP('start') ? (int)GeneralUtility::_GP('start') : 0;
89 $filter = GeneralUtility::_GP('filterTxt') ? GeneralUtility::_GP('filterTxt') : '';
90 $startUid = GeneralUtility::_GP('startUid') ? GeneralUtility::_GP('startUid') : '';
91 $depth = GeneralUtility::_GP('depth') ? GeneralUtility::_GP('depth') : '';
92 $this->setDataInSession('tableSelection', $table);
93 $model = GeneralUtility::makeInstance('TYPO3\\CMS\\Recycler\\Domain\\Model\\DeletedRecords');
94 $model->loadData($startUid, $table, $depth, $start . ',' . $limit, $filter);
95 $deletedRowsArray = $model->getDeletedRows();
96 $model = GeneralUtility::makeInstance('TYPO3\\CMS\\Recycler\\Domain\\Model\\DeletedRecords');
97 $totalDeleted = $model->getTotalCount($startUid, $table, $depth, $filter);
98 // load view
99 $view = GeneralUtility::makeInstance('TYPO3\\CMS\\Recycler\\Controller\\DeletedRecordsController');
100 $str = $view->transform($deletedRowsArray, $totalDeleted);
101 break;
102 case 'doDelete':
103 $str = FALSE;
104 $model = GeneralUtility::makeInstance('TYPO3\\CMS\\Recycler\\Domain\\Model\\DeletedRecords');
105 if ($model->deleteData($this->data)) {
106 $str = TRUE;
107 }
108 break;
109 case 'doUndelete':
110 $str = FALSE;
111 $recursive = GeneralUtility::_GP('recursive');
112 $model = GeneralUtility::makeInstance('TYPO3\\CMS\\Recycler\\Domain\\Model\\DeletedRecords');
113 if ($model->undeleteData($this->data, $recursive)) {
114 $str = TRUE;
115 }
116 break;
117 case 'getTables':
118 $depth = GeneralUtility::_GP('depth') ? GeneralUtility::_GP('depth') : 0;
119 $startUid = GeneralUtility::_GP('startUid') ? GeneralUtility::_GP('startUid') : '';
120 $this->setDataInSession('depthSelection', $depth);
121 $model = GeneralUtility::makeInstance('TYPO3\\CMS\\Recycler\\Domain\\Model\\Tables');
122 $str = $model->getTables('json', 1, $startUid, $depth);
123 break;
124 default:
125 $str = 'No command was recognized.';
126 }
127 $this->content = $str;
128 }
129
130 /**
131 * Returns the content that was created in the mapCommand method
132 *
133 * @return string
134 */
135 public function getContent() {
136 echo $this->content;
137 }
138
139 /**
140 * Sets data in the session of the current backend user.
141 *
142 * @param string $identifier: The identifier to be used to set the data
143 * @param string $data: The data to be stored in the session
144 * @return void
145 */
146 protected function setDataInSession($identifier, $data) {
147 $GLOBALS['BE_USER']->uc['tx_recycler'][$identifier] = $data;
148 $GLOBALS['BE_USER']->writeUC();
149 }
150
151 }