2 /***************************************************************
5 * (c) 2010 Ingo Renner <ingo@typo3.org>
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.
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
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.
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
27 * Additional field to set the notification email address(es) for system health
28 * issue notifications.
30 * @author Ingo Renner <ingo@typo3.org>
34 class tx_reports_tasks_SystemStatusUpdateTaskNotificationEmailField
implements tx_scheduler_AdditionalFieldProvider
{
42 protected $fields = array('notificationEmail');
49 protected $fieldPrefix = 'SystemStatusUpdate';
52 * Gets additional fields to render in the form to add/edit a task
54 * @param array $taskInfo Values of the fields from the add/edit task form
55 * @param tx_scheduler_Task $task The task object being eddited. Null when adding a task!
56 * @param tx_scheduler_Module $schedulerModule Reference to the scheduler backend module
57 * @return array A two dimensional array, array('Identifier' => array('fieldId' => array('code' => '', 'label' => '', 'cshKey' => '', 'cshLabel' => ''))
59 public function getAdditionalFields(array &$taskInfo, $task, tx_scheduler_Module
$schedulerModule) {
60 $fields = array('notificationEmail');
62 if ($schedulerModule->CMD
== 'edit') {
63 $taskInfo[$this->fieldPrefix
. 'NotificationEmail'] = $task->getNotificationEmail();
66 $additionalFields = array();
67 foreach ($fields as $field) {
68 $fieldName = $this->getFullFieldName($field);
69 $fieldId = 'task_' . $fieldName;
70 $fieldHtml = '<input type="text" '
71 . 'name="tx_scheduler[' . $fieldName . ']" '
72 . 'id="' . $fieldId . '" '
73 . 'value="' . htmlspecialchars($taskInfo[$fieldName]) . '" />';
75 $additionalFields[$fieldId] = array(
77 'label' => 'LLL:EXT:reports/reports/locallang.xml:status_updateTaskField_' . $field,
79 'cshLabel' => $fieldId
83 return $additionalFields;
87 * Validates the additional fields' values
89 * @param array $submittedData An array containing the data submitted by the add/edit task form
90 * @param tx_scheduler_Module $schedulerModule Reference to the scheduler backend module
91 * @return boolean True if validation was ok (or selected class is not relevant), false otherwise
93 public function validateAdditionalFields(array &$submittedData, tx_scheduler_Module
$schedulerModule) {
95 $submittedData[$this->fieldPrefix
. 'NotificationEmail'] = trim($submittedData[$this->fieldPrefix
. 'NotificationEmail']);
98 empty($submittedData[$this->fieldPrefix
. 'NotificationEmail'])
99 ||
!filter_var($submittedData[$this->fieldPrefix
. 'NotificationEmail'], FILTER_VALIDATE_EMAIL
)
101 $schedulerModule->addMessage(
102 $GLOBALS['LANG']->sL('LLL:EXT:reports/reports/locallang.xml:status_updateTaskField_notificationEmail_invalid'),
103 t3lib_FlashMessage
::ERROR
112 * Takes care of saving the additional fields' values in the task's object
114 * @param array $submittedData An array containing the data submitted by the add/edit task form
115 * @param tx_scheduler_Task $task Reference to the scheduler backend module
118 public function saveAdditionalFields(array $submittedData, tx_scheduler_Task
$task) {
120 if (!($task instanceof tx_reports_tasks_SystemStatusUpdateTask
)) {
121 throw new InvalidArgumentException(
122 'Expected a task of type tx_reports_tasks_SystemStatusUpdateTask, but got ' . get_class($task),
127 $task->setNotificationEmail($submittedData[$this->fieldPrefix
. 'NotificationEmail']);
131 * Constructs the full field name which can be used in HTML markup.
133 * @param string $fieldName A raw field name
134 * @return string Field name ready to use in HTML markup
136 protected function getFullFieldName($fieldName) {
137 return $this->fieldPrefix
. ucfirst($fieldName);
143 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['XCLASS']['ext/reports/tasks/class.tx_reports_tasks_systemstatusupdatetasknotificationemailfield.php'])) {
144 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['XCLASS']['ext/reports/tasks/class.tx_reports_tasks_systemstatusupdatetasknotificationemailfield.php']);