4ced5f61598f127cbfe41edf639bbbba80b76776
[Packages/TYPO3.CMS.git] / typo3 / sysext / scheduler / examples / class.tx_scheduler_testtask_additionalfieldprovider.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009-2011 Fran├žois Suter <francois@typo3.org>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * Aditional fields provider class for usage with the Scheduler's test task
27 *
28 * @author Fran├žois Suter <francois@typo3.org>
29 * @package TYPO3
30 * @subpackage tx_scheduler
31 */
32 class tx_scheduler_TestTask_AdditionalFieldProvider implements tx_scheduler_AdditionalFieldProvider {
33
34 /**
35 * This method is used to define new fields for adding or editing a task
36 * In this case, it adds an email field
37 *
38 * @param array $taskInfo Reference to the array containing the info used in the add/edit form
39 * @param object $task When editing, reference to the current task object. Null when adding.
40 * @param tx_scheduler_Module $parentObject Reference to the calling object (Scheduler's BE module)
41 * @return array Array containing all the information pertaining to the additional fields
42 * The array is multidimensional, keyed to the task class name and each field's id
43 * For each field it provides an associative sub-array with the following:
44 * ['code'] => The HTML code for the field
45 * ['label'] => The label of the field (possibly localized)
46 * ['cshKey'] => The CSH key for the field
47 * ['cshLabel'] => The code of the CSH label
48 */
49 public function getAdditionalFields(array &$taskInfo, $task, tx_scheduler_Module $parentObject) {
50
51 // Initialize extra field value
52 if (empty($taskInfo['email'])) {
53 if ($parentObject->CMD == 'add') {
54 // In case of new task and if field is empty, set default email address
55 $taskInfo['email'] = $GLOBALS['BE_USER']->user['email'];
56
57 } elseif ($parentObject->CMD == 'edit') {
58 // In case of edit, and editing a test task, set to internal value if not data was submitted already
59 $taskInfo['email'] = $task->email;
60 } else {
61 // Otherwise set an empty value, as it will not be used anyway
62 $taskInfo['email'] = '';
63 }
64 }
65
66 // Write the code for the field
67 $fieldID = 'task_email';
68 $fieldCode = '<input type="text" name="tx_scheduler[email]" id="' . $fieldID . '" value="' . $taskInfo['email'] . '" size="30" />';
69 $additionalFields = array();
70 $additionalFields[$fieldID] = array(
71 'code' => $fieldCode,
72 'label' => 'LLL:EXT:scheduler/mod1/locallang.xml:label.email',
73 'cshKey' => '_MOD_tools_txschedulerM1',
74 'cshLabel' => $fieldID
75 );
76
77 return $additionalFields;
78 }
79
80 /**
81 * This method checks any additional data that is relevant to the specific task
82 * If the task class is not relevant, the method is expected to return TRUE
83 *
84 * @param array $submittedData Reference to the array containing the data submitted by the user
85 * @param tx_scheduler_Module $parentObject Reference to the calling object (Scheduler's BE module)
86 * @return boolean TRUE if validation was ok (or selected class is not relevant), FALSE otherwise
87 */
88 public function validateAdditionalFields(array &$submittedData, tx_scheduler_Module $parentObject) {
89 $submittedData['email'] = trim($submittedData['email']);
90
91 if (empty($submittedData['email'])) {
92 $parentObject->addMessage($GLOBALS['LANG']->sL('LLL:EXT:scheduler/mod1/locallang.xml:msg.noEmail'), t3lib_FlashMessage::ERROR);
93 $result = FALSE;
94 } else {
95 $result = TRUE;
96 }
97
98 return $result;
99 }
100
101 /**
102 * This method is used to save any additional input into the current task object
103 * if the task class matches
104 *
105 * @param array $submittedData Array containing the data submitted by the user
106 * @param tx_scheduler_Task $task Reference to the current task object
107 * @return void
108 */
109 public function saveAdditionalFields(array $submittedData, tx_scheduler_Task $task) {
110 $task->email = $submittedData['email'];
111 }
112 }
113 ?>