|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2009-2011 Christian Kuhn <lolli@schwarzbu.ch> 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 * Additional BE fields for caching framework garbage collection task. 00027 * Creates a multi selectbox with all available cache backends to select from. 00028 * 00029 * @author Christian Kuhn <lolli@schwarzbu.ch> 00030 * @package TYPO3 00031 * @subpackage scheduler 00032 */ 00033 class tx_scheduler_CachingFrameworkGarbageCollection_AdditionalFieldProvider implements tx_scheduler_AdditionalFieldProvider { 00034 /** 00035 * Add a multi select box with all available cache backends. 00036 * 00037 * @param array Reference to the array containing the info used in the add/edit form 00038 * @param object When editing, reference to the current task object. Null when adding. 00039 * @param tx_scheduler_Module Reference to the calling object (Scheduler's BE module) 00040 * @return array Array containg all the information pertaining to the additional fields 00041 */ 00042 public function getAdditionalFields(array &$taskInfo, $task, tx_scheduler_Module $parentObject) { 00043 // Initialize selected fields 00044 if (empty($taskInfo['scheduler_cachingFrameworkGarbageCollection_selectedBackends'])) { 00045 $taskInfo['scheduler_cachingFrameworkGarbageCollection_selectedBackends'] = array(); 00046 if ($parentObject->CMD == 'add') { 00047 // In case of new task, set to dbBackend if it's available 00048 if (in_array('t3lib_cache_backend_DbBackend', $this->getRegisteredBackends())) { 00049 $taskInfo['scheduler_cachingFrameworkGarbageCollection_selectedBackends'][] = 't3lib_cache_backend_DbBackend'; 00050 } 00051 } elseif ($parentObject->CMD == 'edit') { 00052 // In case of editing the task, set to currently selected value 00053 $taskInfo['scheduler_cachingFrameworkGarbageCollection_selectedBackends'] = $task->selectedBackends; 00054 } 00055 } 00056 00057 $fieldName = 'tx_scheduler[scheduler_cachingFrameworkGarbageCollection_selectedBackends][]'; 00058 $fieldId = 'task_cachingFrameworkGarbageCollection_selectedBackends'; 00059 $fieldOptions = $this->getCacheBackendOptions($taskInfo['scheduler_cachingFrameworkGarbageCollection_selectedBackends']); 00060 $fieldHtml = 00061 '<select name="' . $fieldName . '" id="' . $fieldId . '" class="wide" size="10" multiple="multiple">' . 00062 $fieldOptions . 00063 '</select>'; 00064 00065 $additionalFields[$fieldID] = array( 00066 'code' => $fieldHtml, 00067 'label' => 'LLL:EXT:scheduler/mod1/locallang.xml:label.cachingFrameworkGarbageCollection.selectBackends', 00068 'cshKey' => '_MOD_tools_txschedulerM1', 00069 'cshLabel' => $fieldId, 00070 ); 00071 00072 return $additionalFields; 00073 } 00074 00075 /** 00076 * Checks that all selected backends exist in available backend list 00077 * 00078 * @param array Reference to the array containing the data submitted by the user 00079 * @param tx_scheduler_Module Reference to the calling object (Scheduler's BE module) 00080 * @return boolean True if validation was ok (or selected class is not relevant), false otherwise 00081 */ 00082 public function validateAdditionalFields(array &$submittedData, tx_scheduler_Module $parentObject) { 00083 $validData = TRUE; 00084 00085 $availableBackends = $this->getRegisteredBackends(); 00086 $invalidBackends = array_diff($submittedData['scheduler_cachingFrameworkGarbageCollection_selectedBackends'], $availableBackends); 00087 if (!empty($invalidBackends)) { 00088 $validData = FALSE; 00089 } 00090 00091 return $validData; 00092 } 00093 00094 /** 00095 * Save selected backends in task object 00096 * 00097 * @param array Contains data submitted by the user 00098 * @param tx_scheduler_Task Reference to the current task object 00099 * @return void 00100 */ 00101 public function saveAdditionalFields(array $submittedData, tx_scheduler_Task $task) { 00102 $task->selectedBackends = $submittedData['scheduler_cachingFrameworkGarbageCollection_selectedBackends']; 00103 } 00104 00105 /** 00106 * Build select options of available backends and set currently selected backends 00107 * 00108 * @param array Selected backends 00109 * @return string HTML of selectbox options 00110 */ 00111 protected function getCacheBackendOptions(array $selectedBackends) { 00112 $options = array(); 00113 00114 $availableBackends = $this->getRegisteredBackends(); 00115 foreach ($availableBackends as $backendName) { 00116 if (in_array($backendName, $selectedBackends)) { 00117 $selected = ' selected="selected"'; 00118 } else { 00119 $selected = ''; 00120 } 00121 $options[] = 00122 '<option value="' . $backendName . '"' . $selected . '>' . 00123 $backendName . 00124 '</option>'; 00125 } 00126 00127 return implode($options); 00128 } 00129 00130 /** 00131 * Get all registered caching framework backends 00132 * 00133 * @return array Registered backends 00134 */ 00135 protected function getRegisteredBackends() { 00136 $backends = array(); 00137 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheBackends'])) { 00138 $backends = $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheBackends']; 00139 } 00140 return array_keys($backends); 00141 } 00142 } // End of class 00143 00144 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/scheduler/tasks/class.tx_scheduler_cachingframeworkgarbagecollection_additionalfieldprovider.php'])) { 00145 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/scheduler/tasks/class.tx_scheduler_cachingframeworkgarbagecollection_additionalfieldprovider.php']); 00146 } 00147 00148 ?>
1.8.0