‪TYPO3CMS  10.4
IpAnonymizationAdditionalFieldProvider.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
23 
29 {
38  public function ‪getAdditionalFields(array &$taskInfo, $task, ‪SchedulerModuleController $schedulerModule)
39  {
40  $additionalFields = [];
41  $additionalFields['task_ipAnonymization_table'] = $this->‪getTableAdditionalField($taskInfo, $task, $schedulerModule);
42  $additionalFields['task_ipAnonymization_numberOfDays'] = $this->‪getNumberOfDaysAdditionalField($taskInfo, $task, $schedulerModule);
43  $additionalFields['task_ipAnonymization_mask'] = $this->‪getMaskAdditionalField($taskInfo, $task, $schedulerModule);
44  return $additionalFields;
45  }
46 
55  protected function ‪getTableAdditionalField(array &$taskInfo, $task, ‪SchedulerModuleController $schedulerModule)
56  {
57  $currentSchedulerModuleAction = $schedulerModule->‪getCurrentAction();
58  $tableConfiguration = ‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][IpAnonymizationTask::class]['options']['tables'];
59  $options = [];
60  // Add an empty option on top if an existing task is configured
61  // with a table that can not be found in configuration anymore
62  if (!array_key_exists($task->table, $tableConfiguration) && $currentSchedulerModuleAction->equals(‪Action::EDIT)) {
63  $options[] = '<option value="" selected="selected"></option>';
64  }
65  foreach ($tableConfiguration as $tableName => $configuration) {
66  if ($currentSchedulerModuleAction->equals(‪Action::ADD) && empty($options)) {
67  // Select first table by default if adding a new task
68  $options[] = '<option value="' . $tableName . '" selected="selected">' . $tableName . '</option>';
69  } elseif ($task->table === $tableName) {
70  // Select currently selected table
71  $options[] = '<option value="' . $tableName . '" selected="selected">' . $tableName . '</option>';
72  } else {
73  $options[] = '<option value="' . $tableName . '">' . $tableName . '</option>';
74  }
75  }
76  $fieldName = 'tx_scheduler[scheduler_ipAnonymization_table]';
77  $fieldId = 'task_ipAnonymization_table';
78  $fieldHtml = [];
79  // Add table drop down html
80  $fieldHtml[] = '<select class="form-control" name="' . $fieldName . '" id="' . $fieldId . '">' . implode(LF, $options) . '</select>';
81  $fieldConfiguration = [
82  'code' => implode(LF, $fieldHtml),
83  'label' => 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.ipAnonymization.table',
84  'cshKey' => '_MOD_system_txschedulerM1',
85  'cshLabel' => $fieldId
86  ];
87  return $fieldConfiguration;
88  }
89 
98  protected function ‪getNumberOfDaysAdditionalField(array &$taskInfo, $task, ‪SchedulerModuleController $schedulerModule)
99  {
100  $fieldId = 'scheduler_ipAnonymization_numberOfDays';
101  if (empty($taskInfo[$fieldId])) {
102  $taskInfo[$fieldId] = $task->numberOfDays ?? 180;
103  }
104  $fieldName = 'tx_scheduler[' . $fieldId . ']';
105  $fieldHtml = '<input class="form-control" type="text" name="' . $fieldName . '" id="' . $fieldId . '" value="' . (int)$taskInfo[$fieldId] . '" size="4">';
106  $fieldConfiguration = [
107  'code' => $fieldHtml,
108  'label' => 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.ipAnonymization.numberOfDays',
109  'cshKey' => '_MOD_system_txschedulerM1',
110  'cshLabel' => $fieldId
111  ];
112  return $fieldConfiguration;
113  }
114 
123  protected function ‪getMaskAdditionalField(array &$taskInfo, $task, ‪SchedulerModuleController $schedulerModule)
124  {
125  $fieldId = 'scheduler_ipAnonymization_mask';
126  if (empty($taskInfo[$fieldId])) {
127  $taskInfo[$fieldId] = $task->mask ?? 2;
128  }
129  $fieldName = 'tx_scheduler[' . $fieldId . ']';
130 
131  $fieldHtml = '';
132  foreach ([1, 2] as $mask) {
133  $selected = (int)$taskInfo[$fieldId] === $mask ? ' selected' : '';
134  $fieldHtml .= '<option value="' . $mask . '"' . $selected . '>'
135  . htmlspecialchars($this->‪getLanguageService()->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.ipAnonymization.mask.' . $mask))
136  . '</option>';
137  }
138 
139  $fieldHtml = '<select class="form-control" name="' . $fieldName . '" id="' . $fieldId . '">' . $fieldHtml . '</select>';
140 
141  $fieldConfiguration = [
142  'code' => $fieldHtml,
143  'label' => 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.ipAnonymization.mask',
144  'cshKey' => '_MOD_system_txschedulerM1',
145  'cshLabel' => $fieldId
146  ];
147  return $fieldConfiguration;
148  }
149 
157  public function ‪validateAdditionalFields(array &$submittedData, ‪SchedulerModuleController $schedulerModule)
158  {
159  $validData = $this->‪validateTableAdditionalField($submittedData, $schedulerModule);
160  $validData &= $this->‪validateNumberOfDaysAdditionalField($submittedData, $schedulerModule);
161  return $validData;
162  }
163 
171  public function ‪validateTableAdditionalField(array &$submittedData, ‪SchedulerModuleController $schedulerModule)
172  {
173  $validData = false;
174  $tableConfiguration = ‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][IpAnonymizationTask::class]['options']['tables'];
175  if (!isset($submittedData['scheduler_ipAnonymization_table'])) {
176  $validData = true;
177  } elseif (array_key_exists($submittedData['scheduler_ipAnonymization_table'], $tableConfiguration)) {
178  $validData = true;
179  }
180  return $validData;
181  }
182 
190  public function ‪validateNumberOfDaysAdditionalField(array &$submittedData, ‪SchedulerModuleController $schedulerModule)
191  {
192  $validData = false;
193  if (!isset($submittedData['scheduler_ipAnonymization_numberOfDays'])) {
194  $validData = true;
195  } elseif ((int)$submittedData['scheduler_ipAnonymization_numberOfDays'] >= 0) {
196  $validData = true;
197  } else {
198  // Issue error message
199  $this->‪addMessage($this->‪getLanguageService()->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:msg.invalidNumberOfDays'), ‪FlashMessage::ERROR);
200  }
201  return $validData;
202  }
203 
210  public function ‪saveAdditionalFields(array $submittedData, ‪AbstractTask $task)
211  {
212  $task->table = $submittedData['scheduler_ipAnonymization_table'];
213  $task->mask = (int)$submittedData['scheduler_ipAnonymization_mask'];
214  $task->numberOfDays = (int)$submittedData['scheduler_ipAnonymization_numberOfDays'];
215  }
216 
223  {
224  return ‪$GLOBALS['LANG'];
225  }
226 }
‪TYPO3\CMS\Scheduler\Task\Enumeration\Action\ADD
‪const ADD
Definition: Action.php:28
‪TYPO3\CMS\Scheduler\Task\IpAnonymizationAdditionalFieldProvider
Definition: IpAnonymizationAdditionalFieldProvider.php:29
‪TYPO3\CMS\Scheduler\Task\IpAnonymizationAdditionalFieldProvider\validateNumberOfDaysAdditionalField
‪bool validateNumberOfDaysAdditionalField(array &$submittedData, SchedulerModuleController $schedulerModule)
Definition: IpAnonymizationAdditionalFieldProvider.php:190
‪TYPO3\CMS\Scheduler\Task\IpAnonymizationAdditionalFieldProvider\getTableAdditionalField
‪array getTableAdditionalField(array &$taskInfo, $task, SchedulerModuleController $schedulerModule)
Definition: IpAnonymizationAdditionalFieldProvider.php:55
‪TYPO3\CMS\Scheduler\Task\IpAnonymizationAdditionalFieldProvider\getAdditionalFields
‪array getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $schedulerModule)
Definition: IpAnonymizationAdditionalFieldProvider.php:38
‪TYPO3\CMS\Scheduler\Task
Definition: AbstractTask.php:16
‪TYPO3\CMS\Scheduler\Task\IpAnonymizationAdditionalFieldProvider\validateTableAdditionalField
‪bool validateTableAdditionalField(array &$submittedData, SchedulerModuleController $schedulerModule)
Definition: IpAnonymizationAdditionalFieldProvider.php:171
‪TYPO3\CMS\Scheduler\Task\IpAnonymizationAdditionalFieldProvider\getLanguageService
‪LanguageService getLanguageService()
Definition: IpAnonymizationAdditionalFieldProvider.php:222
‪TYPO3\CMS\Scheduler\AbstractAdditionalFieldProvider
Definition: AbstractAdditionalFieldProvider.php:28
‪TYPO3\CMS\Scheduler\AbstractAdditionalFieldProvider\addMessage
‪addMessage(string $message, int $severity=FlashMessage::OK)
Definition: AbstractAdditionalFieldProvider.php:35
‪TYPO3\CMS\Scheduler\Task\IpAnonymizationAdditionalFieldProvider\getNumberOfDaysAdditionalField
‪array getNumberOfDaysAdditionalField(array &$taskInfo, $task, SchedulerModuleController $schedulerModule)
Definition: IpAnonymizationAdditionalFieldProvider.php:98
‪TYPO3\CMS\Scheduler\Task\AbstractTask
Definition: AbstractTask.php:35
‪TYPO3\CMS\Scheduler\Task\IpAnonymizationAdditionalFieldProvider\getMaskAdditionalField
‪array getMaskAdditionalField(array &$taskInfo, $task, SchedulerModuleController $schedulerModule)
Definition: IpAnonymizationAdditionalFieldProvider.php:123
‪TYPO3\CMS\Scheduler\Controller\SchedulerModuleController
Definition: SchedulerModuleController.php:56
‪TYPO3\CMS\Scheduler\Task\Enumeration\Action\EDIT
‪const EDIT
Definition: Action.php:30
‪TYPO3\CMS\Scheduler\Controller\SchedulerModuleController\getCurrentAction
‪Action getCurrentAction()
Definition: SchedulerModuleController.php:181
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:24
‪TYPO3\CMS\Scheduler\Task\Enumeration\Action
Definition: Action.php:26
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Scheduler\Task\IpAnonymizationAdditionalFieldProvider\saveAdditionalFields
‪saveAdditionalFields(array $submittedData, AbstractTask $task)
Definition: IpAnonymizationAdditionalFieldProvider.php:210
‪TYPO3\CMS\Scheduler\Task\IpAnonymizationAdditionalFieldProvider\validateAdditionalFields
‪bool validateAdditionalFields(array &$submittedData, SchedulerModuleController $schedulerModule)
Definition: IpAnonymizationAdditionalFieldProvider.php:157
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:31