‪TYPO3CMS  9.5
CleanerFieldProvider.php
Go to the documentation of this file.
1 <?php
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 
22 
29 {
38  public function ‪getAdditionalFields(array &$taskInfo, $task, ‪SchedulerModuleController $schedulerModule)
39  {
40  $currentSchedulerModuleAction = $schedulerModule->‪getCurrentAction();
41 
42  if ($currentSchedulerModuleAction->equals(‪Action::EDIT)) {
43  $taskInfo['RecyclerCleanerTCA'] = $task->getTcaTables();
44  $taskInfo['RecyclerCleanerPeriod'] = $task->getPeriod();
45  }
46 
47  $additionalFields['period'] = [
48  'code' => '<input type="text" class="form-control" name="tx_scheduler[RecyclerCleanerPeriod]" value="' . $taskInfo['RecyclerCleanerPeriod'] . '">',
49  'label' => 'LLL:EXT:recycler/Resources/Private/Language/locallang_tasks.xlf:cleanerTaskPeriod',
50  'cshKey' => '',
51  'cshLabel' => 'task_recyclerCleaner_selectedPeriod'
52  ];
53 
54  $additionalFields['tca'] = [
55  'code' => $this->‪getTcaSelectHtml($taskInfo['RecyclerCleanerTCA']),
56  'label' => 'LLL:EXT:recycler/Resources/Private/Language/locallang_tasks.xlf:cleanerTaskTCA',
57  'cshKey' => '',
58  'cshLabel' => 'task_recyclerCleaner_selectedTables'
59  ];
60 
61  return $additionalFields;
62  }
63 
70  protected function ‪getTcaSelectHtml($selectedTables = [])
71  {
72  if (!is_array($selectedTables)) {
73  $selectedTables = [];
74  }
75  $tcaSelectHtml = '<select name="tx_scheduler[RecyclerCleanerTCA][]" multiple="multiple" class="form-control" size="10">';
76 
77  $options = [];
78  foreach (‪$GLOBALS['TCA'] as $table => $tableConf) {
79  if (!empty($tableConf['ctrl']['delete'])) {
80  $selected = in_array($table, $selectedTables, true) ? ' selected="selected"' : '';
81  $tableTitle = $this->‪getLanguageService()->sL($tableConf['ctrl']['title']);
82  $options[$tableTitle . ' ' . $table] = '<option' . $selected . ' value="' . $table . '">' . htmlspecialchars($tableTitle . ' (' . $table . ')') . '</option>';
83  }
84  }
85  ksort($options);
86 
87  $tcaSelectHtml .= implode('', $options);
88  $tcaSelectHtml .= '</select>';
89 
90  return $tcaSelectHtml;
91  }
92 
100  public function ‪validateAdditionalFields(array &$submittedData, ‪SchedulerModuleController $schedulerModule)
101  {
102  $validPeriod = $this->‪validateAdditionalFieldPeriod($submittedData['RecyclerCleanerPeriod']);
103  $validTca = $this->‪validateAdditionalFieldTca($submittedData['RecyclerCleanerTCA']);
104 
105  return $validPeriod && $validTca;
106  }
107 
115  {
116  return $this->‪checkTcaIsNotEmpty(‪$tca) && $this->‪checkTcaIsValid(‪$tca);
117  }
118 
125  protected function ‪checkTcaIsNotEmpty(‪$tca)
126  {
127  if (is_array(‪$tca) && !empty(‪$tca)) {
128  $validTca = true;
129  } else {
130  $this->‪addMessage(
131  $this->‪getLanguageService()->sL('LLL:EXT:recycler/Resources/Private/Language/locallang_tasks.xlf:cleanerTaskErrorTCAempty'),
133  );
134  $validTca = false;
135  }
136 
137  return $validTca;
138  }
139 
146  protected function ‪checkTcaIsValid(array ‪$tca)
147  {
148  $checkTca = false;
149  foreach (‪$tca as $tcaTable) {
150  if (!isset(‪$GLOBALS['TCA'][$tcaTable])) {
151  $checkTca = false;
152  $this->‪addMessage(
153  sprintf($this->‪getLanguageService()->sL('LLL:EXT:recycler/Resources/Private/Language/locallang_tasks.xlf:cleanerTaskErrorTCANotSet'), $tcaTable),
155  );
156  break;
157  }
158  $checkTca = true;
159  }
160 
161  return $checkTca;
162  }
163 
170  protected function ‪validateAdditionalFieldPeriod($period)
171  {
172  if (!empty($period) && filter_var($period, FILTER_VALIDATE_INT) !== false) {
173  $validPeriod = true;
174  } else {
175  $this->‪addMessage(
176  $this->‪getLanguageService()->sL('LLL:EXT:recycler/Resources/Private/Language/locallang_tasks.xlf:cleanerTaskErrorPeriod'),
178  );
179  $validPeriod = false;
180  }
181 
182  return $validPeriod;
183  }
184 
192  public function ‪saveAdditionalFields(array $submittedData, ‪AbstractTask $task)
193  {
194  if (!$task instanceof ‪CleanerTask) {
195  throw new \InvalidArgumentException(
196  'Expected a task of type ' . CleanerTask::class . ', but got ' . get_class($task),
197  1329219449
198  );
199  }
200 
201  $task->setTcaTables($submittedData['RecyclerCleanerTCA']);
202  $task->setPeriod($submittedData['RecyclerCleanerPeriod']);
203  }
204 
208  protected function ‪getLanguageService()
209  {
210  return ‪$GLOBALS['LANG'];
211  }
212 }
‪TYPO3\CMS\Recycler\Task\CleanerFieldProvider
Definition: CleanerFieldProvider.php:29
‪TYPO3\CMS\Recycler\Task\CleanerFieldProvider\validateAdditionalFieldPeriod
‪bool validateAdditionalFieldPeriod($period)
Definition: CleanerFieldProvider.php:170
‪TYPO3\CMS\Scheduler\AbstractAdditionalFieldProvider
Definition: AbstractAdditionalFieldProvider.php:26
‪TYPO3\CMS\Recycler\Task\CleanerFieldProvider\validateAdditionalFieldTca
‪bool validateAdditionalFieldTca($tca)
Definition: CleanerFieldProvider.php:114
‪TYPO3\CMS\Scheduler\AbstractAdditionalFieldProvider\addMessage
‪addMessage(string $message, int $severity=FlashMessage::OK)
Definition: AbstractAdditionalFieldProvider.php:33
‪TYPO3\CMS\Recycler\Task\CleanerFieldProvider\checkTcaIsValid
‪bool checkTcaIsValid(array $tca)
Definition: CleanerFieldProvider.php:146
‪TYPO3\CMS\Scheduler\Task\AbstractTask
Definition: AbstractTask.php:32
‪TYPO3\CMS\Recycler\Task\CleanerTask
Definition: CleanerTask.php:27
‪TYPO3\CMS\Scheduler\Controller\SchedulerModuleController
Definition: SchedulerModuleController.php:53
‪TYPO3\CMS\Recycler\Task\CleanerFieldProvider\getAdditionalFields
‪array getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $schedulerModule)
Definition: CleanerFieldProvider.php:38
‪TYPO3\CMS\Scheduler\Task\Enumeration\Action\EDIT
‪const EDIT
Definition: Action.php:28
‪TYPO3\CMS\Recycler\Task\CleanerFieldProvider\validateAdditionalFields
‪bool validateAdditionalFields(array &$submittedData, SchedulerModuleController $schedulerModule)
Definition: CleanerFieldProvider.php:100
‪TYPO3\CMS\Scheduler\Controller\SchedulerModuleController\getCurrentAction
‪Action getCurrentAction()
Definition: SchedulerModuleController.php:198
‪TYPO3\CMS\Recycler\Task\CleanerFieldProvider\getLanguageService
‪TYPO3 CMS Core Localization LanguageService getLanguageService()
Definition: CleanerFieldProvider.php:208
‪TYPO3\CMS\Recycler\Task
Definition: CleanerFieldProvider.php:2
‪TYPO3\CMS\Recycler\Task\CleanerFieldProvider\getTcaSelectHtml
‪string getTcaSelectHtml($selectedTables=[])
Definition: CleanerFieldProvider.php:70
‪TYPO3\CMS\Recycler\Task\CleanerFieldProvider\checkTcaIsNotEmpty
‪bool checkTcaIsNotEmpty($tca)
Definition: CleanerFieldProvider.php:125
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:22
‪TYPO3\CMS\Scheduler\Task\Enumeration\Action
Definition: Action.php:24
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪$tca
‪$tca
Definition: sys_file_metadata.php:4
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:29
‪TYPO3\CMS\Recycler\Task\CleanerFieldProvider\saveAdditionalFields
‪saveAdditionalFields(array $submittedData, AbstractTask $task)
Definition: CleanerFieldProvider.php:192