[BUGFIX] SQL error in install tool if no root page available
[Packages/TYPO3.CMS.git] / typo3 / sysext / recycler / Classes / Domain / Model / Tables.php
1 <?php
2 namespace TYPO3\CMS\Recycler\Domain\Model;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2009-2013 Julian Kleinhans <typo3@kj187.de>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 /**
28 * Model class for the 'recycler' extension.
29 *
30 * @author Julian Kleinhans <typo3@kj187.de>
31 */
32 class Tables {
33
34 /**
35 * Get tables for menu example
36 *
37 * @param string $format: Return format (example: json)
38 * @param boolean $withAllOption: 0 no, 1 return tables with a "all" option
39 * @param integer $id: UID from selected page
40 * @param integer $depth: How many levels recursive
41 * @return string The tables to be displayed
42 */
43 public function getTables($format, $withAllOption = 0, $startUid, $depth = 0) {
44 $deletedRecordsTotal = 0;
45 $tables = array();
46 foreach (array_keys($GLOBALS['TCA']) as $tableName) {
47 $deletedField = \TYPO3\CMS\Recycler\Utility\RecyclerUtility::getDeletedField($tableName);
48 if ($deletedField) {
49 // Determine whether the table has deleted records:
50 $deletedCount = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('uid', $tableName, $deletedField . '<>0');
51 if ($deletedCount) {
52 $deletedDataObject = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Recycler\\Domain\\Model\\DeletedRecords');
53 $deletedData = $deletedDataObject->loadData($startUid, $tableName, $depth)->getDeletedRows();
54 if (isset($deletedData[$tableName])) {
55 if ($deletedRecordsInTable = count($deletedData[$tableName])) {
56 $deletedRecordsTotal += $deletedRecordsInTable;
57 $tables[] = array(
58 $tableName,
59 $deletedRecordsInTable,
60 $tableName,
61 \TYPO3\CMS\Recycler\Utility\RecyclerUtility::getUtf8String($GLOBALS['LANG']->sL($GLOBALS['TCA'][$tableName]['ctrl']['title']))
62 );
63 }
64 }
65 }
66 }
67 }
68 $jsonArray = $tables;
69 if ($withAllOption) {
70 array_unshift($jsonArray, array(
71 '',
72 $deletedRecordsTotal,
73 '',
74 $GLOBALS['LANG']->sL('LLL:EXT:recycler/mod1/locallang.xlf:label_alltables')
75 ));
76 }
77 $output = json_encode($jsonArray);
78 return $output;
79 }
80
81 }
82
83
84 ?>