Passed
Push — master ( 211177...134b43 )
by Ralf
10:54
created

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

321
                $domDocument->firstChild->/** @scrutinizer ignore-call */ 
322
                                          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...
322
                return str_replace(['<html>','</html>'], '', $domDocument->saveHTML());
323
            }
324
        }
325
    }
326
327
    public function getHelpTextShort()
328
    {
329
        if ($this->helpText) {
330
            $domDocument = new \DOMDocument();
331
            $domDocument->loadXML("<html>".$this->helpText."</html>");
332
            $xpath = \EWW\Dpf\Helper\XPath::create($domDocument);
333
            $nodes = $xpath->query("//p");
334
            if ($nodes->length > 0) {
335
                return $nodes->item(0)->nodeValue;
336
            }
337
        }
338
    }
339
340
}
341