cba3abfa15379046b6e56243ea322a6fd0baef2c
[Packages/TYPO3.CMS.git] / typo3 / sysext / recycler / Classes / Domain / Model / Tables.php
1 <?php
2 namespace TYPO3\CMS\Recycler\Domain\Model;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Utility\GeneralUtility;
18 use TYPO3\CMS\Recycler\Utility\RecyclerUtility;
19
20 /**
21 * Model class for the 'recycler' extension.
22 */
23 class Tables
24 {
25 /**
26 * Get tables for menu example
27 *
28 * @param int $startUid UID from selected page
29 * @param int $depth How many levels recursive
30 * @return string The tables to be displayed
31 */
32 public function getTables($startUid, $depth = 0)
33 {
34 $deletedRecordsTotal = 0;
35 $lang = $this->getLanguageService();
36 $tables = array();
37 foreach (RecyclerUtility::getModifyableTables() as $tableName) {
38 $deletedField = RecyclerUtility::getDeletedField($tableName);
39 if ($deletedField) {
40 // Determine whether the table has deleted records:
41 $deletedCount = $this->getDatabaseConnection()->exec_SELECTcountRows('uid', $tableName, $deletedField . '<>0');
42 if ($deletedCount) {
43 /* @var $deletedDataObject DeletedRecords */
44 $deletedDataObject = GeneralUtility::makeInstance(DeletedRecords::class);
45 $deletedData = $deletedDataObject->loadData($startUid, $tableName, $depth)->getDeletedRows();
46 if (isset($deletedData[$tableName])) {
47 if ($deletedRecordsInTable = count($deletedData[$tableName])) {
48 $deletedRecordsTotal += $deletedRecordsInTable;
49 $tables[] = array(
50 $tableName,
51 $deletedRecordsInTable,
52 $lang->sL($GLOBALS['TCA'][$tableName]['ctrl']['title'])
53 );
54 }
55 }
56 }
57 }
58 }
59 $jsonArray = $tables;
60 array_unshift($jsonArray, array(
61 '',
62 $deletedRecordsTotal,
63 $lang->sL('LLL:EXT:recycler/mod1/locallang.xlf:label_allrecordtypes')
64 ));
65 return $jsonArray;
66 }
67
68 /**
69 * Returns an instance of DatabaseConnection
70 *
71 * @return \TYPO3\CMS\Core\Database\DatabaseConnection
72 */
73 protected function getDatabaseConnection()
74 {
75 return $GLOBALS['TYPO3_DB'];
76 }
77
78 /**
79 * Returns an instance of LanguageService
80 *
81 * @return \TYPO3\CMS\Lang\LanguageService
82 */
83 protected function getLanguageService()
84 {
85 return $GLOBALS['LANG'];
86 }
87 }