Email   A
last analyzed

Complexity

Total Complexity 26

Size/Duplication

Total Lines 247
Duplicated Lines 0 %

Importance

Changes 8
Bugs 0 Features 0
Metric Value
eloc 117
c 8
b 0
f 0
dl 0
loc 247
rs 10
wmc 26

3 Methods

Rating   Name   Duplication   Size   Complexity  
B validateFields() 0 29 8
A saveFields() 0 12 1
F getFields() 0 155 17
1
<?php
2
3
/**
4
 * @license GPLv3, http://www.gnu.org/copyleft/gpl.html
5
 * @copyright Metaways Infosystems GmbH, 2014
6
 * @copyright Aimeos (aimeos.org), 2014-2016
7
 * @package TYPO3
8
 */
9
10
11
namespace Aimeos\Aimeos\Scheduler\Provider;
12
13
use Aimeos\Aimeos\Base;
14
use Aimeos\Aimeos\Scheduler;
15
use TYPO3\CMS\Scheduler\Task\Enumeration\Action;
16
17
18
/**
19
 * Common methods for Aimeos' e-mail additional field providers.
20
 *
21
 * @package TYPO3
22
 */
23
abstract class Email extends AbstractProvider
24
{
25
    private $fieldSenderFrom = 'aimeos_sender_from';
26
    private $fieldSenderEmail = 'aimeos_sender_email';
27
    private $fieldReplyEmail = 'aimeos_reply_email';
28
    private $fieldPageLogin = 'aimeos_pageid_login';
29
    private $fieldPageDetail = 'aimeos_pageid_detail';
30
    private $fieldPageCatalog = 'aimeos_pageid_catalog';
31
    private $fieldPageDownload = 'aimeos_pageid_download';
32
    private $fieldTemplateBaseurl = 'aimeos_template_baseurl';
33
34
35
    /**
36
     * Fields generation.
37
     * This method is used to define new fields for adding or editing a task
38
     * In this case, it adds a page ID field
39
     *
40
     * @param array $taskInfo Reference to the array containing the info used in the add/edit form
41
     * @param object $task When editing, reference to the current task object. Null when adding.
42
     * @param object $parentObject Reference to the calling object (Scheduler's BE module)
43
     * @return array Array containg all the information pertaining to the additional fields
44
     *        The array is multidimensional, keyed to the task class name and each field's id
45
     *        For each field it provides an associative sub-array with the following:
46
     *            ['code']        => The HTML code for the field
47
     *            ['label']        => The label of the field (possibly localized)
48
     *            ['cshKey']        => The CSH key for the field
49
     *            ['cshLabel']    => The code of the CSH label
50
     */
51
    protected function getFields(array &$taskInfo, $task, $parentObject)
52
    {
53
        $additionalFields = [];
54
55
56
        // In case of editing a task, set to the internal value if data wasn't already submitted
57
        if (empty($taskInfo[$this->fieldSenderFrom]) && $parentObject->getCurrentAction()->equals(Action::EDIT)) {
58
            $taskInfo[$this->fieldSenderFrom] = $task->{$this->fieldSenderFrom} ?? '';
59
        }
60
61
        $taskInfo[$this->fieldSenderFrom] = htmlspecialchars($taskInfo[$this->fieldSenderFrom] ?? '', ENT_QUOTES, 'UTF-8');
62
63
        $fieldStr = '<input class="form-control" name="tx_scheduler[%1$s]" id="%1$s" value="%2$s">';
64
        $fieldCode = sprintf($fieldStr, $this->fieldSenderFrom, $taskInfo[$this->fieldSenderFrom]);
65
66
        $additionalFields[$this->fieldSenderFrom] = [
67
            'code'     => $fieldCode,
68
            'label'    => 'LLL:EXT:aimeos/Resources/Private/Language/scheduler.xlf:email.label.from-name',
69
            'cshKey'   => 'xMOD_tx_aimeos',
70
            'cshLabel' => $this->fieldSenderFrom
71
        ];
72
73
74
        // In case of editing a task, set to the internal value if data wasn't already submitted
75
        if (empty($taskInfo[$this->fieldSenderEmail]) && $parentObject->getCurrentAction()->equals(Action::EDIT)) {
76
            $taskInfo[$this->fieldSenderEmail] = $task->{$this->fieldSenderEmail} ?? '';
77
        }
78
79
        $taskInfo[$this->fieldSenderEmail] = htmlspecialchars($taskInfo[$this->fieldSenderEmail] ?? '', ENT_QUOTES, 'UTF-8');
80
81
        $fieldStr = '<input class="form-control" name="tx_scheduler[%1$s]" id="%1$s" value="%2$s">';
82
        $fieldCode = sprintf($fieldStr, $this->fieldSenderEmail, $taskInfo[$this->fieldSenderEmail]);
83
84
        $additionalFields[$this->fieldSenderEmail] = [
85
            'code'     => $fieldCode,
86
            'label'    => 'LLL:EXT:aimeos/Resources/Private/Language/scheduler.xlf:email.label.from-email',
87
            'cshKey'   => 'xMOD_tx_aimeos',
88
            'cshLabel' => $this->fieldSenderEmail
89
        ];
90
91
92
        // In case of editing a task, set to the internal value if data wasn't already submitted
93
        if (empty($taskInfo[$this->fieldReplyEmail]) && $parentObject->getCurrentAction()->equals(Action::EDIT)) {
94
            $taskInfo[$this->fieldReplyEmail] = $task->{$this->fieldReplyEmail} ?? '';
95
        }
96
97
        $taskInfo[$this->fieldReplyEmail] = htmlspecialchars($taskInfo[$this->fieldReplyEmail] ?? '', ENT_QUOTES, 'UTF-8');
98
99
        $fieldStr = '<input class="form-control" name="tx_scheduler[%1$s]" id="%1$s" value="%2$s">';
100
        $fieldCode = sprintf($fieldStr, $this->fieldReplyEmail, $taskInfo[$this->fieldReplyEmail]);
101
102
        $additionalFields[$this->fieldReplyEmail] = [
103
            'code'     => $fieldCode,
104
            'label'    => 'LLL:EXT:aimeos/Resources/Private/Language/scheduler.xlf:email.label.reply-email',
105
            'cshKey'   => 'xMOD_tx_aimeos',
106
            'cshLabel' => $this->fieldReplyEmail
107
        ];
108
109
110
        // In case of editing a task, set to the internal value if data wasn't already submitted
111
        if (empty($taskInfo[$this->fieldPageCatalog]) && $parentObject->getCurrentAction()->equals(Action::EDIT)) {
112
            $taskInfo[$this->fieldPageCatalog] = $task->{$this->fieldPageCatalog} ?? '';
113
        }
114
115
        $taskInfo[$this->fieldPageCatalog] = htmlspecialchars($taskInfo[$this->fieldPageCatalog] ?? '', ENT_QUOTES, 'UTF-8');
116
117
        $fieldStr = '<input class="form-control" name="tx_scheduler[%1$s]" id="%1$s" value="%2$s">';
118
        $fieldCode = sprintf($fieldStr, $this->fieldPageCatalog, $taskInfo[$this->fieldPageCatalog]);
119
120
        $additionalFields[$this->fieldPageCatalog] = [
121
            'code'     => $fieldCode,
122
            'label'    => 'LLL:EXT:aimeos/Resources/Private/Language/scheduler.xlf:email.label.page-catalog',
123
            'cshKey'   => 'xMOD_tx_aimeos',
124
            'cshLabel' => $this->fieldPageCatalog
125
        ];
126
127
128
        // In case of editing a task, set to the internal value if data wasn't already submitted
129
        if (empty($taskInfo[$this->fieldPageDetail]) && $parentObject->getCurrentAction()->equals(Action::EDIT)) {
130
            $taskInfo[$this->fieldPageDetail] = $task->{$this->fieldPageDetail} ?? '';
131
        }
132
133
        $taskInfo[$this->fieldPageDetail] = htmlspecialchars($taskInfo[$this->fieldPageDetail] ?? '', ENT_QUOTES, 'UTF-8');
134
135
        $fieldStr = '<input class="form-control" name="tx_scheduler[%1$s]" id="%1$s" value="%2$s">';
136
        $fieldCode = sprintf($fieldStr, $this->fieldPageDetail, $taskInfo[$this->fieldPageDetail]);
137
138
        $additionalFields[$this->fieldPageDetail] = [
139
            'code'     => $fieldCode,
140
            'label'    => 'LLL:EXT:aimeos/Resources/Private/Language/scheduler.xlf:email.label.page-detail',
141
            'cshKey'   => 'xMOD_tx_aimeos',
142
            'cshLabel' => $this->fieldPageDetail
143
        ];
144
145
146
        // In case of editing a task, set to the internal value if data wasn't already submitted
147
        if (empty($taskInfo[$this->fieldPageDownload]) && $parentObject->getCurrentAction()->equals(Action::EDIT)) {
148
            $taskInfo[$this->fieldPageDownload] = $task->{$this->fieldPageDownload} ?? '';
149
        }
150
151
        $taskInfo[$this->fieldPageDownload] = htmlspecialchars($taskInfo[$this->fieldPageDownload] ?? '', ENT_QUOTES, 'UTF-8');
152
153
        $fieldStr = '<input class="form-control" name="tx_scheduler[%1$s]" id="%1$s" value="%2$s">';
154
        $fieldCode = sprintf($fieldStr, $this->fieldPageDownload, $taskInfo[$this->fieldPageDownload]);
155
156
        $additionalFields[$this->fieldPageDownload] = [
157
            'code'     => $fieldCode,
158
            'label'    => 'LLL:EXT:aimeos/Resources/Private/Language/scheduler.xlf:email.label.page-download',
159
            'cshKey'   => 'xMOD_tx_aimeos',
160
            'cshLabel' => $this->fieldPageDownload
161
        ];
162
163
164
        // In case of editing a task, set to the internal value if data wasn't already submitted
165
        if (empty($taskInfo[$this->fieldPageLogin]) && $parentObject->getCurrentAction()->equals(Action::EDIT)) {
166
            $taskInfo[$this->fieldPageLogin] = $task->{$this->fieldPageLogin} ?? '';
167
        }
168
169
        $taskInfo[$this->fieldPageLogin] = htmlspecialchars($taskInfo[$this->fieldPageLogin] ?? '', ENT_QUOTES, 'UTF-8');
170
171
        $fieldStr = '<input class="form-control" name="tx_scheduler[%1$s]" id="%1$s" value="%2$s">';
172
        $fieldCode = sprintf($fieldStr, $this->fieldPageLogin, $taskInfo[$this->fieldPageLogin]);
173
174
        $additionalFields[$this->fieldPageLogin] = [
175
            'code'     => $fieldCode,
176
            'label'    => 'LLL:EXT:aimeos/Resources/Private/Language/scheduler.xlf:email.label.page-login',
177
            'cshKey'   => 'xMOD_tx_aimeos',
178
            'cshLabel' => $this->fieldPageLogin
179
        ];
180
181
182
        // In case of editing a task, set to the internal value if data wasn't already submitted
183
        if (empty($taskInfo[$this->fieldTemplateBaseurl]) && $parentObject->getCurrentAction()->equals(Action::EDIT)) {
184
            $taskInfo[$this->fieldTemplateBaseurl] = $task->{$this->fieldTemplateBaseurl} ?? '';
185
        }
186
187
        $taskInfo[$this->fieldTemplateBaseurl] = htmlspecialchars($taskInfo[$this->fieldTemplateBaseurl] ?? '', ENT_QUOTES, 'UTF-8');
188
189
        $path = 'typo3conf/ext/aimeos/Resources/Public/Themes/default';
190
        $path = $taskInfo[$this->fieldTemplateBaseurl] = $taskInfo[$this->fieldTemplateBaseurl] ?? $path;
191
192
        $fieldStr = '<input class="form-control" name="tx_scheduler[%1$s]" id="%1$s" value="%2$s">';
193
        $fieldCode = sprintf($fieldStr, $this->fieldTemplateBaseurl, $path);
194
195
        $additionalFields[$this->fieldTemplateBaseurl] = [
196
            'code'     => $fieldCode,
197
            'label'    => 'LLL:EXT:aimeos/Resources/Private/Language/scheduler.xlf:email.label.template-baseurl',
198
            'cshKey'   => 'xMOD_tx_aimeos',
199
            'cshLabel' => $this->fieldTemplateBaseurl
200
        ];
201
202
203
        $additionalFields += parent::getFields($taskInfo, $task, $parentObject);
204
205
        return $additionalFields;
206
    }
207
208
209
    /**
210
     * Store fields.
211
     * This method is used to save any additional input into the current task object
212
     * if the task class matches
213
     *
214
     * @param array $submittedData Array containing the data submitted by the user
215
     * @param object $task Reference to the current task object
216
     */
217
    protected function saveFields(array $submittedData, $task)
218
    {
219
        parent::saveFields($submittedData, $task);
220
221
        $task->{$this->fieldSenderFrom} = $submittedData[$this->fieldSenderFrom] ?? '';
222
        $task->{$this->fieldSenderEmail} = $submittedData[$this->fieldSenderEmail] ?? '';
223
        $task->{$this->fieldReplyEmail} = $submittedData[$this->fieldReplyEmail] ?? '';
224
        $task->{$this->fieldPageCatalog} = $submittedData[$this->fieldPageCatalog] ?? '';
225
        $task->{$this->fieldPageDetail} = $submittedData[$this->fieldPageDetail] ?? '';
226
        $task->{$this->fieldPageLogin} = $submittedData[$this->fieldPageLogin] ?? '';
227
        $task->{$this->fieldPageDownload} = $submittedData[$this->fieldPageDownload] ?? '';
228
        $task->{$this->fieldTemplateBaseurl} = $submittedData[$this->fieldTemplateBaseurl] ?? '';
229
    }
230
231
232
    /**
233
     * Fields validation.
234
     * This method checks if page id given in the 'Hide content' specific task is int+
235
     * If the task class is not relevant, the method is expected to return true
236
     *
237
     * @param array $submittedData Reference to the array containing the data submitted by the user
238
     * @param tx_scheduler_Module $parentObject Reference to the calling object (Scheduler's BE module)
0 ignored issues
show
Bug introduced by
The type Aimeos\Aimeos\Scheduler\...der\tx_scheduler_Module was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
239
     * @return boolean True if validation was ok (or selected class is not relevant), false otherwise
240
     */
241
    protected function validateFields(array &$submittedData, $parentObject)
242
    {
243
        if (preg_match('/^.+@[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)*$/', $submittedData[$this->fieldSenderEmail] ?? '') !== 1) {
244
            throw new \InvalidArgumentException($GLOBALS['LANG']->sL('LLL:EXT:aimeos/Resources/Private/Language/scheduler.xlf:email.error.from-email.invalid'));
245
        }
246
247
        if (($submittedData[$this->fieldReplyEmail] ?? '') && preg_match('/^.+@[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)*$/', $submittedData[$this->fieldReplyEmail]) !== 1) {
248
            throw new \InvalidArgumentException($GLOBALS['LANG']->sL('LLL:EXT:aimeos/Resources/Private/Language/scheduler.xlf:email.error.reply-email.invalid'));
249
        }
250
251
        if (preg_match('/^[0-9]+$/', $submittedData[$this->fieldPageCatalog] ?? '') !== 1) {
252
            throw new \InvalidArgumentException($GLOBALS['LANG']->sL('LLL:EXT:aimeos/Resources/Private/Language/scheduler.xlf:email.error.page-catalog.invalid'));
253
        }
254
255
        if (preg_match('/^[0-9]+$/', $submittedData[$this->fieldPageDetail] ?? '') !== 1) {
256
            throw new \InvalidArgumentException($GLOBALS['LANG']->sL('LLL:EXT:aimeos/Resources/Private/Language/scheduler.xlf:email.error.page-detail.invalid'));
257
        }
258
259
        if (preg_match('/^[0-9]+$/', $submittedData[$this->fieldPageLogin] ?? '') !== 1) {
260
            throw new \InvalidArgumentException($GLOBALS['LANG']->sL('LLL:EXT:aimeos/Resources/Private/Language/scheduler.xlf:email.error.page-login.invalid'));
261
        }
262
263
        if (preg_match('/^[0-9]+$/', $submittedData[$this->fieldPageDownload] ?? '') !== 1) {
264
            throw new \InvalidArgumentException($GLOBALS['LANG']->sL('LLL:EXT:aimeos/Resources/Private/Language/scheduler.xlf:email.error.page-download.invalid'));
265
        }
266
267
        parent::validateFields($submittedData, $parentObject);
268
269
        return true;
270
    }
271
}
272