Completed
Push — registration_fields ( ba51da )
by Torben
10:23
created

Field   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 237
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 0
Metric Value
wmc 20
lcom 2
cbo 2
dl 0
loc 237
rs 10
c 0
b 0
f 0

16 Methods

Rating   Name   Duplication   Size   Complexity  
A getTitle() 0 4 1
A setTitle() 0 4 1
A getType() 0 4 1
A setType() 0 4 1
A getRequired() 0 4 1
A setRequired() 0 4 1
A getPlaceholder() 0 4 1
A setPlaceholder() 0 4 1
A getDefaultValue() 0 4 1
A setDefaultValue() 0 4 1
A getSettings() 0 4 1
A setSettings() 0 4 1
A getSettingsForOption() 0 17 4
A getEvent() 0 4 1
A setEvent() 0 4 1
A getValueType() 0 13 2
1
<?php
2
namespace DERHANSEN\SfEventMgt\Domain\Model\Registration;
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
17
use DERHANSEN\SfEventMgt\Domain\Model\Event;
18
use DERHANSEN\SfEventMgt\Utility\FieldType;
19
use DERHANSEN\SfEventMgt\Utility\FieldValueType;
20
use TYPO3\CMS\Core\Utility\GeneralUtility;
21
22
/**
23
 * Field
24
 *
25
 * @author Torben Hansen <[email protected]>
26
 */
27
class Field extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
28
{
29
    /**
30
     * The title
31
     *
32
     * @var string
33
     */
34
    protected $title = '';
35
36
    /**
37
     * Type - possible values
38
     *
39
     *  "input", "radio", "check"
40
     *
41
     * @var string
42
     */
43
    protected $type = '';
44
45
    /**
46
     * Field is required
47
     *
48
     * @var bool
49
     */
50
    protected $required = false;
51
52
    /**
53
     * Placeholder
54
     *
55
     * @var string
56
     */
57
    protected $placeholder = '';
58
59
    /**
60
     * Default value
61
     *
62
     * @var string
63
     */
64
    protected $defaultValue = '';
65
66
    /**
67
     * Settings
68
     *
69
     * @var string
70
     */
71
    protected $settings = '';
72
73
    /**
74
     * @var \DERHANSEN\SfEventMgt\Domain\Model\Event
75
     */
76
    protected $event = null;
77
78
    /**
79
     * Returns the title
80
     *
81
     * @return string
82
     */
83
    public function getTitle()
84
    {
85
        return $this->title;
86
    }
87
88
    /**
89
     * Sets the title
90
     *
91
     * @param string $title
92
     * @return void
93
     */
94
    public function setTitle($title)
95
    {
96
        $this->title = $title;
97
    }
98
99
    /**
100
     * Returns the type
101
     *
102
     * @return string
103
     */
104
    public function getType()
105
    {
106
        return $this->type;
107
    }
108
109
    /**
110
     * Sets the type
111
     *
112
     * @param string $type
113
     * @return void
114
     */
115
    public function setType($type)
116
    {
117
        $this->type = $type;
118
    }
119
120
    /**
121
     * Returns the required flag
122
     *
123
     * @return bool
124
     */
125
    public function getRequired()
126
    {
127
        return $this->required;
128
    }
129
130
    /**
131
     * Sets the required flag
132
     *
133
     * @param bool $required
134
     */
135
    public function setRequired($required)
136
    {
137
        $this->required = $required;
138
    }
139
140
    /**
141
     * Returns placeholder
142
     *
143
     * @return string
144
     */
145
    public function getPlaceholder()
146
    {
147
        return $this->placeholder;
148
    }
149
150
    /**
151
     * Sets placeholder
152
     *
153
     * @param string $placeholder
154
     * @return void
155
     */
156
    public function setPlaceholder($placeholder)
157
    {
158
        $this->placeholder = $placeholder;
159
    }
160
161
    /**
162
     * Returns default value
163
     *
164
     * @return string
165
     */
166
    public function getDefaultValue()
167
    {
168
        return $this->defaultValue;
169
    }
170
171
    /**
172
     * Sets default value
173
     *
174
     * @param string $defaultValue
175
     */
176
    public function setDefaultValue($defaultValue)
177
    {
178
        $this->defaultValue = $defaultValue;
179
    }
180
181
    /**
182
     * Returns settings
183
     *
184
     * @return string
185
     */
186
    public function getSettings()
187
    {
188
        return $this->settings;
189
    }
190
191
    /**
192
     * Sets settings
193
     *
194
     * @param string $settings
195
     */
196
    public function setSettings($settings)
197
    {
198
        $this->settings = $settings;
199
    }
200
201
    /**
202
     * Explodes the given string and returns an array of options for check and radio fields
203
     *
204
     * @return array
205
     */
206
    public function getSettingsForOption()
207
    {
208
        $options = [];
209
        $string = str_replace('[\n]', PHP_EOL, $this->settings);
210
        $settingsField = GeneralUtility::trimExplode(PHP_EOL, $string, true);
211
        foreach ($settingsField as $line) {
212
            $settings = GeneralUtility::trimExplode('|', $line, false);
213
            $value = (isset($settings[1]) ? $settings[1] : $settings[0]);
214
            $label = $settings[0];
215
            $options[] = [
216
                'label' => $label,
217
                'value' => $value,
218
                'selected' => $this->defaultValue === $value ? 1 : 0
219
            ];
220
        }
221
        return $options;
222
    }
223
224
    /**
225
     * Returns the event
226
     *
227
     * @return Event
228
     */
229
    public function getEvent()
230
    {
231
        return $this->event;
232
    }
233
234
    /**
235
     * Sets the event
236
     *
237
     * @param Event $event
238
     * @return void
239
     */
240
    public function setEvent($event)
241
    {
242
        $this->event = $event;
243
    }
244
245
    /**
246
     * Returns the field valueType
247
     *
248
     * @return int
249
     */
250
    public function getValueType()
251
    {
252
        $valueTypes = [
253
            FieldType::INPUT => FieldValueType::TYPE_TEXT,
254
            FieldType::CHECK => FieldValueType::TYPE_ARRAY,
255
            FieldType::RADIO => FieldValueType::TYPE_TEXT
256
        ];
257
        if (isset($valueTypes[$this->type])) {
258
            return $valueTypes[$this->type];
259
        } else {
260
            return FieldValueType::TYPE_TEXT;
261
        }
262
    }
263
}
264