TYPO3 CMS  TYPO3_7-6
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] = 180;
98  if (isset($task->numberOfDays)) {
99  $taskInfo[$fieldId] = $task->numberOfDays;
100  }
101  }
102  $fieldName = 'tx_scheduler[' . $fieldId . ']';
103  $fieldHtml = '<input class="form-control" type="text" ' . 'name="' . $fieldName . '" ' . 'id="' . $fieldId . '" ' . 'value="' . (int)$taskInfo[$fieldId] . '" ' . 'size="4">';
104  $fieldConfiguration = [
105  'code' => $fieldHtml,
106  'label' => 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.ipAnonymization.numberOfDays',
107  'cshKey' => '_MOD_system_txschedulerM1',
108  'cshLabel' => $fieldId
109  ];
110  return $fieldConfiguration;
111  }
112 
121  protected function getMaskAdditionalField(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
122  {
123  $fieldId = 'scheduler_ipAnonymization_mask';
124  if (empty($taskInfo[$fieldId])) {
125  $taskInfo[$fieldId] = 2;
126  if (isset($task->mask)) {
127  $taskInfo[$fieldId] = $task->mask;
128  }
129  }
130  $fieldName = 'tx_scheduler[' . $fieldId . ']';
131 
132  $fieldHtml = '';
133  foreach ([1, 2] as $mask) {
134  $selected = (int)$taskInfo[$fieldId] === $mask ? ' selected' : '';
135  $fieldHtml .= '<option value="' . $mask . '"' . $selected . '>'
136  . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.ipAnonymization.mask.' . $mask))
137  . '</option>';
138  }
139 
140  $fieldHtml = '<select class="form-control" name="' . $fieldName . '" ' . 'id="' . $fieldId . '">' . $fieldHtml . '</select>';
141 
142  $fieldConfiguration = [
143  'code' => $fieldHtml,
144  'label' => 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.ipAnonymization.mask',
145  'cshKey' => '_MOD_system_txschedulerM1',
146  'cshLabel' => $fieldId
147  ];
148  return $fieldConfiguration;
149  }
150 
158  public function validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
159  {
160  $validData = $this->validateTableAdditionalField($submittedData, $parentObject);
161  $validData &= $this->validateNumberOfDaysAdditionalField($submittedData, $parentObject);
162  return $validData;
163  }
164 
172  public function validateTableAdditionalField(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
173  {
174  $validData = false;
175  $tableConfiguration = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][IpAnonymizationTask::class]['options']['tables'];
176  if (!isset($submittedData['scheduler_ipAnonymization_table'])) {
177  $validData = true;
178  } elseif (array_key_exists($submittedData['scheduler_ipAnonymization_table'], $tableConfiguration)) {
179  $validData = true;
180  }
181  return $validData;
182  }
183 
191  public function validateNumberOfDaysAdditionalField(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
192  {
193  $validData = false;
194  if (!isset($submittedData['scheduler_ipAnonymization_numberOfDays'])) {
195  $validData = true;
196  } elseif ((int)$submittedData['scheduler_ipAnonymization_numberOfDays'] >= 0) {
197  $validData = true;
198  } else {
199  // Issue error message
200  $parentObject->addMessage($this->getLanguageService()->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:msg.invalidNumberOfDays'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
201  }
202  return $validData;
203  }
204 
211  public function saveAdditionalFields(array $submittedData, AbstractTask $task)
212  {
213  $task->table = $submittedData['scheduler_ipAnonymization_table'];
214  $task->mask = $submittedData['scheduler_ipAnonymization_mask'];
215  $task->numberOfDays = (int)$submittedData['scheduler_ipAnonymization_numberOfDays'];
216  }
217 
223  protected function getLanguageService()
224  {
225  return $GLOBALS['LANG'];
226  }
227 }
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']