TYPO3 CMS  TYPO3_7-6
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 
20 
26 {
35  public function getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $schedulerModule)
36  {
37  if ($schedulerModule->CMD === 'edit') {
38  $taskInfo['RecyclerCleanerTCA'] = $task->getTcaTables();
39  $taskInfo['RecyclerCleanerPeriod'] = $task->getPeriod();
40  }
41 
42  $additionalFields['period'] = [
43  'code' => '<input type="text" class="form-control" name="tx_scheduler[RecyclerCleanerPeriod]" value="' . $taskInfo['RecyclerCleanerPeriod'] . '">',
44  'label' => 'LLL:EXT:recycler/Resources/Private/Language/locallang_tasks.xlf:cleanerTaskPeriod',
45  'cshKey' => '',
46  'cshLabel' => 'task_recyclerCleaner_selectedPeriod'
47  ];
48 
49  $additionalFields['tca'] = [
50  'code' => $this->getTcaSelectHtml($taskInfo['RecyclerCleanerTCA']),
51  'label' => 'LLL:EXT:recycler/Resources/Private/Language/locallang_tasks.xlf:cleanerTaskTCA',
52  'cshKey' => '',
53  'cshLabel' => 'task_recyclerCleaner_selectedTables'
54  ];
55 
56  return $additionalFields;
57  }
58 
65  protected function getTcaSelectHtml($selectedTables = [])
66  {
67  if (!is_array($selectedTables)) {
68  $selectedTables = [];
69  }
70  $tcaSelectHtml = '<select name="tx_scheduler[RecyclerCleanerTCA][]" multiple="multiple" class="form-control" size="10">';
71 
72  $options = [];
73  foreach ($GLOBALS['TCA'] as $table => $tableConf) {
74  if (!$tableConf['ctrl']['adminOnly'] && !empty($tableConf['ctrl']['delete'])) {
75  $selected = in_array($table, $selectedTables, true) ? ' selected="selected"' : '';
76  $tableTitle = $this->getLanguageService()->sL($tableConf['ctrl']['title']);
77  $options[$tableTitle] = '<option' . $selected . ' value="' . $table . '">' . htmlspecialchars($tableTitle . ' (' . $table . ')') . '</option>';
78  }
79  }
80  ksort($options);
81 
82  $tcaSelectHtml .= implode('', $options);
83  $tcaSelectHtml .= '</select>';
84 
85  return $tcaSelectHtml;
86  }
87 
95  public function validateAdditionalFields(array &$submittedData, SchedulerModuleController $schedulerModule)
96  {
97  $validPeriod = $this->validateAdditionalFieldPeriod($submittedData['RecyclerCleanerPeriod'], $schedulerModule);
98  $validTca = $this->validateAdditionalFieldTca($submittedData['RecyclerCleanerTCA'], $schedulerModule);
99 
100  return $validPeriod && $validTca;
101  }
102 
110  protected function validateAdditionalFieldTca($tca, SchedulerModuleController $schedulerModule)
111  {
112  return $this->checkTcaIsNotEmpty($tca, $schedulerModule) && $this->checkTcaIsValid($tca, $schedulerModule);
113  }
114 
122  protected function checkTcaIsNotEmpty($tca, SchedulerModuleController $schedulerModule)
123  {
124  if (is_array($tca) && !empty($tca)) {
125  $validTca = true;
126  } else {
127  $schedulerModule->addMessage(
128  $this->getLanguageService()->sL('LLL:EXT:recycler/Resources/Private/Language/locallang_tasks.xlf:cleanerTaskErrorTCAempty', true),
130  );
131  $validTca = false;
132  }
133 
134  return $validTca;
135  }
136 
144  protected function checkTcaIsValid(array $tca, SchedulerModuleController $schedulerModule)
145  {
146  $checkTca = false;
147  foreach ($tca as $tcaTable) {
148  if (!isset($GLOBALS['TCA'][$tcaTable])) {
149  $checkTca = false;
150  $schedulerModule->addMessage(
151  sprintf($this->getLanguageService()->sL('LLL:EXT:recycler/Resources/Private/Language/locallang_tasks.xlf:cleanerTaskErrorTCANotSet', true), $tcaTable),
153  );
154  break;
155  } else {
156  $checkTca = true;
157  }
158  }
159 
160  return $checkTca;
161  }
162 
170  protected function validateAdditionalFieldPeriod($period, SchedulerModuleController $schedulerModule)
171  {
172  if (!empty($period) && filter_var($period, FILTER_VALIDATE_INT) !== false) {
173  $validPeriod = true;
174  } else {
175  $schedulerModule->addMessage(
176  $this->getLanguageService()->sL('LLL:EXT:recycler/Resources/Private/Language/locallang_tasks.xlf:cleanerTaskErrorPeriod', true),
178  );
179  $validPeriod = false;
180  }
181 
182  return $validPeriod;
183  }
184 
193  public function saveAdditionalFields(array $submittedData, AbstractTask $task)
194  {
195  if (!$task instanceof CleanerTask) {
196  throw new \InvalidArgumentException(
197  'Expected a task of type \TYPO3\CMS\Recycler\Task\CleanerTask, but got ' . get_class($task),
198  1329219449
199  );
200  }
201 
202  $task->setTcaTables($submittedData['RecyclerCleanerTCA']);
203  $task->setPeriod($submittedData['RecyclerCleanerPeriod']);
204  }
205 
209  protected function getLanguageService()
210  {
211  return $GLOBALS['LANG'];
212  }
213 }
checkTcaIsNotEmpty($tca, SchedulerModuleController $schedulerModule)
validateAdditionalFieldTca($tca, SchedulerModuleController $schedulerModule)
validateAdditionalFieldPeriod($period, SchedulerModuleController $schedulerModule)
validateAdditionalFields(array &$submittedData, SchedulerModuleController $schedulerModule)
checkTcaIsValid(array $tca, SchedulerModuleController $schedulerModule)
saveAdditionalFields(array $submittedData, AbstractTask $task)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $schedulerModule)