Cleanup: Updated copyright comments
[Packages/TYPO3.CMS.git] / typo3 / sysext / reports / tasks / class.tx_reports_tasks_systemstatusupdatetasknotificationemailfield.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010-2011 Ingo Renner <ingo@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 /**
27 * Additional field to set the notification email address(es) for system health
28 * issue notifications.
29 *
30 * @author Ingo Renner <ingo@typo3.org>
31 * @package TYPO3
32 * @subpackage reports
33 */
34 class tx_reports_tasks_SystemStatusUpdateTaskNotificationEmailField implements tx_scheduler_AdditionalFieldProvider {
35
36
37 /**
38 * Additional fields
39 *
40 * @var array
41 */
42 protected $fields = array('notificationEmail');
43
44 /**
45 * Field prefix.
46 *
47 * @var string
48 */
49 protected $fieldPrefix = 'SystemStatusUpdate';
50
51 /**
52 * Gets additional fields to render in the form to add/edit a task
53 *
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' => ''))
58 */
59 public function getAdditionalFields(array &$taskInfo, $task, tx_scheduler_Module $schedulerModule) {
60 $fields = array('notificationEmail');
61
62 if ($schedulerModule->CMD == 'edit') {
63 $taskInfo[$this->fieldPrefix . 'NotificationEmail'] = $task->getNotificationEmail();
64 }
65
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]) . '" />';
74
75 $additionalFields[$fieldId] = array(
76 'code' => $fieldHtml,
77 'label' => 'LLL:EXT:reports/reports/locallang.xml:status_updateTaskField_' . $field,
78 'cshKey' => '',
79 'cshLabel' => $fieldId
80 );
81 }
82
83 return $additionalFields;
84 }
85
86 /**
87 * Validates the additional fields' values
88 *
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
92 */
93 public function validateAdditionalFields(array &$submittedData, tx_scheduler_Module $schedulerModule) {
94 $validInput = TRUE;
95 $submittedData[$this->fieldPrefix . 'NotificationEmail'] = trim($submittedData[$this->fieldPrefix . 'NotificationEmail']);
96
97 if (
98 empty($submittedData[$this->fieldPrefix . 'NotificationEmail'])
99 || !filter_var($submittedData[$this->fieldPrefix . 'NotificationEmail'], FILTER_VALIDATE_EMAIL)
100 ) {
101 $schedulerModule->addMessage(
102 $GLOBALS['LANG']->sL('LLL:EXT:reports/reports/locallang.xml:status_updateTaskField_notificationEmail_invalid'),
103 t3lib_FlashMessage::ERROR
104 );
105 $validInput = FALSE;
106 }
107
108 return $validInput;
109 }
110
111 /**
112 * Takes care of saving the additional fields' values in the task's object
113 *
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
116 * @return void
117 */
118 public function saveAdditionalFields(array $submittedData, tx_scheduler_Task $task) {
119
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),
123 1295012802
124 );
125 }
126
127 $task->setNotificationEmail($submittedData[$this->fieldPrefix . 'NotificationEmail']);
128 }
129
130 /**
131 * Constructs the full field name which can be used in HTML markup.
132 *
133 * @param string $fieldName A raw field name
134 * @return string Field name ready to use in HTML markup
135 */
136 protected function getFullFieldName($fieldName) {
137 return $this->fieldPrefix . ucfirst($fieldName);
138 }
139
140 }
141
142
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']);
145 }
146
147 ?>