TYPO3 CMS  TYPO3_7-6
TableGarbageCollectionAdditionalFieldProvider.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 
21 {
25  protected $defaultNumberOfDays = [];
26 
35  public function getAdditionalFields(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
36  {
37  $this->initDefaultNumberOfDays();
38  $additionalFields = [];
39  $additionalFields['task_tableGarbageCollection_allTables'] = $this->getAllTablesAdditionalField($taskInfo, $task, $parentObject);
40  $additionalFields['task_tableGarbageCollection_table'] = $this->getTableAdditionalField($taskInfo, $task, $parentObject);
41  $additionalFields['task_tableGarbageCollection_numberOfDays'] = $this->getNumberOfDaysAdditionalField($taskInfo, $task, $parentObject);
42  return $additionalFields;
43  }
44 
50  protected function initDefaultNumberOfDays()
51  {
52  $tableConfiguration = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][\TYPO3\CMS\Scheduler\Task\TableGarbageCollectionTask::class]['options']['tables'];
53  foreach ($tableConfiguration as $tableName => $configuration) {
54  if (isset($configuration['expirePeriod'])) {
55  $this->defaultNumberOfDays[$tableName] = $configuration['expirePeriod'];
56  }
57  }
58  }
59 
68  protected function getAllTablesAdditionalField(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
69  {
70  if ($parentObject->CMD === 'edit') {
71  $checked = $task->allTables === true ? 'checked="checked" ' : '';
72  } else {
73  $checked = '';
74  }
75  $fieldName = 'tx_scheduler[scheduler_tableGarbageCollection_allTables]';
76  $fieldId = 'task_tableGarbageCollection_allTables';
77  $fieldHtml = '<div class="checkbox"><label><input type="checkbox" ' . $checked . ' name="' . $fieldName . '" ' . 'id="' . $fieldId . '"></label></div>';
78  $fieldConfiguration = [
79  'code' => $fieldHtml,
80  'label' => 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.tableGarbageCollection.allTables',
81  'cshKey' => '_MOD_system_txschedulerM1',
82  'cshLabel' => $fieldId
83  ];
84  return $fieldConfiguration;
85  }
86 
95  protected function getTableAdditionalField(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
96  {
97  $tableConfiguration = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][\TYPO3\CMS\Scheduler\Task\TableGarbageCollectionTask::class]['options']['tables'];
98  $options = [];
99  // Add an empty option on top if an existing task is configured
100  // with a table that can not be found in configuration anymore
101  if ($parentObject->CMD === 'edit' && !array_key_exists($task->table, $tableConfiguration)) {
102  $options[] = '<option value="" selected="selected"></option>';
103  }
104  foreach ($tableConfiguration as $tableName => $configuration) {
105  if ($parentObject->CMD === 'add' && empty($options)) {
106  // Select first table by default if adding a new task
107  $options[] = '<option value="' . $tableName . '" selected="selected">' . $tableName . '</option>';
108  } elseif ($task->table === $tableName) {
109  // Select currently selected table
110  $options[] = '<option value="' . $tableName . '" selected="selected">' . $tableName . '</option>';
111  } else {
112  $options[] = '<option value="' . $tableName . '">' . $tableName . '</option>';
113  }
114  }
115  $disabled = $task->allTables === true ? ' disabled="disabled"' : '';
116  $fieldName = 'tx_scheduler[scheduler_tableGarbageCollection_table]';
117  $fieldId = 'task_tableGarbageCollection_table';
118  $fieldHtml = [];
119  // Add table drop down html
120  $fieldHtml[] = '<select class="form-control" name="' . $fieldName . '" ' . $disabled . ' id="' . $fieldId . '">' . implode(LF, $options) . '</select>';
121  // Add js array for default 'number of days' values
122  $fieldHtml[] = '<script type="text/javascript">/*<![CDATA[*/<!--';
123  $fieldHtml[] = 'var defaultNumberOfDays = ' . json_encode($this->defaultNumberOfDays) . ';';
124  $fieldHtml[] = '// -->/*]]>*/</script>';
125  $fieldConfiguration = [
126  'code' => implode(LF, $fieldHtml),
127  'label' => 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.tableGarbageCollection.table',
128  'cshKey' => '_MOD_system_txschedulerM1',
129  'cshLabel' => $fieldId
130  ];
131  return $fieldConfiguration;
132  }
133 
142  protected function getNumberOfDaysAdditionalField(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
143  {
144  // Initialize selected fields
145  $disabled = '';
146  if (empty($taskInfo['scheduler_tableGarbageCollection_numberOfDays'])) {
147  if ($parentObject->CMD === 'add') {
148  // In case of new task, set to 180 days
149  $taskInfo['scheduler_tableGarbageCollection_numberOfDays'] = 180;
150  } elseif ($parentObject->CMD === 'edit') {
151  // In case of editing the task, set to currently selected value
152  $taskInfo['scheduler_tableGarbageCollection_numberOfDays'] = $task->numberOfDays;
153  if ($task->numberOfDays === 0 && !isset($this->defaultNumberOfDays[$task->table])) {
154  $disabled = ' disabled="disabled"';
155  }
156  }
157  }
158  if ($task->allTables === true) {
159  $disabled = ' disabled="disabled"';
160  }
161  $fieldName = 'tx_scheduler[scheduler_tableGarbageCollection_numberOfDays]';
162  $fieldId = 'task_tableGarbageCollection_numberOfDays';
163  $fieldHtml = '<input class="form-control" type="text" ' . 'name="' . $fieldName . '" ' . 'id="' . $fieldId . '" ' . $disabled . 'value="' . (int)$taskInfo['scheduler_tableGarbageCollection_numberOfDays'] . '" ' . 'size="4">';
164  $fieldConfiguration = [
165  'code' => $fieldHtml,
166  'label' => 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.tableGarbageCollection.numberOfDays',
167  'cshKey' => '_MOD_system_txschedulerM1',
168  'cshLabel' => $fieldId
169  ];
170  return $fieldConfiguration;
171  }
172 
180  public function validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
181  {
182  $validData = $this->validateAllTablesAdditionalField($submittedData, $parentObject);
183  $validData &= $this->validateTableAdditionalField($submittedData, $parentObject);
184  $validData &= $this->validateNumberOfDaysAdditionalField($submittedData, $parentObject);
185  return $validData;
186  }
187 
195  public function validateAllTablesAdditionalField(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
196  {
197  $validData = false;
198  if (!isset($submittedData['scheduler_tableGarbageCollection_allTables'])) {
199  $validData = true;
200  } elseif ($submittedData['scheduler_tableGarbageCollection_allTables'] === 'on') {
201  $validData = true;
202  }
203  return $validData;
204  }
205 
213  public function validateTableAdditionalField(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
214  {
215  $validData = false;
216  $tableConfiguration = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][\TYPO3\CMS\Scheduler\Task\TableGarbageCollectionTask::class]['options']['tables'];
217  if (!isset($submittedData['scheduler_tableGarbageCollection_table'])) {
218  $validData = true;
219  } elseif (array_key_exists($submittedData['scheduler_tableGarbageCollection_table'], $tableConfiguration)) {
220  $validData = true;
221  }
222  return $validData;
223  }
224 
232  public function validateNumberOfDaysAdditionalField(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
233  {
234  $validData = false;
235  if (!isset($submittedData['scheduler_tableGarbageCollection_numberOfDays'])) {
236  $validData = true;
237  } elseif ((int)$submittedData['scheduler_tableGarbageCollection_numberOfDays'] >= 0) {
238  $validData = true;
239  } else {
240  // Issue error message
241  $parentObject->addMessage($GLOBALS['LANG']->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:msg.invalidNumberOfDays'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
242  }
243  return $validData;
244  }
245 
253  public function saveAdditionalFields(array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask $task)
254  {
255  $task->allTables = $submittedData['scheduler_tableGarbageCollection_allTables'] === 'on';
256  $task->table = $submittedData['scheduler_tableGarbageCollection_table'];
257  $task->numberOfDays = (int)$submittedData['scheduler_tableGarbageCollection_numberOfDays'];
258  }
259 }
getTableAdditionalField(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
validateAllTablesAdditionalField(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
validateTableAdditionalField(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
validateNumberOfDaysAdditionalField(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
saveAdditionalFields(array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask $task)
getAdditionalFields(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
getAllTablesAdditionalField(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
getNumberOfDaysAdditionalField(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)