|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2009-2011 Julian Kleinhans <typo3@kj187.de> 00006 * All rights reserved 00007 * 00008 * This script is part of the TYPO3 project. The TYPO3 project is 00009 * free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * The GNU General Public License can be found at 00015 * http://www.gnu.org/copyleft/gpl.html. 00016 * 00017 * This script is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 * GNU General Public License for more details. 00021 * 00022 * This copyright notice MUST APPEAR in all copies of the script! 00023 ***************************************************************/ 00024 00025 // Pre-Include all models and views 00026 require_once(t3lib_extMgm::extPath('recycler', 'classes/model/class.tx_recycler_model_deletedRecords.php')); 00027 require_once(t3lib_extMgm::extPath('recycler', 'classes/model/class.tx_recycler_model_tables.php')); 00028 require_once(t3lib_extMgm::extPath('recycler', 'classes/view/class.tx_recycler_view_deletedRecords.php')); 00029 require_once(t3lib_extMgm::extPath('recycler', 'classes/helper/class.tx_recycler_helper.php')); 00030 00031 /** 00032 * Controller class for the 'recycler' extension. Handles the AJAX Requests 00033 * 00034 * @author Julian Kleinhans <typo3@kj187.de> 00035 * @author Erik Frister <erik_frister@otq-solutions.com> 00036 * @package TYPO3 00037 * @subpackage tx_recycler 00038 * @version $Id: class.tx_recycler_controller_ajax.php 10120 2011-01-18 20:03:36Z ohader $ 00039 */ 00040 class tx_recycler_controller_ajax { 00041 /** 00042 * Stores the content for the ajax output 00043 * 00044 * @var string 00045 */ 00046 protected $content; 00047 00048 /** 00049 * Command to be processed 00050 * 00051 * @var string 00052 */ 00053 protected $command; 00054 00055 /** 00056 * Stores relevant data from extJS 00057 * Example: Json format 00058 * [ ["pages",1],["pages",2],["tt_content",34] ] 00059 * 00060 * @var string 00061 */ 00062 protected $data; 00063 00064 /** 00065 * Initialize method 00066 * 00067 * @return void 00068 */ 00069 public function init() { 00070 $this->mapCommand(); 00071 $this->getContent(); 00072 } 00073 00074 /** 00075 * Maps the command to the correct Model and View 00076 * 00077 * @return void 00078 **/ 00079 public function mapCommand() { 00080 $this->command = t3lib_div::_GP('cmd'); 00081 $this->data = t3lib_div::_GP('data'); 00082 00083 // check params 00084 if (!is_string($this->command)) { 00085 // @TODO make devlog output 00086 return false; 00087 } 00088 00089 // Create content 00090 $this->createContent(); 00091 } 00092 00093 /** 00094 * Creates the content 00095 * 00096 * @return void 00097 **/ 00098 protected function createContent() { 00099 $str = ''; 00100 00101 switch ($this->command) { 00102 // Get deleted records 00103 case 'getDeletedRecords': 00104 $table = ( t3lib_div::_GP('table') ? t3lib_div::_GP('table') : t3lib_div::_GP('tableDefault')); 00105 $limit = ( t3lib_div::_GP('limit') ? (int)t3lib_div::_GP('limit') : (int)t3lib_div::_GP('pagingSizeDefault')); 00106 $start = ( t3lib_div::_GP('start') ? (int)t3lib_div::_GP('start') : 0); 00107 $filter = ( t3lib_div::_GP('filterTxt') ? t3lib_div::_GP('filterTxt') : ''); 00108 $startUid = ( t3lib_div::_GP('startUid') ? t3lib_div::_GP('startUid') : ''); 00109 $depth = ( t3lib_div::_GP('depth') ? t3lib_div::_GP('depth') : ''); 00110 $this->setDataInSession('tableSelection', $table); 00111 00112 $model = t3lib_div::makeInstance('tx_recycler_model_deletedRecords'); 00113 $model->loadData($startUid, $table, $depth, $start . ',' . $limit, $filter); 00114 00115 $deletedRowsArray = $model->getDeletedRows(); 00116 00117 $model = t3lib_div::makeInstance('tx_recycler_model_deletedRecords'); 00118 $totalDeleted = $model->getTotalCount($startUid, $table, $depth, $filter); 00119 00120 // load view 00121 $view = t3lib_div::makeInstance('tx_recycler_view_deletedRecords'); 00122 $str = $view->transform($deletedRowsArray, $totalDeleted); 00123 break; 00124 00125 // Delete records 00126 case 'doDelete': 00127 $str = false; 00128 $model = t3lib_div::makeInstance('tx_recycler_model_deletedRecords'); 00129 if ($model->deleteData($this->data)) { 00130 $str = true; 00131 } 00132 break; 00133 00134 // Undelete records 00135 case 'doUndelete': 00136 $str = false; 00137 $recursive = t3lib_div::_GP('recursive'); 00138 $model = t3lib_div::makeInstance('tx_recycler_model_deletedRecords'); 00139 if ($model->undeleteData($this->data, $recursive)) { 00140 $str = true; 00141 } 00142 break; 00143 00144 // getTables for menu 00145 case 'getTables': 00146 $depth = ( t3lib_div::_GP('depth') ? t3lib_div::_GP('depth') : 0); 00147 $startUid = ( t3lib_div::_GP('startUid') ? t3lib_div::_GP('startUid') : ''); 00148 $this->setDataInSession('depthSelection', $depth); 00149 00150 $model = t3lib_div::makeInstance('tx_recycler_model_tables'); 00151 $str = $model->getTables('json', 1, $startUid, $depth); 00152 break; 00153 00154 // No cmd 00155 default: 00156 $str = 'No command was recognized.'; 00157 break; 00158 } 00159 00160 $this->content = $str; 00161 } 00162 00163 /** 00164 * Returns the content that was created in the mapCommand method 00165 * 00166 * @return string 00167 **/ 00168 public function getContent() { 00169 echo $this->content; 00170 } 00171 00172 /** 00173 * Sets data in the session of the current backend user. 00174 * 00175 * @param string $identifier: The identifier to be used to set the data 00176 * @param string $data: The data to be stored in the session 00177 * @return void 00178 */ 00179 protected function setDataInSession($identifier, $data) { 00180 $GLOBALS['BE_USER']->uc['tx_recycler'][$identifier] = $data; 00181 $GLOBALS['BE_USER']->writeUC(); 00182 } 00183 } 00184 00185 00186 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/recycler/classes/controller/class.tx_recycler_controller_ajax.php'])) { 00187 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/recycler/classes/controller/class.tx_recycler_controller_ajax.php']); 00188 } 00189 00190 ?>
1.8.0