[CLEANUP] The correct case must be used for standard PHP types in phpdoc
[Packages/TYPO3.CMS.git] / typo3 / sysext / scheduler / Classes / Task / RecyclerGarbageCollectionAdditionalFieldProvider.php
1 <?php
2 namespace TYPO3\CMS\Scheduler\Task;
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
17 /**
18 * Additional BE fields for recycler garbage collection task.
19 *
20 * Creates an integer input field for difference between scheduler run time
21 * and file modification time in days to select from.
22 */
23 class RecyclerGarbageCollectionAdditionalFieldProvider implements \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface
24 {
25 /**
26 * Default period in days to remove a recycled file
27 *
28 * @var int Default number of days
29 */
30 protected $defaultNumberOfDays = 30;
31
32 /**
33 * Add an integer input field for difference between scheduler run time
34 * and file modification time in days to select from
35 *
36 * @param array $taskInfo Reference to the array containing the info used in the add/edit form
37 * @param AbstractTask|null $task When editing, reference to the current task. NULL when adding.
38 * @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject Reference to the calling object (Scheduler's BE module)
39 * @return array Array containing all the information pertaining to the additional fields
40 */
41 public function getAdditionalFields(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
42 {
43 // Initialize selected fields
44 if (!isset($taskInfo['scheduler_recyclerGarbageCollection_numberOfDays'])) {
45 $taskInfo['scheduler_recyclerGarbageCollection_numberOfDays'] = $this->defaultNumberOfDays;
46 if ($parentObject->CMD === 'edit') {
47 $taskInfo['scheduler_recyclerGarbageCollection_numberOfDays'] = $task->numberOfDays;
48 }
49 }
50 $fieldName = 'tx_scheduler[scheduler_recyclerGarbageCollection_numberOfDays]';
51 $fieldId = 'task_recyclerGarbageCollection_numberOfDays';
52 $fieldValue = (int)$taskInfo['scheduler_recyclerGarbageCollection_numberOfDays'];
53 $fieldHtml = '<input class="form-control" type="text" name="' . $fieldName . '" id="' . $fieldId . '" value="' . htmlspecialchars($fieldValue) . '">';
54 $additionalFields[$fieldId] = [
55 'code' => $fieldHtml,
56 'label' => 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.recyclerGarbageCollection.numberOfDays',
57 'cshKey' => '_MOD_system_txschedulerM1',
58 'cshLabel' => $fieldId
59 ];
60 return $additionalFields;
61 }
62
63 /**
64 * Checks if the given value is an integer
65 *
66 * @param array $submittedData Reference to the array containing the data submitted by the user
67 * @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject Reference to the calling object (Scheduler's BE module)
68 * @return bool TRUE if validation was ok (or selected class is not relevant), FALSE otherwise
69 */
70 public function validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
71 {
72 $result = true;
73 // Check if number of days is indeed a number and greater or equals to 0
74 // If not, fail validation and issue error message
75 if (!is_numeric($submittedData['scheduler_recyclerGarbageCollection_numberOfDays']) || (int)$submittedData['scheduler_recyclerGarbageCollection_numberOfDays'] < 0) {
76 $result = false;
77 $parentObject->addMessage($GLOBALS['LANG']->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:msg.invalidNumberOfDays'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
78 }
79 return $result;
80 }
81
82 /**
83 * Saves given integer value in task object
84 *
85 * @param array $submittedData Contains data submitted by the user
86 * @param \TYPO3\CMS\Scheduler\Task\AbstractTask $task Reference to the current task object
87 */
88 public function saveAdditionalFields(array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask $task)
89 {
90 $task->numberOfDays = (int)$submittedData['scheduler_recyclerGarbageCollection_numberOfDays'];
91 }
92 }