Completed
Push — master ( 613ee8...b4d6e2 )
by Torben
03:56 queued 02:19
created

Field::getPartialName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
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
     * Returns the title
74
     *
75
     * @return string
76
     */
77
    public function getTitle()
78
    {
79
        return $this->title;
80
    }
81
82
    /**
83
     * Sets the title
84
     *
85
     * @param string $title
86
     * @return void
87
     */
88
    public function setTitle($title)
89
    {
90
        $this->title = $title;
91
    }
92
93
    /**
94
     * Returns the type
95
     *
96
     * @return string
97
     */
98
    public function getType()
99
    {
100
        return $this->type;
101
    }
102
103
    /**
104
     * Sets the type
105
     *
106
     * @param string $type
107
     * @return void
108
     */
109
    public function setType($type)
110
    {
111
        $this->type = $type;
112
    }
113
114
    /**
115
     * Returns the required flag
116
     *
117
     * @return bool
118
     */
119
    public function getRequired()
120
    {
121
        return $this->required;
122
    }
123
124
    /**
125
     * Sets the required flag
126
     *
127
     * @param bool $required
128
     */
129
    public function setRequired($required)
130
    {
131
        $this->required = $required;
132
    }
133
134
    /**
135
     * Returns placeholder
136
     *
137
     * @return string
138
     */
139
    public function getPlaceholder()
140
    {
141
        return $this->placeholder;
142
    }
143
144
    /**
145
     * Sets placeholder
146
     *
147
     * @param string $placeholder
148
     * @return void
149
     */
150
    public function setPlaceholder($placeholder)
151
    {
152
        $this->placeholder = $placeholder;
153
    }
154
155
    /**
156
     * Returns default value
157
     *
158
     * @return string
159
     */
160
    public function getDefaultValue()
161
    {
162
        return $this->defaultValue;
163
    }
164
165
    /**
166
     * Sets default value
167
     *
168
     * @param string $defaultValue
169
     */
170
    public function setDefaultValue($defaultValue)
171
    {
172
        $this->defaultValue = $defaultValue;
173
    }
174
175
    /**
176
     * Returns settings
177
     *
178
     * @return string
179
     */
180
    public function getSettings()
181
    {
182
        return $this->settings;
183
    }
184
185
    /**
186
     * Sets settings
187
     *
188
     * @param string $settings
189
     */
190
    public function setSettings($settings)
191
    {
192
        $this->settings = $settings;
193
    }
194
195
    /**
196
     * Explodes the given string and returns an array of options for check and radio fields
197
     *
198
     * @return array
199
     */
200
    public function getSettingsForOption()
201
    {
202
        $options = [];
203
        $string = str_replace('[\n]', PHP_EOL, $this->settings);
204
        $settingsField = GeneralUtility::trimExplode(PHP_EOL, $string, true);
205
        foreach ($settingsField as $line) {
206
            $settings = GeneralUtility::trimExplode('|', $line, false);
207
            $value = (isset($settings[1]) ? $settings[1] : $settings[0]);
208
            $label = $settings[0];
209
            $options[] = [
210
                'label' => $label,
211
                'value' => $value,
212
                'selected' => $this->defaultValue === $value ? 1 : 0
213
            ];
214
        }
215
216
        return $options;
217
    }
218
219
    /**
220
     * Returns the event
221
     *
222
     * @return Event
223
     */
224
    public function getEvent()
225
    {
226
        return $this->event;
227
    }
228
229
    /**
230
     * Sets the event
231
     *
232
     * @param Event $event
233
     * @return void
234
     */
235
    public function setEvent($event)
236
    {
237
        $this->event = $event;
238
    }
239
240
    /**
241
     * Returns the field valueType
242
     *
243
     * @return int
244
     */
245
    public function getValueType()
246
    {
247
        $valueTypes = [
248
            FieldType::INPUT => FieldValueType::TYPE_TEXT,
249
            FieldType::CHECK => FieldValueType::TYPE_ARRAY,
250
            FieldType::RADIO => FieldValueType::TYPE_TEXT,
251
            FieldType::TEXTAREA => FieldValueType::TYPE_TEXT
252
        ];
253
        if (isset($valueTypes[$this->type])) {
254
            return $valueTypes[$this->type];
255
        }
256
257
        return FieldValueType::TYPE_TEXT;
258
    }
259
260
    /**
261
     * Returns the name of the partial for the field
262
     *
263
     * @return string
264
     */
265
    public function getPartialName()
266
    {
267
        return ucfirst($this->type);
268
    }
269
}
270