[FEATURE] Description-field for scheduler-jobs
[Packages/TYPO3.CMS.git] / typo3 / sysext / scheduler / Classes / Task / RecyclerGarbageCollectionAdditionalFieldProvider.php
1 <?php
2 namespace TYPO3\CMS\Scheduler\Task;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2011-2013 Kai Vogel <kai.vogel@speedprogs.de>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26 /**
27 * Additional BE fields for recycler garbage collection task.
28 *
29 * Creates an integer input field for difference between scheduler run time
30 * and file modification time in days to select from.
31 *
32 * @author 2011 Kai Vogel <kai.vogel@speedprogs.de>
33 */
34 class RecyclerGarbageCollectionAdditionalFieldProvider implements \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface {
35
36 /**
37 * Default period in days to remove a recycled file
38 *
39 * @var integer Default number of days
40 */
41 protected $defaultNumberOfDays = 30;
42
43 /**
44 * Add an integer input field for difference between scheduler run time
45 * and file modification time in days to select from
46 *
47 * @param array $taskInfo Reference to the array containing the info used in the add/edit form
48 * @param object $task When editing, reference to the current task object. Null when adding.
49 * @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject Reference to the calling object (Scheduler's BE module)
50 * @return array Array containing all the information pertaining to the additional fields
51 */
52 public function getAdditionalFields(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject) {
53 // Initialize selected fields
54 if (!isset($taskInfo['scheduler_recyclerGarbageCollection_numberOfDays'])) {
55 $taskInfo['scheduler_recyclerGarbageCollection_numberOfDays'] = $this->defaultNumberOfDays;
56 if ($parentObject->CMD === 'edit') {
57 $taskInfo['scheduler_recyclerGarbageCollection_numberOfDays'] = $task->numberOfDays;
58 }
59 }
60 $fieldName = 'tx_scheduler[scheduler_recyclerGarbageCollection_numberOfDays]';
61 $fieldId = 'task_recyclerGarbageCollection_numberOfDays';
62 $fieldValue = intval($taskInfo['scheduler_recyclerGarbageCollection_numberOfDays']);
63 $fieldHtml = '<input type="text" name="' . $fieldName . '" id="' . $fieldId . '" value="' . htmlspecialchars($fieldValue) . '" />';
64 $additionalFields[$fieldId] = array(
65 'code' => $fieldHtml,
66 'label' => 'LLL:EXT:scheduler/mod1/locallang.xlf:label.recyclerGarbageCollection.numberOfDays',
67 'cshKey' => '_MOD_system_txschedulerM1',
68 'cshLabel' => $fieldId
69 );
70 return $additionalFields;
71 }
72
73 /**
74 * Checks if the given value is an integer
75 *
76 * @param array $submittedData Reference to the array containing the data submitted by the user
77 * @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject Reference to the calling object (Scheduler's BE module)
78 * @return boolean TRUE if validation was ok (or selected class is not relevant), FALSE otherwise
79 */
80 public function validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject) {
81 $result = TRUE;
82 // Check if number of days is indeed a number and greater or equals to 0
83 // If not, fail validation and issue error message
84 if (!is_numeric($submittedData['scheduler_recyclerGarbageCollection_numberOfDays']) || intval($submittedData['scheduler_recyclerGarbageCollection_numberOfDays']) < 0) {
85 $result = FALSE;
86 $parentObject->addMessage($GLOBALS['LANG']->sL('LLL:EXT:scheduler/mod1/locallang.xlf:msg.invalidNumberOfDays'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
87 }
88 return $result;
89 }
90
91 /**
92 * Saves given integer value in task object
93 *
94 * @param array $submittedData Contains data submitted by the user
95 * @param \TYPO3\CMS\Scheduler\Task\AbstractTask $task Reference to the current task object
96 * @return void
97 */
98 public function saveAdditionalFields(array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask $task) {
99 $task->numberOfDays = intval($submittedData['scheduler_recyclerGarbageCollection_numberOfDays']);
100 }
101
102 }