[TASK] Doctrine: migrate ext:recycler/Tables
[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\Core\Database\Connection;
19 use TYPO3\CMS\Core\Database\ConnectionPool;
20 use TYPO3\CMS\Recycler\Utility\RecyclerUtility;
21
22 /**
23 * Model class for the 'recycler' extension.
24 */
25 class Tables
26 {
27 /**
28 * Get tables for menu example
29 *
30 * @param int $startUid UID from selected page
31 * @param int $depth How many levels recursive
32 * @return string The tables to be displayed
33 */
34 public function getTables($startUid, $depth = 0)
35 {
36 $deletedRecordsTotal = 0;
37 $lang = $this->getLanguageService();
38 $tables = array();
39 $connection = GeneralUtility::makeInstance(ConnectionPool::class);
40 foreach (RecyclerUtility::getModifyableTables() as $tableName) {
41 $deletedField = RecyclerUtility::getDeletedField($tableName);
42 if ($deletedField) {
43 // Determine whether the table has deleted records:
44 $queryBuilder = $connection->getQueryBuilderForTable($tableName);
45 $queryBuilder
46 ->getQueryContext()
47 ->setIgnoreEnableFields(true)
48 ->setIncludeDeleted(true);
49
50 $deletedCount = $queryBuilder->count('uid')
51 ->from($tableName)
52 ->where($queryBuilder->expr()->neq($deletedField, 0))
53 ->execute()
54 ->fetchColumn();
55
56 if ($deletedCount) {
57 /* @var $deletedDataObject DeletedRecords */
58 $deletedDataObject = GeneralUtility::makeInstance(DeletedRecords::class);
59 $deletedData = $deletedDataObject->loadData($startUid, $tableName, $depth)->getDeletedRows();
60 if (isset($deletedData[$tableName])) {
61 if ($deletedRecordsInTable = count($deletedData[$tableName])) {
62 $deletedRecordsTotal += $deletedRecordsInTable;
63 $tables[] = array(
64 $tableName,
65 $deletedRecordsInTable,
66 $lang->sL($GLOBALS['TCA'][$tableName]['ctrl']['title'])
67 );
68 }
69 }
70 }
71 }
72 }
73 $jsonArray = $tables;
74 array_unshift($jsonArray, array(
75 '',
76 $deletedRecordsTotal,
77 $lang->sL('LLL:EXT:recycler/mod1/locallang.xlf:label_allrecordtypes')
78 ));
79 return $jsonArray;
80 }
81
82 /**
83 * Returns an instance of LanguageService
84 *
85 * @return \TYPO3\CMS\Lang\LanguageService
86 */
87 protected function getLanguageService()
88 {
89 return $GLOBALS['LANG'];
90 }
91 }