Cleanup: Updated copyright comments
[Packages/TYPO3.CMS.git] / typo3 / sysext / recycler / classes / model / class.tx_recycler_model_tables.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 require_once(t3lib_extMgm::extPath('recycler', 'classes/model/class.tx_recycler_model_deletedRecords.php'));
26
27 /**
28 * Model class for the 'recycler' extension.
29 *
30 * @author Julian Kleinhans <typo3@kj187.de>
31 * @package TYPO3
32 * @subpackage tx_recycler
33 * @version $Id$
34 */
35 class tx_recycler_model_tables {
36 /**
37 * Get tables for menu example
38 *
39 * @param string $format: Return format (example: json)
40 * @param boolean $withAllOption: 0 no, 1 return tables with a "all" option
41 * @param integer $id: UID from selected page
42 * @param integer $depth: How many levels recursive
43 * @return string The tables to be displayed
44 */
45 public function getTables($format, $withAllOption=0, $startUid, $depth=0) {
46 $deletedRecordsTotal = 0;
47 $tables = array();
48
49 foreach (array_keys($GLOBALS['TCA']) as $tableName) {
50 $deletedField = tx_recycler_helper::getDeletedField($tableName);
51 if ($deletedField) {
52 // Determine whether the table has deleted records:
53 $deletedCount = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows(
54 'uid',
55 $tableName,
56 $deletedField . '!=0'
57 );
58 if ($deletedCount) {
59 $deletedDataObject = t3lib_div::makeInstance('tx_recycler_model_deletedRecords');
60 $deletedData = $deletedDataObject->loadData($startUid, $tableName, $depth)->getDeletedRows();
61 if (isset($deletedData[$tableName])) {
62 if ($deletedRecordsInTable = count($deletedData[$tableName])) {
63 $deletedRecordsTotal += $deletedRecordsInTable;
64 $tables[] = array(
65 $tableName,
66 $deletedRecordsInTable,
67 $tableName,
68 tx_recycler_helper::getUtf8String(
69 $GLOBALS['LANG']->sL($GLOBALS['TCA'][$tableName]['ctrl']['title'])
70 ),
71 );
72 }
73 }
74 }
75 }
76 }
77
78 $jsonArray = $tables;
79 if ($withAllOption) {
80 array_unshift(
81 $jsonArray,
82 array(
83 '',
84 $deletedRecordsTotal,
85 '',
86 $GLOBALS['LANG']->sL('LLL:EXT:recycler/mod1/locallang.xml:label_alltables'),
87 )
88 );
89 }
90 $output = json_encode($jsonArray);
91
92 return $output;
93 }
94 }
95
96 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/recycler/classes/model/class.tx_recycler_model_tables.php'])) {
97 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/recycler/classes/model/class.tx_recycler_model_tables.php']);
98 }
99
100 ?>