Completed
Push — master ( b01b7f...f51276 )
by Torben
05:03 queued 03:26
created

Field::getDatepickermode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
namespace DERHANSEN\SfEventMgt\Domain\Model\Registration;
3
4
/*
5
 * This file is part of the Extension "sf_event_mgt" for TYPO3 CMS.
6
 *
7
 * For the full copyright and license information, please read the
8
 * LICENSE.txt file that was distributed with this source code.
9
 */
10
11
use DERHANSEN\SfEventMgt\Domain\Model\Event;
12
use DERHANSEN\SfEventMgt\Utility\FieldType;
13
use DERHANSEN\SfEventMgt\Utility\FieldValueType;
14
use TYPO3\CMS\Core\Utility\GeneralUtility;
15
16
/**
17
 * Field
18
 *
19
 * @author Torben Hansen <[email protected]>
20
 */
21
class Field extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
22
{
23
    /**
24
     * The title
25
     *
26
     * @var string
27
     */
28
    protected $title = '';
29
30
    /**
31
     * Type - possible values
32
     *
33
     *  "input", "radio", "check", "textarea"
34
     *
35
     * @var string
36
     */
37
    protected $type = '';
38
39
    /**
40
     * Field is required
41
     *
42
     * @var bool
43
     */
44
    protected $required = false;
45
46
    /**
47
     * Placeholder
48
     *
49
     * @var string
50
     */
51
    protected $placeholder = '';
52
53
    /**
54
     * Default value
55
     *
56
     * @var string
57
     */
58
    protected $defaultValue = '';
59
60
    /**
61
     * Settings
62
     *
63
     * @var string
64
     */
65
    protected $settings = '';
66
67
    /**
68
     * @var \DERHANSEN\SfEventMgt\Domain\Model\Event
69
     */
70
    protected $event = null;
71
72
    /**
73
     * @var string
74
     */
75
    protected $text;
76
77
    /**
78
     * @var int
79
     */
80
    protected $datepickermode;
81
82
    /**
83
     * @var string
84
     */
85
    protected $datepickermodeType;
86
87
    /**
88
     * Returns the title
89
     *
90
     * @return string
91
     */
92
    public function getTitle()
93
    {
94
        return $this->title;
95
    }
96
97
    /**
98
     * Sets the title
99
     *
100
     * @param string $title
101
     * @return void
102
     */
103
    public function setTitle($title)
104
    {
105
        $this->title = $title;
106
    }
107
108
    /**
109
     * Returns the type
110
     *
111
     * @return string
112
     */
113
    public function getType()
114
    {
115
        return $this->type;
116
    }
117
118
    /**
119
     * Sets the type
120
     *
121
     * @param string $type
122
     * @return void
123
     */
124
    public function setType($type)
125
    {
126
        $this->type = $type;
127
    }
128
129
    /**
130
     * Returns the required flag
131
     *
132
     * @return bool
133
     */
134
    public function getRequired()
135
    {
136
        return $this->required;
137
    }
138
139
    /**
140
     * Sets the required flag
141
     *
142
     * @param bool $required
143
     */
144
    public function setRequired($required)
145
    {
146
        $this->required = $required;
147
    }
148
149
    /**
150
     * Returns placeholder
151
     *
152
     * @return string
153
     */
154
    public function getPlaceholder()
155
    {
156
        return $this->placeholder;
157
    }
158
159
    /**
160
     * Sets placeholder
161
     *
162
     * @param string $placeholder
163
     * @return void
164
     */
165
    public function setPlaceholder($placeholder)
166
    {
167
        $this->placeholder = $placeholder;
168
    }
169
170
    /**
171
     * Returns default value
172
     *
173
     * @return string
174
     */
175
    public function getDefaultValue()
176
    {
177
        return $this->defaultValue;
178
    }
179
180
    /**
181
     * Sets default value
182
     *
183
     * @param string $defaultValue
184
     */
185
    public function setDefaultValue($defaultValue)
186
    {
187
        $this->defaultValue = $defaultValue;
188
    }
189
190
    /**
191
     * Returns settings
192
     *
193
     * @return string
194
     */
195
    public function getSettings()
196
    {
197
        return $this->settings;
198
    }
199
200
    /**
201
     * Sets settings
202
     *
203
     * @param string $settings
204
     */
205
    public function setSettings($settings)
206
    {
207
        $this->settings = $settings;
208
    }
209
210
    /**
211
     * Explodes the given string and returns an array of options for check and radio fields
212
     *
213
     * @return array
214
     */
215
    public function getSettingsForOption()
216
    {
217
        $options = [];
218
        $string = str_replace('[\n]', PHP_EOL, $this->settings);
219
        $settingsField = GeneralUtility::trimExplode(PHP_EOL, $string, true);
220
        foreach ($settingsField as $line) {
221
            $settings = GeneralUtility::trimExplode('|', $line, false);
222
            $value = (isset($settings[1]) ? $settings[1] : $settings[0]);
223
            $label = $settings[0];
224
            $options[] = [
225
                'label' => $label,
226
                'value' => $value,
227
                'selected' => $this->defaultValue === $value ? 1 : 0
228
            ];
229
        }
230
231
        return $options;
232
    }
233
234
    /**
235
     * Returns the event
236
     *
237
     * @return Event
238
     */
239
    public function getEvent()
240
    {
241
        return $this->event;
242
    }
243
244
    /**
245
     * Sets the event
246
     *
247
     * @param Event $event
248
     * @return void
249
     */
250
    public function setEvent($event)
251
    {
252
        $this->event = $event;
253
    }
254
255
    /**
256
     * Returns the field valueType
257
     *
258
     * @return int
259
     */
260
    public function getValueType()
261
    {
262
        $valueTypes = [
263
            FieldType::INPUT => FieldValueType::TYPE_TEXT,
264
            FieldType::CHECK => FieldValueType::TYPE_ARRAY,
265
            FieldType::RADIO => FieldValueType::TYPE_TEXT,
266
            FieldType::TEXTAREA => FieldValueType::TYPE_TEXT,
267
            FieldType::TEXT => FieldValueType::TYPE_TEXT,
268
            FieldType::DIVIDER => FieldValueType::TYPE_TEXT,
269
            FieldType::SELECT => FieldValueType::TYPE_ARRAY,
270
        ];
271
        if (isset($valueTypes[$this->type])) {
272
            return $valueTypes[$this->type];
273
        }
274
275
        return FieldValueType::TYPE_TEXT;
276
    }
277
278
    /**
279
     * Returns the name of the partial for the field
280
     *
281
     * @return string
282
     */
283
    public function getPartialName()
284
    {
285
        return ucfirst($this->type);
286
    }
287
288
    /**
289
     * Returns the text
290
     *
291
     * @return string
292
     */
293
    public function getText()
294
    {
295
        return $this->text;
296
    }
297
298
    /**
299
     * Sets the text
300
     *
301
     * @param string $text
302
     * @return void
303
     */
304
    public function setText($text)
305
    {
306
        $this->text = $text;
307
    }
308
309
    /**
310
     * Returns the datepickermode
311
     *
312
     * @return int
313
     */
314
    public function getDatepickermode()
315
    {
316
        return $this->datepickermode;
317
    }
318
319
    /**
320
     * Sets the datepickermode
321
     *
322
     * @param int $datepickermode
323
     * @return void
324
     */
325
    public function setDatepickermode($datepickermode)
326
    {
327
        $this->datepickermode = $datepickermode;
328
    }
329
330
    /**
331
     * Returns the datepickermode type as string
332
     *
333
     * @return string
334
     */
335
    public function getDatepickermodeType()
336
    {
337
        switch ($this->datepickermode) {
338
            case 1:
339
                return 'datetime-local';
340
            case 2:
341
                return 'time';
342
            default:
343
                return 'date';
344
        }
345
    }
346
}
347