[TASK] Re-work/simplify copyright header in PHP files - Part 9
[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 * Additional BE fields for recycler garbage collection task.
18 *
19 * Creates an integer input field for difference between scheduler run time
20 * and file modification time in days to select from.
21 *
22 * @author 2011 Kai Vogel <kai.vogel@speedprogs.de>
23 */
24 class RecyclerGarbageCollectionAdditionalFieldProvider implements \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface {
25
26 /**
27 * Default period in days to remove a recycled file
28 *
29 * @var integer Default number of days
30 */
31 protected $defaultNumberOfDays = 30;
32
33 /**
34 * Add an integer input field for difference between scheduler run time
35 * and file modification time in days to select from
36 *
37 * @param array $taskInfo Reference to the array containing the info used in the add/edit form
38 * @param object $task When editing, reference to the current task object. Null when adding.
39 * @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject Reference to the calling object (Scheduler's BE module)
40 * @return array Array containing all the information pertaining to the additional fields
41 */
42 public function getAdditionalFields(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject) {
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 type="text" name="' . $fieldName . '" id="' . $fieldId . '" value="' . htmlspecialchars($fieldValue) . '" />';
54 $additionalFields[$fieldId] = array(
55 'code' => $fieldHtml,
56 'label' => 'LLL:EXT:scheduler/mod1/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 boolean 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 $result = TRUE;
72 // Check if number of days is indeed a number and greater or equals to 0
73 // If not, fail validation and issue error message
74 if (!is_numeric($submittedData['scheduler_recyclerGarbageCollection_numberOfDays']) || (int)$submittedData['scheduler_recyclerGarbageCollection_numberOfDays'] < 0) {
75 $result = FALSE;
76 $parentObject->addMessage($GLOBALS['LANG']->sL('LLL:EXT:scheduler/mod1/locallang.xlf:msg.invalidNumberOfDays'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
77 }
78 return $result;
79 }
80
81 /**
82 * Saves given integer value in task object
83 *
84 * @param array $submittedData Contains data submitted by the user
85 * @param \TYPO3\CMS\Scheduler\Task\AbstractTask $task Reference to the current task object
86 * @return void
87 */
88 public function saveAdditionalFields(array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask $task) {
89 $task->numberOfDays = (int)$submittedData['scheduler_recyclerGarbageCollection_numberOfDays'];
90 }
91
92 }