‪TYPO3CMS  10.4
SystemStatusUpdateTaskNotificationEmailField.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
25 
32 {
38  protected ‪$fields = ['notificationEmail', 'notificationAll'];
39 
45  protected ‪$fieldPrefix = 'SystemStatusUpdate';
46 
55  public function ‪getAdditionalFields(array &$taskInfo, $task, ‪SchedulerModuleController $schedulerModule)
56  {
57  $currentSchedulerModuleAction = $schedulerModule->‪getCurrentAction();
58 
59  if ($currentSchedulerModuleAction->equals(‪Action::EDIT)) {
60  $taskInfo[$this->fieldPrefix . 'NotificationEmail'] = $task->getNotificationEmail();
61  $taskInfo[$this->fieldPrefix . 'NotificationAll'] = $task->getNotificationAll();
62  }
63  // build html for additional email field
64  $fieldName = $this->‪getFullFieldName('notificationEmail');
65  $fieldId = 'task_' . $fieldName;
66  $fieldHtml = '<textarea class="form-control" rows="5" cols="50" name="tx_scheduler[' . $fieldName . ']" id="' . $fieldId . '" >' . htmlspecialchars($taskInfo[$fieldName]) . '</textarea>';
67 
68  $additionalFields = [];
69  $additionalFields[$fieldId] = [
70  'code' => $fieldHtml,
71  'label' => 'LLL:EXT:reports/Resources/Private/Language/locallang_reports.xlf:status_updateTaskField_notificationEmails',
72  'cshKey' => '',
73  'cshLabel' => $fieldId
74  ];
75 
76  // build html for additional mail all checkbox field
77  $fieldName = $this->‪getFullFieldName('notificationAll');
78  $fieldId = 'task_' . $fieldName;
79  $fieldHtml = '<input type="checkbox" name="tx_scheduler[' . $fieldName . ']" id="' . $fieldId . '" value="1"' . ($taskInfo[$fieldName] ? ' checked="checked"' : '') . '>';
80 
81  $additionalFields[$fieldId] = [
82  'code' => $fieldHtml,
83  'label' => 'LLL:EXT:reports/Resources/Private/Language/locallang_reports.xlf:status_updateTaskField_notificationAll',
84  'cshKey' => '',
85  'cshLabel' => $fieldId
86  ];
87 
88  return $additionalFields;
89  }
90 
98  public function ‪validateAdditionalFields(array &$submittedData, ‪SchedulerModuleController $schedulerModule)
99  {
100  $validInput = true;
101  $notificationEmails = ‪GeneralUtility::trimExplode(LF, $submittedData[$this->fieldPrefix . 'NotificationEmail'], true);
102  foreach ($notificationEmails as $notificationEmail) {
103  if (!GeneralUtility::validEmail($notificationEmail)) {
104  $validInput = false;
105  break;
106  }
107  }
108  if (!$validInput || empty($submittedData[$this->fieldPrefix . 'NotificationEmail'])) {
109  $this->‪addMessage($this->‪getLanguageService()->sL('LLL:EXT:reports/Resources/Private/Language/locallang_reports.xlf:status_updateTaskField_notificationEmails_invalid'), ‪FlashMessage::ERROR);
110  $validInput = false;
111  }
112  return $validInput;
113  }
114 
122  public function ‪saveAdditionalFields(array $submittedData, ‪AbstractTask $task)
123  {
124  if (!$task instanceof ‪SystemStatusUpdateTask) {
125  throw new \InvalidArgumentException('Expected a task of type ' . SystemStatusUpdateTask::class . ', but got ' . get_class($task), 1295012802);
126  }
127  $task->setNotificationEmail($submittedData[$this->fieldPrefix . 'NotificationEmail']);
128  $task->setNotificationAll(!empty($submittedData[$this->fieldPrefix . 'NotificationAll']));
129  }
130 
137  protected function ‪getFullFieldName($fieldName)
138  {
139  return $this->fieldPrefix . ucfirst($fieldName);
140  }
141 
145  protected function ‪getLanguageService()
146  {
147  return ‪$GLOBALS['LANG'];
148  }
149 }
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTask
Definition: SystemStatusUpdateTask.php:33
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTaskNotificationEmailField\saveAdditionalFields
‪saveAdditionalFields(array $submittedData, AbstractTask $task)
Definition: SystemStatusUpdateTaskNotificationEmailField.php:120
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTaskNotificationEmailField\validateAdditionalFields
‪bool validateAdditionalFields(array &$submittedData, SchedulerModuleController $schedulerModule)
Definition: SystemStatusUpdateTaskNotificationEmailField.php:96
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTaskNotificationEmailField\getAdditionalFields
‪array getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $schedulerModule)
Definition: SystemStatusUpdateTaskNotificationEmailField.php:53
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTaskNotificationEmailField\$fieldPrefix
‪string $fieldPrefix
Definition: SystemStatusUpdateTaskNotificationEmailField.php:43
‪TYPO3\CMS\Scheduler\AbstractAdditionalFieldProvider
Definition: AbstractAdditionalFieldProvider.php:28
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTaskNotificationEmailField\getLanguageService
‪LanguageService getLanguageService()
Definition: SystemStatusUpdateTaskNotificationEmailField.php:143
‪TYPO3\CMS\Scheduler\AbstractAdditionalFieldProvider\addMessage
‪addMessage(string $message, int $severity=FlashMessage::OK)
Definition: AbstractAdditionalFieldProvider.php:35
‪TYPO3\CMS\Scheduler\Task\AbstractTask
Definition: AbstractTask.php:35
‪TYPO3\CMS\Scheduler\Controller\SchedulerModuleController
Definition: SchedulerModuleController.php:56
‪TYPO3\CMS\Scheduler\Task\Enumeration\Action\EDIT
‪const EDIT
Definition: Action.php:30
‪TYPO3\CMS\Scheduler\Controller\SchedulerModuleController\getCurrentAction
‪Action getCurrentAction()
Definition: SchedulerModuleController.php:181
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static string[] trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:1059
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:24
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTaskNotificationEmailField\getFullFieldName
‪string getFullFieldName($fieldName)
Definition: SystemStatusUpdateTaskNotificationEmailField.php:135
‪TYPO3\CMS\Scheduler\Task\Enumeration\Action
Definition: Action.php:26
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTaskNotificationEmailField
Definition: SystemStatusUpdateTaskNotificationEmailField.php:32
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Reports\Task
Definition: SystemStatusUpdateTask.php:16
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTaskNotificationEmailField\$fields
‪array $fields
Definition: SystemStatusUpdateTaskNotificationEmailField.php:37
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:31