Cleanup: Updated copyright comments
[Packages/TYPO3.CMS.git] / typo3 / sysext / recycler / classes / controller / class.tx_recycler_controller_ajax.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009-2011 Julian Kleinhans <typo3@kj187.de>
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 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 // Pre-Include all models and views
26 require_once(t3lib_extMgm::extPath('recycler', 'classes/model/class.tx_recycler_model_deletedRecords.php'));
27 require_once(t3lib_extMgm::extPath('recycler', 'classes/model/class.tx_recycler_model_tables.php'));
28 require_once(t3lib_extMgm::extPath('recycler', 'classes/view/class.tx_recycler_view_deletedRecords.php'));
29 require_once(t3lib_extMgm::extPath('recycler', 'classes/helper/class.tx_recycler_helper.php'));
30
31 /**
32 * Controller class for the 'recycler' extension. Handles the AJAX Requests
33 *
34 * @author Julian Kleinhans <typo3@kj187.de>
35 * @author Erik Frister <erik_frister@otq-solutions.com>
36 * @package TYPO3
37 * @subpackage tx_recycler
38 * @version $Id$
39 */
40 class tx_recycler_controller_ajax {
41 /**
42 * Stores the content for the ajax output
43 *
44 * @var string
45 */
46 protected $content;
47
48 /**
49 * Command to be processed
50 *
51 * @var string
52 */
53 protected $command;
54
55 /**
56 * Stores relevant data from extJS
57 * Example: Json format
58 * [ ["pages",1],["pages",2],["tt_content",34] ]
59 *
60 * @var string
61 */
62 protected $data;
63
64 /**
65 * Initialize method
66 *
67 * @return void
68 */
69 public function init() {
70 $this->mapCommand();
71 $this->getContent();
72 }
73
74 /**
75 * Maps the command to the correct Model and View
76 *
77 * @return void
78 **/
79 public function mapCommand() {
80 $this->command = t3lib_div::_GP('cmd');
81 $this->data = t3lib_div::_GP('data');
82
83 // check params
84 if (!is_string($this->command)) {
85 // @TODO make devlog output
86 return false;
87 }
88
89 // Create content
90 $this->createContent();
91 }
92
93 /**
94 * Creates the content
95 *
96 * @return void
97 **/
98 protected function createContent() {
99 $str = '';
100
101 switch ($this->command) {
102 // Get deleted records
103 case 'getDeletedRecords':
104 $table = ( t3lib_div::_GP('table') ? t3lib_div::_GP('table') : t3lib_div::_GP('tableDefault'));
105 $limit = ( t3lib_div::_GP('limit') ? (int)t3lib_div::_GP('limit') : (int)t3lib_div::_GP('pagingSizeDefault'));
106 $start = ( t3lib_div::_GP('start') ? (int)t3lib_div::_GP('start') : 0);
107 $filter = ( t3lib_div::_GP('filterTxt') ? t3lib_div::_GP('filterTxt') : '');
108 $startUid = ( t3lib_div::_GP('startUid') ? t3lib_div::_GP('startUid') : '');
109 $depth = ( t3lib_div::_GP('depth') ? t3lib_div::_GP('depth') : '');
110 $this->setDataInSession('tableSelection', $table);
111
112 $model = t3lib_div::makeInstance('tx_recycler_model_deletedRecords');
113 $model->loadData($startUid, $table, $depth, $start . ',' . $limit, $filter);
114
115 $deletedRowsArray = $model->getDeletedRows();
116
117 $model = t3lib_div::makeInstance('tx_recycler_model_deletedRecords');
118 $totalDeleted = $model->getTotalCount($startUid, $table, $depth, $filter);
119
120 // load view
121 $view = t3lib_div::makeInstance('tx_recycler_view_deletedRecords');
122 $str = $view->transform($deletedRowsArray, $totalDeleted);
123 break;
124
125 // Delete records
126 case 'doDelete':
127 $str = false;
128 $model = t3lib_div::makeInstance('tx_recycler_model_deletedRecords');
129 if ($model->deleteData($this->data)) {
130 $str = true;
131 }
132 break;
133
134 // Undelete records
135 case 'doUndelete':
136 $str = false;
137 $recursive = t3lib_div::_GP('recursive');
138 $model = t3lib_div::makeInstance('tx_recycler_model_deletedRecords');
139 if ($model->undeleteData($this->data, $recursive)) {
140 $str = true;
141 }
142 break;
143
144 // getTables for menu
145 case 'getTables':
146 $depth = ( t3lib_div::_GP('depth') ? t3lib_div::_GP('depth') : 0);
147 $startUid = ( t3lib_div::_GP('startUid') ? t3lib_div::_GP('startUid') : '');
148 $this->setDataInSession('depthSelection', $depth);
149
150 $model = t3lib_div::makeInstance('tx_recycler_model_tables');
151 $str = $model->getTables('json', 1, $startUid, $depth);
152 break;
153
154 // No cmd
155 default:
156 $str = 'No command was recognized.';
157 break;
158 }
159
160 $this->content = $str;
161 }
162
163 /**
164 * Returns the content that was created in the mapCommand method
165 *
166 * @return string
167 **/
168 public function getContent() {
169 echo $this->content;
170 }
171
172 /**
173 * Sets data in the session of the current backend user.
174 *
175 * @param string $identifier: The identifier to be used to set the data
176 * @param string $data: The data to be stored in the session
177 * @return void
178 */
179 protected function setDataInSession($identifier, $data) {
180 $GLOBALS['BE_USER']->uc['tx_recycler'][$identifier] = $data;
181 $GLOBALS['BE_USER']->writeUC();
182 }
183 }
184
185
186 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/recycler/classes/controller/class.tx_recycler_controller_ajax.php'])) {
187 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/recycler/classes/controller/class.tx_recycler_controller_ajax.php']);
188 }
189
190 ?>