TYPO3 API  SVNRelease
class.tx_recycler_model_tables.php
Go to the documentation of this file.
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 require_once(t3lib_extMgm::extPath('recycler', 'classes/model/class.tx_recycler_model_deletedRecords.php'));
00026 
00027 /**
00028  * Model class for the 'recycler' extension.
00029  *
00030  * @author  Julian Kleinhans <typo3@kj187.de>
00031  * @package TYPO3
00032  * @subpackage  tx_recycler
00033  * @version $Id: class.tx_recycler_model_tables.php 10120 2011-01-18 20:03:36Z ohader $
00034  */
00035 class tx_recycler_model_tables {
00036     /**
00037      * Get tables for menu example
00038      *
00039      * @param   string      $format: Return format (example: json)
00040      * @param   boolean     $withAllOption: 0 no, 1 return tables with a "all" option
00041      * @param   integer     $id: UID from selected page
00042      * @param   integer     $depth: How many levels recursive
00043      * @return  string      The tables to be displayed
00044      */
00045     public function getTables($format, $withAllOption=0, $startUid, $depth=0) {
00046         $deletedRecordsTotal = 0;
00047         $tables = array();
00048 
00049         foreach (array_keys($GLOBALS['TCA']) as $tableName) {
00050             $deletedField = tx_recycler_helper::getDeletedField($tableName);
00051             if ($deletedField) {
00052                     // Determine whether the table has deleted records:
00053                 $deletedCount = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows(
00054                     'uid',
00055                     $tableName,
00056                     $deletedField . '!=0'
00057                 );
00058                 if ($deletedCount) {
00059                     $deletedDataObject = t3lib_div::makeInstance('tx_recycler_model_deletedRecords');
00060                     $deletedData = $deletedDataObject->loadData($startUid, $tableName, $depth)->getDeletedRows();
00061                     if (isset($deletedData[$tableName])) {
00062                         if ($deletedRecordsInTable = count($deletedData[$tableName])) {
00063                             $deletedRecordsTotal += $deletedRecordsInTable;
00064                             $tables[] = array(
00065                                 $tableName,
00066                                 $deletedRecordsInTable,
00067                                 $tableName,
00068                                 tx_recycler_helper::getUtf8String(
00069                                     $GLOBALS['LANG']->sL($GLOBALS['TCA'][$tableName]['ctrl']['title'])
00070                                 ),
00071                             );
00072                         }
00073                     }
00074                 }
00075             }
00076         }
00077 
00078         $jsonArray = $tables;
00079         if ($withAllOption) {
00080             array_unshift(
00081                 $jsonArray,
00082                 array(
00083                     '',
00084                     $deletedRecordsTotal,
00085                     '',
00086                     $GLOBALS['LANG']->sL('LLL:EXT:recycler/mod1/locallang.xml:label_alltables'),
00087                 )
00088             );
00089         }
00090         $output = json_encode($jsonArray);
00091 
00092         return $output;
00093     }
00094 }
00095 
00096 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/recycler/classes/model/class.tx_recycler_model_tables.php'])) {
00097     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/recycler/classes/model/class.tx_recycler_model_tables.php']);
00098 }
00099 
00100 ?>