[TASK] Re-work/simplify copyright header in PHP files - Part 9
[Packages/TYPO3.CMS.git] / typo3 / sysext / reports / Classes / Task / SystemStatusUpdateTaskNotificationEmailField.php
1 <?php
2 namespace TYPO3\CMS\Reports\Task;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16 /**
17 * Additional field to set the notification email address(es) for system health
18 * issue notifications.
19 *
20 * @author Ingo Renner <ingo@typo3.org>
21 */
22 class SystemStatusUpdateTaskNotificationEmailField implements \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface {
23
24 /**
25 * Additional fields
26 *
27 * @var array
28 */
29 protected $fields = array('notificationEmail');
30
31 /**
32 * Field prefix.
33 *
34 * @var string
35 */
36 protected $fieldPrefix = 'SystemStatusUpdate';
37
38 /**
39 * Gets additional fields to render in the form to add/edit a task
40 *
41 * @param array $taskInfo Values of the fields from the add/edit task form
42 * @param \TYPO3\CMS\Scheduler\Task\AbstractTask $task The task object being edited. Null when adding a task!
43 * @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $schedulerModule Reference to the scheduler backend module
44 * @return array A two dimensional array, array('Identifier' => array('fieldId' => array('code' => '', 'label' => '', 'cshKey' => '', 'cshLabel' => ''))
45 */
46 public function getAdditionalFields(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $schedulerModule) {
47 $fields = array('notificationEmail' => 'textarea');
48 if ($schedulerModule->CMD == 'edit') {
49 $taskInfo[$this->fieldPrefix . 'NotificationEmail'] = $task->getNotificationEmail();
50 }
51 // build html for additional email field
52 $fieldName = $this->getFullFieldName('notificationEmail');
53 $fieldId = 'task_' . $fieldName;
54 $fieldHtml = '<textarea ' . 'rows="5" cols="50" name="tx_scheduler[' . $fieldName . ']" ' . 'id="' . $fieldId . '" ' . '>' . htmlspecialchars($taskInfo[$fieldName]) . '</textarea>';
55
56 $additionalFields = array();
57 $additionalFields[$fieldId] = array(
58 'code' => $fieldHtml,
59 'label' => 'LLL:EXT:reports/reports/locallang.xlf:status_updateTaskField_notificationEmails',
60 'cshKey' => '',
61 'cshLabel' => $fieldId
62 );
63
64 return $additionalFields;
65 }
66
67 /**
68 * Validates the additional fields' values
69 *
70 * @param array $submittedData An array containing the data submitted by the add/edit task form
71 * @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $schedulerModule Reference to the scheduler backend module
72 * @return boolean TRUE if validation was ok (or selected class is not relevant), FALSE otherwise
73 */
74 public function validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $schedulerModule) {
75 $validInput = TRUE;
76 $notificationEmails = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(LF, $submittedData[$this->fieldPrefix . 'NotificationEmail'], TRUE);
77 foreach ($notificationEmails as $notificationEmail) {
78 if (!\TYPO3\CMS\Core\Utility\GeneralUtility::validEmail($notificationEmail)) {
79 $validInput = FALSE;
80 break;
81 }
82 }
83 if (empty($submittedData[$this->fieldPrefix . 'NotificationEmail']) || !$validInput) {
84 $schedulerModule->addMessage($GLOBALS['LANG']->sL('LLL:EXT:reports/reports/locallang.xlf:status_updateTaskField_notificationEmails_invalid'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
85 $validInput = FALSE;
86 }
87 return $validInput;
88 }
89
90 /**
91 * Takes care of saving the additional fields' values in the task's object
92 *
93 * @param array $submittedData An array containing the data submitted by the add/edit task form
94 * @param \TYPO3\CMS\Scheduler\Task\AbstractTask $task Reference to the scheduler backend module
95 * @return void
96 */
97 public function saveAdditionalFields(array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask $task) {
98 if (!$task instanceof \TYPO3\CMS\Reports\Task\SystemStatusUpdateTask) {
99 throw new \InvalidArgumentException('Expected a task of type TYPO3\\CMS\\Reports\\Task\\SystemStatusUpdateTask, but got ' . get_class($task), 1295012802);
100 }
101 $task->setNotificationEmail($submittedData[$this->fieldPrefix . 'NotificationEmail']);
102 }
103
104 /**
105 * Constructs the full field name which can be used in HTML markup.
106 *
107 * @param string $fieldName A raw field name
108 * @return string Field name ready to use in HTML markup
109 */
110 protected function getFullFieldName($fieldName) {
111 return $this->fieldPrefix . ucfirst($fieldName);
112 }
113
114 }