Passed
Push — master ( f02d33...dc5694 )
by Ralf
19:35
created

DocumentFormField::getFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
namespace EWW\Dpf\Domain\Model;
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
class DocumentFormField extends AbstractFormElement
18
{
19
    protected $file;
20
21
    protected $value;
22
23
    protected $inputField;
24
25
    protected $selectOptions;
26
27
    protected $inputOptions;
28
29
    protected $fillOutService;
30
31
    protected $defaultInputOption;
32
33
    protected $hasDefaultValue = false;
34
35
    protected $validation;
36
37
    protected $depositLicense = null;
38
39
    /**
40
     * @var string
41
     */
42
    protected $dataType;
43
44
    /**
45
     * @var int
46
     */
47
    protected $gndFieldUid;
48
49
    /**
50
     * consent
51
     *
52
     * @var boolean
53
     */
54
    protected $consent;
55
56
    /**
57
     * @var int
58
     */
59
    protected $maxInputLength;
60
61
    /**
62
     * help text
63
     *
64
     * @var string
65
     */
66
    protected $helpText = '';
67
68
    /**
69
     * @var string
70
     */
71
    protected $objectType = '';
72
73
    public function getValue()
74
    {
75
        return $this->value;
76
    }
77
78
    public function setValue($value, $defaultValue = '')
79
    {
80
81
        $this->hasDefaultValue = !empty($defaultValue);
82
83
        if (empty($value)) {
84
            switch ($this->inputField) {
85
                case \EWW\Dpf\Domain\Model\MetadataObject::select:
86
                    if (!empty($defaultValue)) {
87
                        $this->value = $this->defaultInputOption;
88
                    } else {
89
                        $this->value = '';
90
                    }
91
                    break;
92
93
                case \EWW\Dpf\Domain\Model\MetadataObject::checkbox:
94
                    if (!empty($defaultValue)) {
95
                        $this->value = 'yes';
96
                    } else {
97
                        $this->value = '';
98
                    }
99
                    break;
100
101
                default:
102
                    $this->value = $defaultValue;
103
                    break;
104
            }
105
        } else {
106
            $this->value = $value;
107
        }
108
    }
109
110
    public function getInputField()
111
    {
112
        return $this->inputField;
113
    }
114
115
    public function setInputField($inputField)
116
    {
117
        $this->inputField = $inputField;
118
    }
119
120
    /**
121
     *
122
     * @return array
123
     */
124
    public function getInputOptions()
125
    {
126
        return $this->inputOptions;
127
    }
128
129
    /**
130
     *
131
     * @param \EWW\Dpf\Domain\Model\InputOptionList $inputOptionList
132
     */
133
    public function setInputOptions(\EWW\Dpf\Domain\Model\InputOptionList $inputOptionList = null)
134
    {
135
136
        $this->inputOptions = array();
137
138
        if ($inputOptionList) {
139
            $this->inputOptions[''] = '';
140
            foreach ($inputOptionList->getInputOptions() as $option => $label) {
141
                $this->inputOptions[$option] = $label;
142
            }
143
144
            $this->defaultInputOption = trim($inputOptionList->getDefaultValue());
145
        }
146
147
    }
148
149
    /**
150
     * Returns the fillOutService
151
     *
152
     * @return string $fillOutService
153
     */
154
    public function getFillOutService()
155
    {
156
        return $this->fillOutService;
157
    }
158
159
    /**
160
     * Sets the fillOutService
161
     *
162
     * @param string $fillOutService
163
     * @return void
164
     */
165
    public function setFillOutService($fillOutService)
166
    {
167
        $this->fillOutService = $fillOutService;
168
    }
169
170
    /**
171
     * Returns the consent
172
     *
173
     * @return boolean $consent
174
     */
175
    public function getConsent()
176
    {
177
        return $this->consent;
178
    }
179
180
    /**
181
     * Sets the consent
182
     *
183
     * @param boolean $consent
184
     * @return void
185
     */
186
    public function setConsent($consent)
187
    {
188
        $this->consent = boolval($consent);
189
    }
190
191
    public function getHasDefaultValue()
192
    {
193
        return $this->hasDefaultValue;
194
    }
195
196
    public function getValidation()
197
    {
198
        return $this->validation;
199
    }
200
201
    public function setValidation($validation)
202
    {
203
        $this->validation = $validation;
204
    }
205
206
    /**
207
     * Gets the data type of the field, e.g. DATE
208
     *
209
     * @return string
210
     */
211
    public function getDataType()
212
    {
213
        return $this->dataType;
214
    }
215
216
    /**
217
     * Sets the data type of the field, e.g. DATE
218
     *
219
     * @param string $dataType
220
     * @return void
221
     */
222
    public function setDataType($dataType)
223
    {
224
        $this->dataType = $dataType;
225
    }
226
227
    /**
228
     * Gets the uid of the field which is
229
     * linked with the gnd field
230
     *
231
     * @return int
232
     */
233
    public function getGndFieldUid() {
234
        return $this->gndFieldUid;
235
    }
236
237
    /**
238
     * Sets the uid of the field which is
239
     * linked with the gnd field
240
     *
241
     * @param int $fieldId
242
     * @return void
243
     */
244
    public function setGndFieldUid($fieldId) {
245
        $this->gndFieldUid = $fieldId;
246
    }
247
248
    /**
249
     * Gets the max length of characters for the input field.
250
     *
251
     * @return int
252
     */
253
    public function getMaxInputLength() {
254
        return $this->maxInputLength;
255
    }
256
257
    /**
258
     * Sets the max length of characters for the input field.
259
     *
260
     * @return int
261
     */
262
    public function setMaxInputLength($maxInputLength) {
263
        $this->maxInputLength = $maxInputLength;
264
    }
265
266
    /**
267
     * @return string
268
     */
269
    public function getObjectType(): string
270
    {
271
        return $this->objectType;
272
    }
273
274
    /**
275
     * @param string $objectType
276
     */
277
    public function setObjectType(string $objectType): void
278
    {
279
        $this->objectType = $objectType;
280
    }
281
282
    /**
283
     * @return mixed
284
     */
285
    public function getDepositLicense()
286
    {
287
        return $this->depositLicense;
288
    }
289
290
    /**
291
     * @param mixed $depositLicense
292
     */
293
    public function setDepositLicense($depositLicense): void
294
    {
295
        $this->depositLicense = $depositLicense;
296
    }
297
298
    /**
299
     * @return string
300
     */
301
    public function getHelpText(): string
302
    {
303
        return $this->helpText;
304
    }
305
306
    /**
307
     * @param string $helpText
308
     */
309
    public function setHelpText(string $helpText): void
310
    {
311
        $this->helpText = $helpText;
312
    }
313
314
    public function getHelpTextLong()
315
    {
316
        if ($this->helpText) {
317
            $domDocument = new \DOMDocument();
318
            $domDocument->loadXML("<html>".$this->helpText."</html>");
319
            $xpath = \EWW\Dpf\Helper\XPath::create($domDocument);
320
            $nodes = $xpath->query("//p");
321
            if ($nodes->length > 1) {
322
                $domDocument->firstChild->removeChild($nodes->item(0));
0 ignored issues
show
Bug introduced by
The method removeChild() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

322
                $domDocument->firstChild->/** @scrutinizer ignore-call */ 
323
                                          removeChild($nodes->item(0));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
323
                return str_replace(['<html>','</html>'], '', $domDocument->saveHTML());
324
            }
325
        }
326
    }
327
328
    public function getHelpTextShort()
329
    {
330
        if ($this->helpText) {
331
            $domDocument = new \DOMDocument();
332
            $domDocument->loadXML("<html>" . $this->helpText . "</html>");
333
            $xpath = \EWW\Dpf\Helper\XPath::create($domDocument);
334
            $nodes = $xpath->query("//p");
335
            if ($nodes->length > 0) {
336
                return $nodes->item(0)->nodeValue;
337
            }
338
        }
339
    }
340
341
    /**
342
     * @return mixed
343
     */
344
    public function getFile()
345
    {
346
        return $this->file;
347
    }
348
349
    /**
350
     * @param mixed $file
351
     */
352
    public function setFile($file): void
353
    {
354
        $this->file = $file;
355
    }
356
357
}
358