‪TYPO3CMS  9.5
SystemStatusUpdateTaskNotificationEmailField.php
Go to the documentation of this file.
1 <?php
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 
24 
31 {
37  protected ‪$fields = ['notificationEmail', 'notificationAll'];
38 
44  protected ‪$fieldPrefix = 'SystemStatusUpdate';
45 
54  public function ‪getAdditionalFields(array &$taskInfo, $task, ‪SchedulerModuleController $schedulerModule)
55  {
56  $currentSchedulerModuleAction = $schedulerModule->‪getCurrentAction();
57 
58  if ($currentSchedulerModuleAction->equals(‪Action::EDIT)) {
59  $taskInfo[$this->fieldPrefix . 'NotificationEmail'] = $task->getNotificationEmail();
60  $taskInfo[$this->fieldPrefix . 'NotificationAll'] = $task->getNotificationAll();
61  }
62  // build html for additional email field
63  $fieldName = $this->‪getFullFieldName('notificationEmail');
64  $fieldId = 'task_' . $fieldName;
65  $fieldHtml = '<textarea class="form-control" ' . 'rows="5" cols="50" name="tx_scheduler[' . $fieldName . ']" ' . 'id="' . $fieldId . '" ' . '>' . htmlspecialchars($taskInfo[$fieldName]) . '</textarea>';
66 
67  $additionalFields = [];
68  $additionalFields[$fieldId] = [
69  'code' => $fieldHtml,
70  'label' => 'LLL:EXT:reports/Resources/Private/Language/locallang_reports.xlf:status_updateTaskField_notificationEmails',
71  'cshKey' => '',
72  'cshLabel' => $fieldId
73  ];
74 
75  // build html for additional mail all checkbox field
76  $fieldName = $this->‪getFullFieldName('notificationAll');
77  $fieldId = 'task_' . $fieldName;
78  $fieldHtml = '<input type="checkbox" name="tx_scheduler[' . $fieldName . ']" id="' . $fieldId . '" value="1"' . ($taskInfo[$fieldName] ? ' checked="checked"' : '') . '>';
79 
80  $additionalFields[$fieldId] = [
81  'code' => $fieldHtml,
82  'label' => 'LLL:EXT:reports/Resources/Private/Language/locallang_reports.xlf:status_updateTaskField_notificationAll',
83  'cshKey' => '',
84  'cshLabel' => $fieldId
85  ];
86 
87  return $additionalFields;
88  }
89 
97  public function ‪validateAdditionalFields(array &$submittedData, ‪SchedulerModuleController $schedulerModule)
98  {
99  $validInput = true;
100  $notificationEmails = GeneralUtility::trimExplode(LF, $submittedData[$this->fieldPrefix . 'NotificationEmail'], true);
101  foreach ($notificationEmails as $notificationEmail) {
102  if (!GeneralUtility::validEmail($notificationEmail)) {
103  $validInput = false;
104  break;
105  }
106  }
107  if (!$validInput || empty($submittedData[$this->fieldPrefix . 'NotificationEmail'])) {
108  $this->‪addMessage($this->‪getLanguageService()->sL('LLL:EXT:reports/Resources/Private/Language/locallang_reports.xlf:status_updateTaskField_notificationEmails_invalid'), ‪FlashMessage::ERROR);
109  $validInput = false;
110  }
111  return $validInput;
112  }
113 
121  public function ‪saveAdditionalFields(array $submittedData, ‪AbstractTask $task)
122  {
123  if (!$task instanceof ‪SystemStatusUpdateTask) {
124  throw new \InvalidArgumentException('Expected a task of type ' . SystemStatusUpdateTask::class . ', but got ' . get_class($task), 1295012802);
125  }
126  $task->setNotificationEmail($submittedData[$this->fieldPrefix . 'NotificationEmail']);
127  $task->setNotificationAll(!empty($submittedData[$this->fieldPrefix . 'NotificationAll']));
128  }
129 
136  protected function ‪getFullFieldName($fieldName)
137  {
138  return $this->fieldPrefix . ucfirst($fieldName);
139  }
140 
144  protected function ‪getLanguageService()
145  {
146  return ‪$GLOBALS['LANG'];
147  }
148 }
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTask
Definition: SystemStatusUpdateTask.php:29
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTaskNotificationEmailField\saveAdditionalFields
‪saveAdditionalFields(array $submittedData, AbstractTask $task)
Definition: SystemStatusUpdateTaskNotificationEmailField.php:119
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTaskNotificationEmailField\validateAdditionalFields
‪bool validateAdditionalFields(array &$submittedData, SchedulerModuleController $schedulerModule)
Definition: SystemStatusUpdateTaskNotificationEmailField.php:95
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTaskNotificationEmailField\getAdditionalFields
‪array getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $schedulerModule)
Definition: SystemStatusUpdateTaskNotificationEmailField.php:52
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTaskNotificationEmailField\$fieldPrefix
‪string $fieldPrefix
Definition: SystemStatusUpdateTaskNotificationEmailField.php:42
‪TYPO3\CMS\Scheduler\AbstractAdditionalFieldProvider
Definition: AbstractAdditionalFieldProvider.php:26
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTaskNotificationEmailField\getLanguageService
‪LanguageService getLanguageService()
Definition: SystemStatusUpdateTaskNotificationEmailField.php:142
‪TYPO3\CMS\Scheduler\AbstractAdditionalFieldProvider\addMessage
‪addMessage(string $message, int $severity=FlashMessage::OK)
Definition: AbstractAdditionalFieldProvider.php:33
‪TYPO3\CMS\Scheduler\Task\AbstractTask
Definition: AbstractTask.php:32
‪TYPO3\CMS\Scheduler\Controller\SchedulerModuleController
Definition: SchedulerModuleController.php:53
‪TYPO3\CMS\Scheduler\Task\Enumeration\Action\EDIT
‪const EDIT
Definition: Action.php:28
‪TYPO3\CMS\Scheduler\Controller\SchedulerModuleController\getCurrentAction
‪Action getCurrentAction()
Definition: SchedulerModuleController.php:198
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:22
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTaskNotificationEmailField\getFullFieldName
‪string getFullFieldName($fieldName)
Definition: SystemStatusUpdateTaskNotificationEmailField.php:134
‪TYPO3\CMS\Scheduler\Task\Enumeration\Action
Definition: Action.php:24
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTaskNotificationEmailField
Definition: SystemStatusUpdateTaskNotificationEmailField.php:31
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Reports\Task
Definition: SystemStatusUpdateTask.php:2
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:29
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTaskNotificationEmailField\$fields
‪array $fields
Definition: SystemStatusUpdateTaskNotificationEmailField.php:36
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:29