|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2009-2011 François Suter <francois@typo3.org> 00006 * All rights reserved 00007 * 00008 * This script is part of the TYPO3 project. The TYPO3 project is 00009 * free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * The GNU General Public License can be found at 00015 * http://www.gnu.org/copyleft/gpl.html. 00016 * 00017 * This script is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 * GNU General Public License for more details. 00021 * 00022 * This copyright notice MUST APPEAR in all copies of the script! 00023 ***************************************************************/ 00024 00025 /** 00026 * Aditional fields provider class for usage with the Scheduler's sleep task 00027 * 00028 * @author François Suter <francois@typo3.org> 00029 * @package TYPO3 00030 * @subpackage tx_scheduler 00031 * 00032 * $Id: class.tx_scheduler_sleeptask_additionalfieldprovider.php 10120 2011-01-18 20:03:36Z ohader $ 00033 */ 00034 class tx_scheduler_SleepTask_AdditionalFieldProvider implements tx_scheduler_AdditionalFieldProvider { 00035 00036 /** 00037 * This method is used to define new fields for adding or editing a task 00038 * In this case, it adds an sleep time field 00039 * 00040 * @param array $taskInfo: reference to the array containing the info used in the add/edit form 00041 * @param object $task: when editing, reference to the current task object. Null when adding. 00042 * @param tx_scheduler_Module $parentObject: reference to the calling object (Scheduler's BE module) 00043 * @return array Array containg all the information pertaining to the additional fields 00044 * The array is multidimensional, keyed to the task class name and each field's id 00045 * For each field it provides an associative sub-array with the following: 00046 * ['code'] => The HTML code for the field 00047 * ['label'] => The label of the field (possibly localized) 00048 * ['cshKey'] => The CSH key for the field 00049 * ['cshLabel'] => The code of the CSH label 00050 */ 00051 public function getAdditionalFields(array &$taskInfo, $task, tx_scheduler_Module $parentObject) { 00052 00053 // Initialize extra field value 00054 if (empty($taskInfo['sleepTime'])) { 00055 if ($parentObject->CMD == 'add') { 00056 // In case of new task and if field is empty, set default sleep time 00057 $taskInfo['sleepTime'] = 30; 00058 } else if ($parentObject->CMD == 'edit') { 00059 // In case of edit, set to internal value if no data was submitted already 00060 $taskInfo['sleepTime'] = $task->sleepTime; 00061 } else { 00062 // Otherwise set an empty value, as it will not be used anyway 00063 $taskInfo['sleepTime'] = ''; 00064 } 00065 } 00066 00067 // Write the code for the field 00068 $fieldID = 'task_sleepTime'; 00069 $fieldCode = '<input type="text" name="tx_scheduler[sleepTime]" id="' . $fieldID . '" value="' . $taskInfo['sleepTime'] . '" size="10" />'; 00070 $additionalFields = array(); 00071 $additionalFields[$fieldID] = array( 00072 'code' => $fieldCode, 00073 'label' => 'LLL:EXT:scheduler/mod1/locallang.xml:label.sleepTime', 00074 'cshKey' => '_MOD_tools_txschedulerM1', 00075 'cshLabel' => $fieldID 00076 ); 00077 00078 return $additionalFields; 00079 } 00080 00081 /** 00082 * This method checks any additional data that is relevant to the specific task 00083 * If the task class is not relevant, the method is expected to return true 00084 * 00085 * @param array $submittedData: reference to the array containing the data submitted by the user 00086 * @param tx_scheduler_Module $parentObject: reference to the calling object (Scheduler's BE module) 00087 * @return boolean True if validation was ok (or selected class is not relevant), false otherwise 00088 */ 00089 public function validateAdditionalFields(array &$submittedData, tx_scheduler_Module $parentObject) { 00090 $submittedData['sleepTime'] = intval($submittedData['sleepTime']); 00091 00092 if ($submittedData['sleepTime'] < 0) { 00093 $parentObject->addMessage($GLOBALS['LANG']->sL('LLL:EXT:scheduler/mod1/locallang.xml:msg.invalidSleepTime'), t3lib_FlashMessage::ERROR); 00094 $result = false; 00095 } else { 00096 $result = true; 00097 } 00098 return $result; 00099 } 00100 00101 /** 00102 * This method is used to save any additional input into the current task object 00103 * if the task class matches 00104 * 00105 * @param array $submittedData: array containing the data submitted by the user 00106 * @param tx_scheduler_Task $task: reference to the current task object 00107 * @return void 00108 */ 00109 public function saveAdditionalFields(array $submittedData, tx_scheduler_Task $task) { 00110 $task->sleepTime = $submittedData['sleepTime']; 00111 } 00112 } 00113 00114 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/scheduler/examples/class.tx_scheduler_sleeptask_additionalfieldprovider.php'])) { 00115 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/scheduler/examples/class.tx_scheduler_sleeptask_additionalfieldprovider.php']); 00116 } 00117 00118 ?>
1.8.0