TYPO3 CMS  TYPO3_8-7
IpAnonymizationAdditionalFieldProvider.php
Go to the documentation of this file.
1 <?php
2 
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
20 
25 {
34  public function getAdditionalFields(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
35  {
36  $additionalFields = [];
37  $additionalFields['task_ipAnonymization_table'] = $this->getTableAdditionalField($taskInfo, $task, $parentObject);
38  $additionalFields['task_ipAnonymization_numberOfDays'] = $this->getNumberOfDaysAdditionalField($taskInfo, $task, $parentObject);
39  $additionalFields['task_ipAnonymization_mask'] = $this->getMaskAdditionalField($taskInfo, $task, $parentObject);
40  return $additionalFields;
41  }
42 
51  protected function getTableAdditionalField(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
52  {
53  $tableConfiguration = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][IpAnonymizationTask::class]['options']['tables'];
54  $options = [];
55  // Add an empty option on top if an existing task is configured
56  // with a table that can not be found in configuration anymore
57  if ($parentObject->CMD === 'edit' && !array_key_exists($task->table, $tableConfiguration)) {
58  $options[] = '<option value="" selected="selected"></option>';
59  }
60  foreach ($tableConfiguration as $tableName => $configuration) {
61  if ($parentObject->CMD === 'add' && empty($options)) {
62  // Select first table by default if adding a new task
63  $options[] = '<option value="' . $tableName . '" selected="selected">' . $tableName . '</option>';
64  } elseif ($task->table === $tableName) {
65  // Select currently selected table
66  $options[] = '<option value="' . $tableName . '" selected="selected">' . $tableName . '</option>';
67  } else {
68  $options[] = '<option value="' . $tableName . '">' . $tableName . '</option>';
69  }
70  }
71  $fieldName = 'tx_scheduler[scheduler_ipAnonymization_table]';
72  $fieldId = 'task_ipAnonymization_table';
73  $fieldHtml = [];
74  // Add table drop down html
75  $fieldHtml[] = '<select class="form-control" name="' . $fieldName . '" id="' . $fieldId . '">' . implode(LF, $options) . '</select>';
76  $fieldConfiguration = [
77  'code' => implode(LF, $fieldHtml),
78  'label' => 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.ipAnonymization.table',
79  'cshKey' => '_MOD_system_txschedulerM1',
80  'cshLabel' => $fieldId
81  ];
82  return $fieldConfiguration;
83  }
84 
93  protected function getNumberOfDaysAdditionalField(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
94  {
95  $fieldId = 'scheduler_ipAnonymization_numberOfDays';
96  if (empty($taskInfo[$fieldId])) {
97  $taskInfo[$fieldId] = $task->numberOfDays ?? 180;
98  }
99  $fieldName = 'tx_scheduler[' . $fieldId . ']';
100  $fieldHtml = '<input class="form-control" type="text" ' . 'name="' . $fieldName . '" ' . 'id="' . $fieldId . '" ' . 'value="' . (int)$taskInfo[$fieldId] . '" ' . 'size="4">';
101  $fieldConfiguration = [
102  'code' => $fieldHtml,
103  'label' => 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.ipAnonymization.numberOfDays',
104  'cshKey' => '_MOD_system_txschedulerM1',
105  'cshLabel' => $fieldId
106  ];
107  return $fieldConfiguration;
108  }
109 
118  protected function getMaskAdditionalField(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
119  {
120  $fieldId = 'scheduler_ipAnonymization_mask';
121  if (empty($taskInfo[$fieldId])) {
122  $taskInfo[$fieldId] = $task->mask ?? 2;
123  }
124  $fieldName = 'tx_scheduler[' . $fieldId . ']';
125 
126  $fieldHtml = '';
127  foreach ([1, 2] as $mask) {
128  $selected = (int)$taskInfo[$fieldId] === $mask ? ' selected' : '';
129  $fieldHtml .= '<option value="' . $mask . '"' . $selected . '>'
130  . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.ipAnonymization.mask.' . $mask))
131  . '</option>';
132  }
133 
134  $fieldHtml = '<select class="form-control" name="' . $fieldName . '" ' . 'id="' . $fieldId . '">' . $fieldHtml . '</select>';
135 
136  $fieldConfiguration = [
137  'code' => $fieldHtml,
138  'label' => 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.ipAnonymization.mask',
139  'cshKey' => '_MOD_system_txschedulerM1',
140  'cshLabel' => $fieldId
141  ];
142  return $fieldConfiguration;
143  }
144 
152  public function validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
153  {
154  $validData = $this->validateTableAdditionalField($submittedData, $parentObject);
155  $validData &= $this->validateNumberOfDaysAdditionalField($submittedData, $parentObject);
156  return $validData;
157  }
158 
166  public function validateTableAdditionalField(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
167  {
168  $validData = false;
169  $tableConfiguration = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][IpAnonymizationTask::class]['options']['tables'];
170  if (!isset($submittedData['scheduler_ipAnonymization_table'])) {
171  $validData = true;
172  } elseif (array_key_exists($submittedData['scheduler_ipAnonymization_table'], $tableConfiguration)) {
173  $validData = true;
174  }
175  return $validData;
176  }
177 
185  public function validateNumberOfDaysAdditionalField(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
186  {
187  $validData = false;
188  if (!isset($submittedData['scheduler_ipAnonymization_numberOfDays'])) {
189  $validData = true;
190  } elseif ((int)$submittedData['scheduler_ipAnonymization_numberOfDays'] >= 0) {
191  $validData = true;
192  } else {
193  // Issue error message
194  $parentObject->addMessage($this->getLanguageService()->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:msg.invalidNumberOfDays'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
195  }
196  return $validData;
197  }
198 
205  public function saveAdditionalFields(array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask $task)
206  {
207  $task->table = $submittedData['scheduler_ipAnonymization_table'];
208  $task->mask = $submittedData['scheduler_ipAnonymization_mask'];
209  $task->numberOfDays = (int)$submittedData['scheduler_ipAnonymization_numberOfDays'];
210  }
211 
217  protected function getLanguageService(): LanguageService
218  {
219  return $GLOBALS['LANG'];
220  }
221 }
getTableAdditionalField(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
validateNumberOfDaysAdditionalField(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
getNumberOfDaysAdditionalField(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
getAdditionalFields(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
getMaskAdditionalField(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
validateTableAdditionalField(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
saveAdditionalFields(array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask $task)