TYPO3 CMS  TYPO3_6-2
TableGarbageCollectionAdditionalFieldProvider.php
Go to the documentation of this file.
1 <?php
3 
22 
26  protected $defaultNumberOfDays = array();
27 
36  public function getAdditionalFields(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject) {
37  $this->initDefaultNumberOfDays();
38  $additionalFields['task_tableGarbageCollection_allTables'] = $this->getAllTablesAdditionalField($taskInfo, $task, $parentObject);
39  $additionalFields['task_tableGarbageCollection_table'] = $this->getTableAdditionalField($taskInfo, $task, $parentObject);
40  $additionalFields['task_tableGarbageCollection_numberOfDays'] = $this->getNumberOfDaysAdditionalField($taskInfo, $task, $parentObject);
41  return $additionalFields;
42  }
43 
49  protected function initDefaultNumberOfDays() {
50  $tableConfiguration = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks']['TYPO3\\CMS\\Scheduler\\Task\\TableGarbageCollectionTask']['options']['tables'];
51  foreach ($tableConfiguration as $tableName => $configuration) {
52  if (isset($configuration['expirePeriod'])) {
53  $this->defaultNumberOfDays[$tableName] = $configuration['expirePeriod'];
54  }
55  }
56  }
57 
66  protected function getAllTablesAdditionalField(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject) {
67  if ($parentObject->CMD === 'edit') {
68  $checked = $task->allTables === TRUE ? 'checked="checked" ' : '';
69  } else {
70  $checked = '';
71  }
72  $fieldName = 'tx_scheduler[scheduler_tableGarbageCollection_allTables]';
73  $fieldId = 'task_tableGarbageCollection_allTables';
74  $fieldHtml = '<input type="checkbox" ' . $checked . 'onChange="actOnChangeSchedulerTableGarbageCollectionAllTables(this)" ' . 'name="' . $fieldName . '" ' . 'id="' . $fieldId . '" />';
75  $fieldConfiguration = array(
76  'code' => $fieldHtml,
77  'label' => 'LLL:EXT:scheduler/mod1/locallang.xlf:label.tableGarbageCollection.allTables',
78  'cshKey' => '_MOD_system_txschedulerM1',
79  'cshLabel' => $fieldId
80  );
81  return $fieldConfiguration;
82  }
83 
92  protected function getTableAdditionalField(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject) {
93  $tableConfiguration = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks']['TYPO3\\CMS\\Scheduler\\Task\\TableGarbageCollectionTask']['options']['tables'];
94  $options = array();
95  // Add an empty option on top if an existing task is configured
96  // with a table that can not be found in configuration anymore
97  if ($parentObject->CMD === 'edit' && !array_key_exists($task->table, $tableConfiguration)) {
98  $options[] = '<option value="" selected="selected"></option>';
99  }
100  foreach ($tableConfiguration as $tableName => $configuration) {
101  if ($parentObject->CMD === 'add' && count($options) === 0) {
102  // Select first table by default if adding a new task
103  $options[] = '<option value="' . $tableName . '" selected="selected">' . $tableName . '</option>';
104  } elseif ($task->table === $tableName) {
105  // Select currently selected table
106  $options[] = '<option value="' . $tableName . '" selected="selected">' . $tableName . '</option>';
107  } else {
108  $options[] = '<option value="' . $tableName . '">' . $tableName . '</option>';
109  }
110  }
111  $disabled = $task->allTables === TRUE ? ' disabled="disabled"' : '';
112  $fieldName = 'tx_scheduler[scheduler_tableGarbageCollection_table]';
113  $fieldId = 'task_tableGarbageCollection_table';
114  $fieldHtml = array();
115  // Add table drop down html
116  $fieldHtml[] = '<select ' . 'name="' . $fieldName . '" ' . $disabled . 'onChange="actOnChangeSchedulerTableGarbageCollectionTable(this)"' . 'id="' . $fieldId . '">' . implode(LF, $options) . '</select>';
117  // Add js array for default 'number of days' values
118  $fieldHtml[] = '<script type="text/javascript">/*<![CDATA[*/<!--';
119  $fieldHtml[] = 'var defaultNumberOfDays = ' . json_encode($this->defaultNumberOfDays) . ';';
120  $fieldHtml[] = '// -->/*]]>*/</script>';
121  $fieldConfiguration = array(
122  'code' => implode(LF, $fieldHtml),
123  'label' => 'LLL:EXT:scheduler/mod1/locallang.xlf:label.tableGarbageCollection.table',
124  'cshKey' => '_MOD_system_txschedulerM1',
125  'cshLabel' => $fieldId
126  );
127  return $fieldConfiguration;
128  }
129 
138  protected function getNumberOfDaysAdditionalField(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject) {
139  // Initialize selected fields
140  $disabled = '';
141  if (empty($taskInfo['scheduler_tableGarbageCollection_numberOfDays'])) {
142  if ($parentObject->CMD === 'add') {
143  // In case of new task, set to 180 days
144  $taskInfo['scheduler_tableGarbageCollection_numberOfDays'] = 180;
145  } elseif ($parentObject->CMD === 'edit') {
146  // In case of editing the task, set to currently selected value
147  $taskInfo['scheduler_tableGarbageCollection_numberOfDays'] = $task->numberOfDays;
148  if ($task->numberOfDays === 0 && !isset($this->defaultNumberOfDays[$task->table])) {
149  $disabled = ' disabled="disabled"';
150  }
151  }
152  }
153  if ($task->allTables === TRUE) {
154  $disabled = ' disabled="disabled"';
155  }
156  $fieldName = 'tx_scheduler[scheduler_tableGarbageCollection_numberOfDays]';
157  $fieldId = 'task_tableGarbageCollection_numberOfDays';
158  $fieldHtml = '<input type="text" ' . 'name="' . $fieldName . '" ' . 'id="' . $fieldId . '" ' . $disabled . 'value="' . (int)$taskInfo['scheduler_tableGarbageCollection_numberOfDays'] . '" ' . 'size="4" />';
159  $fieldConfiguration = array(
160  'code' => $fieldHtml,
161  'label' => 'LLL:EXT:scheduler/mod1/locallang.xlf:label.tableGarbageCollection.numberOfDays',
162  'cshKey' => '_MOD_system_txschedulerM1',
163  'cshLabel' => $fieldId
164  );
165  return $fieldConfiguration;
166  }
167 
175  public function validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject) {
176  $validData = $this->validateAllTablesAdditionalField($submittedData, $parentObject);
177  $validData &= $this->validateTableAdditionalField($submittedData, $parentObject);
178  $validData &= $this->validateNumberOfDaysAdditionalField($submittedData, $parentObject);
179  return $validData;
180  }
181 
189  public function validateAllTablesAdditionalField(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject) {
190  $validData = FALSE;
191  if (!isset($submittedData['scheduler_tableGarbageCollection_allTables'])) {
192  $validData = TRUE;
193  } elseif ($submittedData['scheduler_tableGarbageCollection_allTables'] === 'on') {
194  $validData = TRUE;
195  }
196  return $validData;
197  }
198 
206  public function validateTableAdditionalField(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject) {
207  $validData = FALSE;
208  $tableConfiguration = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks']['TYPO3\\CMS\\Scheduler\\Task\\TableGarbageCollectionTask']['options']['tables'];
209  if (!isset($submittedData['scheduler_tableGarbageCollection_table'])) {
210  $validData = TRUE;
211  } elseif (array_key_exists($submittedData['scheduler_tableGarbageCollection_table'], $tableConfiguration)) {
212  $validData = TRUE;
213  }
214  return $validData;
215  }
216 
224  public function validateNumberOfDaysAdditionalField(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject) {
225  $validData = FALSE;
226  if (!isset($submittedData['scheduler_tableGarbageCollection_numberOfDays'])) {
227  $validData = TRUE;
228  } elseif ((int)$submittedData['scheduler_tableGarbageCollection_numberOfDays'] >= 0) {
229  $validData = TRUE;
230  } else {
231  // Issue error message
232  $parentObject->addMessage($GLOBALS['LANG']->sL('LLL:EXT:scheduler/mod1/locallang.xlf:msg.invalidNumberOfDays'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
233  }
234  return $validData;
235  }
236 
244  public function saveAdditionalFields(array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask $task) {
245  $task->allTables = $submittedData['scheduler_tableGarbageCollection_allTables'] === 'on' ? TRUE : FALSE;
246  $task->table = $submittedData['scheduler_tableGarbageCollection_table'];
247  $task->numberOfDays = (int)$submittedData['scheduler_tableGarbageCollection_numberOfDays'];
248  }
249 
250 }
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)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
getAdditionalFields(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
getAllTablesAdditionalField(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
getNumberOfDaysAdditionalField(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)