e0400f7130f8c81daf27469042a65b8f5d1efc53
[Packages/TYPO3.CMS.git] / typo3 / sysext / reports / Classes / Task / SystemStatusUpdateTaskNotificationEmailField.php
1 <?php
2 namespace TYPO3\CMS\Reports\Task;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2010-2011 Ingo Renner <ingo@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
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 */
32 class SystemStatusUpdateTaskNotificationEmailField implements \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface {
33
34 /**
35 * Additional fields
36 *
37 * @var array
38 */
39 protected $fields = array('notificationEmail');
40
41 /**
42 * Field prefix.
43 *
44 * @var string
45 */
46 protected $fieldPrefix = 'SystemStatusUpdate';
47
48 /**
49 * Gets additional fields to render in the form to add/edit a task
50 *
51 * @param array $taskInfo Values of the fields from the add/edit task form
52 * @param \TYPO3\CMS\Scheduler\Task\AbstractTask $task The task object being eddited. Null when adding a task!
53 * @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $schedulerModule Reference to the scheduler backend module
54 * @return array A two dimensional array, array('Identifier' => array('fieldId' => array('code' => '', 'label' => '', 'cshKey' => '', 'cshLabel' => ''))
55 */
56 public function getAdditionalFields(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $schedulerModule) {
57 $fields = array('notificationEmail');
58 if ($schedulerModule->CMD == 'edit') {
59 $taskInfo[$this->fieldPrefix . 'NotificationEmail'] = $task->getNotificationEmail();
60 }
61 $additionalFields = array();
62 foreach ($fields as $field) {
63 $fieldName = $this->getFullFieldName($field);
64 $fieldId = 'task_' . $fieldName;
65 $fieldHtml = '<input type="text" ' . 'name="tx_scheduler[' . $fieldName . ']" ' . 'id="' . $fieldId . '" ' . 'value="' . htmlspecialchars($taskInfo[$fieldName]) . '" />';
66 $additionalFields[$fieldId] = array(
67 'code' => $fieldHtml,
68 'label' => 'LLL:EXT:reports/reports/locallang.xml:status_updateTaskField_' . $field,
69 'cshKey' => '',
70 'cshLabel' => $fieldId
71 );
72 }
73 return $additionalFields;
74 }
75
76 /**
77 * Validates the additional fields' values
78 *
79 * @param array $submittedData An array containing the data submitted by the add/edit task form
80 * @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $schedulerModule Reference to the scheduler backend module
81 * @return boolean TRUE if validation was ok (or selected class is not relevant), FALSE otherwise
82 */
83 public function validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $schedulerModule) {
84 $validInput = TRUE;
85 $submittedData[$this->fieldPrefix . 'NotificationEmail'] = trim($submittedData[$this->fieldPrefix . 'NotificationEmail']);
86 if (empty($submittedData[$this->fieldPrefix . 'NotificationEmail']) || !filter_var($submittedData[($this->fieldPrefix . 'NotificationEmail')], FILTER_VALIDATE_EMAIL)) {
87 $schedulerModule->addMessage($GLOBALS['LANG']->sL('LLL:EXT:reports/reports/locallang.xml:status_updateTaskField_notificationEmail_invalid'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
88 $validInput = FALSE;
89 }
90 return $validInput;
91 }
92
93 /**
94 * Takes care of saving the additional fields' values in the task's object
95 *
96 * @param array $submittedData An array containing the data submitted by the add/edit task form
97 * @param \TYPO3\CMS\Scheduler\Task\AbstractTask $task Reference to the scheduler backend module
98 * @return void
99 */
100 public function saveAdditionalFields(array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask $task) {
101 if (!$task instanceof \TYPO3\CMS\Reports\Task\SystemStatusUpdateTask) {
102 throw new \InvalidArgumentException('Expected a task of type TYPO3\\CMS\\Reports\\Task\\SystemStatusUpdateTask, but got ' . get_class($task), 1295012802);
103 }
104 $task->setNotificationEmail($submittedData[$this->fieldPrefix . 'NotificationEmail']);
105 }
106
107 /**
108 * Constructs the full field name which can be used in HTML markup.
109 *
110 * @param string $fieldName A raw field name
111 * @return string Field name ready to use in HTML markup
112 */
113 protected function getFullFieldName($fieldName) {
114 return $this->fieldPrefix . ucfirst($fieldName);
115 }
116
117 }
118
119
120 ?>