[CLEANUP] The correct case must be used for standard PHP types in 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 class SleepTaskAdditionalFieldProvider implements \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface
23 {
24 /**
25 * This method is used to define new fields for adding or editing a task
26 * In this case, it adds an sleep time field
27 *
28 * @param array $taskInfo Reference to the array containing the info used in the add/edit form
29 * @param AbstractTask|null $task When editing, reference to the current task. NULL when adding.
30 * @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject Reference to the calling object (Scheduler's BE module)
31 * @return array Array containing all the information pertaining to the additional fields
32 */
33 public function getAdditionalFields(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
34 {
35 // Initialize extra field value
36 if (empty($taskInfo['sleepTime'])) {
37 if ($parentObject->CMD === 'add') {
38 // In case of new task and if field is empty, set default sleep time
39 $taskInfo['sleepTime'] = 30;
40 } elseif ($parentObject->CMD === 'edit') {
41 // In case of edit, set to internal value if no data was submitted already
42 $taskInfo['sleepTime'] = $task->sleepTime;
43 } else {
44 // Otherwise set an empty value, as it will not be used anyway
45 $taskInfo['sleepTime'] = '';
46 }
47 }
48 // Write the code for the field
49 $fieldID = 'task_sleepTime';
50 $fieldCode = '<input type="text" class="form-control" name="tx_scheduler[sleepTime]" id="' . $fieldID . '" value="' . $taskInfo['sleepTime'] . '" size="10">';
51 $additionalFields = [];
52 $additionalFields[$fieldID] = [
53 'code' => $fieldCode,
54 'label' => 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.sleepTime',
55 'cshKey' => '_MOD_system_txschedulerM1',
56 'cshLabel' => $fieldID
57 ];
58 return $additionalFields;
59 }
60
61 /**
62 * This method checks any additional data that is relevant to the specific task
63 * If the task class is not relevant, the method is expected to return TRUE
64 *
65 * @param array $submittedData Reference to the array containing the data submitted by the user
66 * @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject Reference to the calling object (Scheduler's BE module)
67 * @return bool TRUE if validation was ok (or selected class is not relevant), FALSE otherwise
68 */
69 public function validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
70 {
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 */
88 public function saveAdditionalFields(array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask $task)
89 {
90 $task->sleepTime = $submittedData['sleepTime'];
91 }
92 }