a66d12688f57618f63d3b79ffcb34afe76776950
[Packages/TYPO3.CMS.git] / typo3 / sysext / scheduler / Classes / Example / SleepTaskAdditionalFieldProvider.php
1 <?php
2 namespace TYPO3\CMS\Scheduler\Example;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2009-2011 Fran├žois Suter <francois@typo3.org>
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 * Aditional fields provider class for usage with the Scheduler's sleep task
28 *
29 * @author Fran├žois Suter <francois@typo3.org>
30 */
31 class SleepTaskAdditionalFieldProvider implements \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface {
32
33 /**
34 * This method is used to define new fields for adding or editing a task
35 * In this case, it adds an sleep time field
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 extra field value
44 if (empty($taskInfo['sleepTime'])) {
45 if ($parentObject->CMD == 'add') {
46 // In case of new task and if field is empty, set default sleep time
47 $taskInfo['sleepTime'] = 30;
48 } elseif ($parentObject->CMD == 'edit') {
49 // In case of edit, set to internal value if no data was submitted already
50 $taskInfo['sleepTime'] = $task->sleepTime;
51 } else {
52 // Otherwise set an empty value, as it will not be used anyway
53 $taskInfo['sleepTime'] = '';
54 }
55 }
56 // Write the code for the field
57 $fieldID = 'task_sleepTime';
58 $fieldCode = '<input type="text" name="TYPO3\\CMS\\Scheduler\\Scheduler[sleepTime]" id="' . $fieldID . '" value="' . $taskInfo['sleepTime'] . '" size="10" />';
59 $additionalFields = array();
60 $additionalFields[$fieldID] = array(
61 'code' => $fieldCode,
62 'label' => 'LLL:EXT:scheduler/mod1/locallang.xml:label.sleepTime',
63 'cshKey' => '_MOD_tools_txschedulerM1',
64 'cshLabel' => $fieldID
65 );
66 return $additionalFields;
67 }
68
69 /**
70 * This method checks any additional data that is relevant to the specific task
71 * If the task class is not relevant, the method is expected to return TRUE
72 *
73 * @param array $submittedData Reference to the array containing the data submitted by the user
74 * @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject Reference to the calling object (Scheduler's BE module)
75 * @return boolean TRUE if validation was ok (or selected class is not relevant), FALSE otherwise
76 */
77 public function validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject) {
78 $submittedData['sleepTime'] = intval($submittedData['sleepTime']);
79 if ($submittedData['sleepTime'] < 0) {
80 $parentObject->addMessage($GLOBALS['LANG']->sL('LLL:EXT:scheduler/mod1/locallang.xml:msg.invalidSleepTime'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
81 $result = FALSE;
82 } else {
83 $result = TRUE;
84 }
85 return $result;
86 }
87
88 /**
89 * This method is used to save any additional input into the current task object
90 * if the task class matches
91 *
92 * @param array $submittedData Array containing the data submitted by the user
93 * @param \TYPO3\CMS\Scheduler\Task\AbstractTask $task Reference to the current task object
94 * @return void
95 */
96 public function saveAdditionalFields(array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask $task) {
97 $task->sleepTime = $submittedData['sleepTime'];
98 }
99
100 }
101
102
103 ?>