[TASK] Re-work/simplify copyright header in PHP files - Part 9
[Packages/TYPO3.CMS.git] / typo3 / sysext / scheduler / Classes / Example / SleepTaskAdditionalFieldProvider.php
1 <?php
2 namespace TYPO3\CMS\Scheduler\Example;
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 fields provider class for usage with the Scheduler's sleep task
18 *
19 * @author Fran├žois Suter <francois@typo3.org>
20 */
21 class SleepTaskAdditionalFieldProvider implements \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface {
22
23 /**
24 * This method is used to define new fields for adding or editing a task
25 * In this case, it adds an sleep time field
26 *
27 * @param array $taskInfo Reference to the array containing the info used in the add/edit form
28 * @param object $task When editing, reference to the current task object. Null when adding.
29 * @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject Reference to the calling object (Scheduler's BE module)
30 * @return array Array containing all the information pertaining to the additional fields
31 */
32 public function getAdditionalFields(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject) {
33 // Initialize extra field value
34 if (empty($taskInfo['sleepTime'])) {
35 if ($parentObject->CMD == 'add') {
36 // In case of new task and if field is empty, set default sleep time
37 $taskInfo['sleepTime'] = 30;
38 } elseif ($parentObject->CMD == 'edit') {
39 // In case of edit, set to internal value if no data was submitted already
40 $taskInfo['sleepTime'] = $task->sleepTime;
41 } else {
42 // Otherwise set an empty value, as it will not be used anyway
43 $taskInfo['sleepTime'] = '';
44 }
45 }
46 // Write the code for the field
47 $fieldID = 'task_sleepTime';
48 $fieldCode = '<input type="text" name="tx_scheduler[sleepTime]" id="' . $fieldID . '" value="' . $taskInfo['sleepTime'] . '" size="10" />';
49 $additionalFields = array();
50 $additionalFields[$fieldID] = array(
51 'code' => $fieldCode,
52 'label' => 'LLL:EXT:scheduler/mod1/locallang.xlf:label.sleepTime',
53 'cshKey' => '_MOD_system_txschedulerM1',
54 'cshLabel' => $fieldID
55 );
56 return $additionalFields;
57 }
58
59 /**
60 * This method checks any additional data that is relevant to the specific task
61 * If the task class is not relevant, the method is expected to return TRUE
62 *
63 * @param array $submittedData Reference to the array containing the data submitted by the user
64 * @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject Reference to the calling object (Scheduler's BE module)
65 * @return boolean TRUE if validation was ok (or selected class is not relevant), FALSE otherwise
66 */
67 public function validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject) {
68 $submittedData['sleepTime'] = (int)$submittedData['sleepTime'];
69 if ($submittedData['sleepTime'] < 0) {
70 $parentObject->addMessage($GLOBALS['LANG']->sL('LLL:EXT:scheduler/mod1/locallang.xlf:msg.invalidSleepTime'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
71 $result = FALSE;
72 } else {
73 $result = TRUE;
74 }
75 return $result;
76 }
77
78 /**
79 * This method is used to save any additional input into the current task object
80 * if the task class matches
81 *
82 * @param array $submittedData Array containing the data submitted by the user
83 * @param \TYPO3\CMS\Scheduler\Task\AbstractTask $task Reference to the current task object
84 * @return void
85 */
86 public function saveAdditionalFields(array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask $task) {
87 $task->sleepTime = $submittedData['sleepTime'];
88 }
89
90 }