[CLEANUP] Improve the @param/@return/@var 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 * @author Kai Vogel <kai.vogel@speedprogs.de>
24 */
25 class RecyclerGarbageCollectionAdditionalFieldProvider implements \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface {
26
27 /**
28 * Default period in days to remove a recycled file
29 *
30 * @var int Default number of days
31 */
32 protected $defaultNumberOfDays = 30;
33
34 /**
35 * Add an integer input field for difference between scheduler run time
36 * and file modification time in days to select from
37 *
38 * @param array $taskInfo Reference to the array containing the info used in the add/edit form
39 * @param AbstractTask|NULL $task When editing, reference to the current task. NULL when adding.
40 * @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject Reference to the calling object (Scheduler's BE module)
41 * @return array Array containing all the information pertaining to the additional fields
42 */
43 public function getAdditionalFields(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject) {
44 // Initialize selected fields
45 if (!isset($taskInfo['scheduler_recyclerGarbageCollection_numberOfDays'])) {
46 $taskInfo['scheduler_recyclerGarbageCollection_numberOfDays'] = $this->defaultNumberOfDays;
47 if ($parentObject->CMD === 'edit') {
48 $taskInfo['scheduler_recyclerGarbageCollection_numberOfDays'] = $task->numberOfDays;
49 }
50 }
51 $fieldName = 'tx_scheduler[scheduler_recyclerGarbageCollection_numberOfDays]';
52 $fieldId = 'task_recyclerGarbageCollection_numberOfDays';
53 $fieldValue = (int)$taskInfo['scheduler_recyclerGarbageCollection_numberOfDays'];
54 $fieldHtml = '<input type="text" name="' . $fieldName . '" id="' . $fieldId . '" value="' . htmlspecialchars($fieldValue) . '" />';
55 $additionalFields[$fieldId] = array(
56 'code' => $fieldHtml,
57 'label' => 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.recyclerGarbageCollection.numberOfDays',
58 'cshKey' => '_MOD_system_txschedulerM1',
59 'cshLabel' => $fieldId
60 );
61 return $additionalFields;
62 }
63
64 /**
65 * Checks if the given value is an integer
66 *
67 * @param array $submittedData Reference to the array containing the data submitted by the user
68 * @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject Reference to the calling object (Scheduler's BE module)
69 * @return bool TRUE if validation was ok (or selected class is not relevant), FALSE otherwise
70 */
71 public function validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject) {
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 * @return void
88 */
89 public function saveAdditionalFields(array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask $task) {
90 $task->numberOfDays = (int)$submittedData['scheduler_recyclerGarbageCollection_numberOfDays'];
91 }
92
93 }