Cleanup: Updated copyright comments
[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 * $Id$
33 */
34 class tx_scheduler_TestTask_AdditionalFieldProvider implements tx_scheduler_AdditionalFieldProvider {
35
36 /**
37 * This method is used to define new fields for adding or editing a task
38 * In this case, it adds an email field
39 *
40 * @param array $taskInfo: reference to the array containing the info used in the add/edit form
41 * @param object $task: when editing, reference to the current task object. Null when adding.
42 * @param tx_scheduler_Module $parentObject: reference to the calling object (Scheduler's BE module)
43 * @return array Array containg all the information pertaining to the additional fields
44 * The array is multidimensional, keyed to the task class name and each field's id
45 * For each field it provides an associative sub-array with the following:
46 * ['code'] => The HTML code for the field
47 * ['label'] => The label of the field (possibly localized)
48 * ['cshKey'] => The CSH key for the field
49 * ['cshLabel'] => The code of the CSH label
50 */
51 public function getAdditionalFields(array &$taskInfo, $task, tx_scheduler_Module $parentObject) {
52
53 // Initialize extra field value
54 if (empty($taskInfo['email'])) {
55 if ($parentObject->CMD == 'add') {
56 // In case of new task and if field is empty, set default email address
57 $taskInfo['email'] = $GLOBALS['BE_USER']->user['email'];
58
59 } elseif ($parentObject->CMD == 'edit') {
60 // In case of edit, and editing a test task, set to internal value if not data was submitted already
61 $taskInfo['email'] = $task->email;
62 } else {
63 // Otherwise set an empty value, as it will not be used anyway
64 $taskInfo['email'] = '';
65 }
66 }
67
68 // Write the code for the field
69 $fieldID = 'task_email';
70 $fieldCode = '<input type="text" name="tx_scheduler[email]" id="' . $fieldID . '" value="' . $taskInfo['email'] . '" size="30" />';
71 $additionalFields = array();
72 $additionalFields[$fieldID] = array(
73 'code' => $fieldCode,
74 'label' => 'LLL:EXT:scheduler/mod1/locallang.xml:label.email',
75 'cshKey' => '_MOD_tools_txschedulerM1',
76 'cshLabel' => $fieldID
77 );
78
79 return $additionalFields;
80 }
81
82 /**
83 * This method checks any additional data that is relevant to the specific task
84 * If the task class is not relevant, the method is expected to return true
85 *
86 * @param array $submittedData: reference to the array containing the data submitted by the user
87 * @param tx_scheduler_Module $parentObject: reference to the calling object (Scheduler's BE module)
88 * @return boolean True if validation was ok (or selected class is not relevant), false otherwise
89 */
90 public function validateAdditionalFields(array &$submittedData, tx_scheduler_Module $parentObject) {
91 $submittedData['email'] = trim($submittedData['email']);
92
93 if (empty($submittedData['email'])) {
94 $parentObject->addMessage($GLOBALS['LANG']->sL('LLL:EXT:scheduler/mod1/locallang.xml:msg.noEmail'), t3lib_FlashMessage::ERROR);
95 $result = false;
96 } else {
97 $result = true;
98 }
99
100 return $result;
101 }
102
103 /**
104 * This method is used to save any additional input into the current task object
105 * if the task class matches
106 *
107 * @param array $submittedData: array containing the data submitted by the user
108 * @param tx_scheduler_Task $task: reference to the current task object
109 * @return void
110 */
111 public function saveAdditionalFields(array $submittedData, tx_scheduler_Task $task) {
112 $task->email = $submittedData['email'];
113 }
114 }
115
116 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/scheduler/examples/class.tx_scheduler_testtask_additionalfieldprovider.php'])) {
117 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/scheduler/examples/class.tx_scheduler_testtask_additionalfieldprovider.php']);
118 }
119
120 ?>