Completed
Push — development ( 9d105e...bf3399 )
by Torben
04:26
created

FieldValue::getValue()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 3
nc 2
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\Registration;
12
use DERHANSEN\SfEventMgt\Utility\ArrayUtility;
13
use DERHANSEN\SfEventMgt\Utility\FieldValueType;
14
15
/**
16
 * Answer
17
 *
18
 * @author Torben Hansen <[email protected]>
19
 */
20
class FieldValue extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
21
{
22
    /**
23
     * Value
24
     *
25
     * @var string
26
     */
27
    protected $value = '';
28
29
    /**
30
     * The type of the value
31
     *
32
     * @var int
33
     */
34
    protected $valueType = FieldValueType::TYPE_TEXT;
35
36
    /**
37
     * Field
38
     *
39
     * @var \DERHANSEN\SfEventMgt\Domain\Model\Registration\Field
40
     */
41
    protected $field = null;
42
43
    /**
44
     * Registration
45
     *
46
     * @var Registration
47
     */
48
    protected $registration = null;
49
50
    /**
51
     * Returns value depending on the valueType
52
     *
53
     * @return string|array
54
     */
55
    public function getValue()
56
    {
57
        $value = $this->value;
58
        if ($this->getField()->getValueType() === FieldValueType::TYPE_ARRAY && ArrayUtility::isJsonArray($value)) {
59
            $value = json_decode($value, true);
60
        }
61
62
        return $value;
63
    }
64
65
    public function getValueForCsvExport()
66
    {
67
        $value = $this->value;
68
        if ($this->getField()->getValueType() === FieldValueType::TYPE_ARRAY && ArrayUtility::isJsonArray($value)) {
69
            $value = implode(',', json_decode($value, true));
70
        }
71
72
        return $value;
73
    }
74
75
    /**
76
     * Sets value
77
     *
78
     * @param string $value
79
     * @return void
80
     */
81
    public function setValue($value)
82
    {
83
        $this->value = $value;
84
    }
85
86
    /**
87
     * Returns field
88
     *
89
     * @return \DERHANSEN\SfEventMgt\Domain\Model\Registration\Field
90
     */
91
    public function getField()
92
    {
93
        return $this->field;
94
    }
95
96
    /**
97
     * Sets field
98
     *
99
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration\Field $field
100
     * @return void
101
     */
102
    public function setField($field)
103
    {
104
        $this->field = $field;
105
    }
106
107
    /**
108
     * Returns registration
109
     *
110
     * @return Registration
111
     */
112
    public function getRegistration()
113
    {
114
        return $this->registration;
115
    }
116
117
    /**
118
     * Sets registration
119
     *
120
     * @param Registration $registration
121
     * @return void
122
     */
123
    public function setRegistration($registration)
124
    {
125
        $this->registration = $registration;
126
    }
127
128
    /**
129
     * Sets value type
130
     *
131
     * @return int
132
     */
133
    public function getValueType()
134
    {
135
        return $this->valueType;
136
    }
137
138
    /**
139
     * Returns value type
140
     *
141
     * @param int $valueType
142
     */
143
    public function setValueType($valueType)
144
    {
145
        $this->valueType = $valueType;
146
    }
147
}
148