TYPO3 CMS  TYPO3_8-7
SystemStatusUpdateTaskNotificationEmailField.php
Go to the documentation of this file.
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 
23 
29 {
35  protected $fields = ['notificationEmail', 'notificationAll'];
36 
42  protected $fieldPrefix = 'SystemStatusUpdate';
43 
52  public function getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $schedulerModule)
53  {
54  if ($schedulerModule->CMD === 'edit') {
55  $taskInfo[$this->fieldPrefix . 'NotificationEmail'] = $task->getNotificationEmail();
56  $taskInfo[$this->fieldPrefix . 'NotificationAll'] = $task->getNotificationAll();
57  }
58  // build html for additional email field
59  $fieldName = $this->getFullFieldName('notificationEmail');
60  $fieldId = 'task_' . $fieldName;
61  $fieldHtml = '<textarea class="form-control" ' . 'rows="5" cols="50" name="tx_scheduler[' . $fieldName . ']" ' . 'id="' . $fieldId . '" ' . '>' . htmlspecialchars($taskInfo[$fieldName]) . '</textarea>';
62 
63  $additionalFields = [];
64  $additionalFields[$fieldId] = [
65  'code' => $fieldHtml,
66  'label' => 'LLL:EXT:reports/Resources/Private/Language/locallang_reports.xlf:status_updateTaskField_notificationEmails',
67  'cshKey' => '',
68  'cshLabel' => $fieldId
69  ];
70 
71  // build html for additional mail all checkbox field
72  $fieldName = $this->getFullFieldName('notificationAll');
73  $fieldId = 'task_' . $fieldName;
74  $fieldHtml = '<input type="checkbox" name="tx_scheduler[' . $fieldName . ']" id="' . $fieldId . '" value="1"' . ($taskInfo[$fieldName] ? ' checked="checked"' : '') . '>';
75 
76  $additionalFields[$fieldId] = [
77  'code' => $fieldHtml,
78  'label' => 'LLL:EXT:reports/Resources/Private/Language/locallang_reports.xlf:status_updateTaskField_notificationAll',
79  'cshKey' => '',
80  'cshLabel' => $fieldId
81  ];
82 
83  return $additionalFields;
84  }
85 
93  public function validateAdditionalFields(array &$submittedData, SchedulerModuleController $schedulerModule)
94  {
95  $validInput = true;
96  $notificationEmails = GeneralUtility::trimExplode(LF, $submittedData[$this->fieldPrefix . 'NotificationEmail'], true);
97  foreach ($notificationEmails as $notificationEmail) {
98  if (!GeneralUtility::validEmail($notificationEmail)) {
99  $validInput = false;
100  break;
101  }
102  }
103  if (empty($submittedData[$this->fieldPrefix . 'NotificationEmail']) || !$validInput) {
104  $schedulerModule->addMessage($this->getLanguageService()->sL('LLL:EXT:reports/Resources/Private/Language/locallang_reports.xlf:status_updateTaskField_notificationEmails_invalid'), FlashMessage::ERROR);
105  $validInput = false;
106  }
107  return $validInput;
108  }
109 
116  public function saveAdditionalFields(array $submittedData, AbstractTask $task)
117  {
118  if (!$task instanceof SystemStatusUpdateTask) {
119  throw new \InvalidArgumentException('Expected a task of type ' . SystemStatusUpdateTask::class . ', but got ' . get_class($task), 1295012802);
120  }
121  $task->setNotificationEmail($submittedData[$this->fieldPrefix . 'NotificationEmail']);
122  $task->setNotificationAll(!empty($submittedData[$this->fieldPrefix . 'NotificationAll']));
123  }
124 
131  protected function getFullFieldName($fieldName)
132  {
133  return $this->fieldPrefix . ucfirst($fieldName);
134  }
135 
139  protected function getLanguageService()
140  {
141  return $GLOBALS['LANG'];
142  }
143 }
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $schedulerModule)
validateAdditionalFields(array &$submittedData, SchedulerModuleController $schedulerModule)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']