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