CustomFieldChoice::getPosition()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Date: 21/08/15
4
 */
5
6
namespace Mailxpert\Model;
7
8
/**
9
 * Class CustomFieldChoice
10
 * @package Mailxpert\Model
11
 */
12
class CustomFieldChoice
13
{
14
    /**
15
     * @var string
16
     */
17
    private $id;
18
19
    /**
20
     * @var string
21
     */
22
    private $label;
23
24
    /**
25
     * @var string
26
     */
27
    private $alias;
28
29
    /**
30
     * @var int
31
     */
32
    private $position;
33
34
    /**
35
     * @var boolean
36
     */
37
    private $checked;
38
39
    /**
40
     * CustomFieldChoice constructor.
41
     *
42
     * @param string      $alias
43
     * @param string|null $id
44
     */
45
    public function __construct($alias, $id = null)
46
    {
47
        $this->alias = $alias;
48
        $this->id = $id;
49
    }
50
51
    /**
52
     * @return string
53
     */
54
    public function getId()
55
    {
56
        return $this->id;
57
    }
58
59
    /**
60
     * @param string $id
61
     */
62
    public function setId($id)
63
    {
64
        $this->id = $id;
65
    }
66
67
    /**
68
     * @return string
69
     */
70
    public function getLabel()
71
    {
72
        return $this->label;
73
    }
74
75
    /**
76
     * @param string $label
77
     */
78
    public function setLabel($label)
79
    {
80
        $this->label = $label;
81
    }
82
83
    /**
84
     * @return string
85
     */
86
    public function getAlias()
87
    {
88
        return $this->alias;
89
    }
90
91
    /**
92
     * @param string $alias
93
     */
94
    public function setAlias($alias)
95
    {
96
        $this->alias = $alias;
97
    }
98
99
    /**
100
     * @return int
101
     */
102
    public function getPosition()
103
    {
104
        return $this->position;
105
    }
106
107
    /**
108
     * @param int $position
109
     */
110
    public function setPosition($position)
111
    {
112
        $this->position = (int) $position;
113
    }
114
115
    /**
116
     * @return boolean
117
     */
118
    public function isChecked()
119
    {
120
        return $this->checked;
121
    }
122
123
    /**
124
     * @param boolean $checked
125
     */
126
    public function setChecked($checked)
127
    {
128
        if (!is_bool($checked)) {
129
            if ($checked === 0 || $checked == 'false') {
130
                $checked = false;
131
            } else {
132
                $checked = true;
133
            }
134
        }
135
136
        $this->checked = $checked;
137
    }
138
139
    /**
140
     * @return array
141
     */
142
    public function toAPI()
143
    {
144
        return [
145
            'label' => $this->getLabel(),
146
            'alias' => $this->getAlias(),
147
            'position' => $this->getPosition(),
148
            'checked' => ($this->isChecked()) ? 'true' : 'false',
149
        ];
150
    }
151
152
    /**
153
     * @param array $data
154
     */
155
    public function fromAPI($data)
156
    {
157
        foreach ($data as $field => $value) {
158
            switch ($field) {
159
                case 'label':
160
                    $this->setLabel($value);
161
                    break;
162
                case 'alias':
163
                    $this->setAlias($value);
164
                    break;
165
                case 'position':
166
                    $this->setPosition($value);
167
                    break;
168
                case 'checked':
169
                    $this->setChecked($value);
170
                    break;
171
            }
172
        }
173
    }
174
}
175