1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LPTracker\models; |
4
|
|
|
|
5
|
|
|
use LPTracker\exceptions\LPTrackerSDKException; |
6
|
|
|
|
7
|
|
|
class CustomField extends Model |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @var int |
11
|
|
|
*/ |
12
|
|
|
protected $id; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @var int |
16
|
|
|
*/ |
17
|
|
|
protected $projectId; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
protected $name; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
protected $type; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var bool |
31
|
|
|
*/ |
32
|
|
|
protected $showInLeads; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var bool |
36
|
|
|
*/ |
37
|
|
|
protected $showInDeals; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var bool |
41
|
|
|
*/ |
42
|
|
|
protected $isMultiSelect; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var bool |
46
|
|
|
*/ |
47
|
|
|
protected $isRequired; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var string |
51
|
|
|
*/ |
52
|
|
|
protected $description; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var bool |
56
|
|
|
*/ |
57
|
|
|
protected $isMultiLine; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @var Category[] |
61
|
|
|
*/ |
62
|
|
|
protected $categories = []; |
63
|
|
|
|
64
|
|
|
public function __construct(array $data = []) |
65
|
|
|
{ |
66
|
|
|
if (isset($data['id'])) { |
67
|
|
|
$this->id = $data['id']; |
68
|
|
|
} |
69
|
|
|
if (isset($data['project_id'])) { |
70
|
|
|
$this->projectId = $data['project_id']; |
71
|
|
|
} |
72
|
|
|
if (isset($data['name'])) { |
73
|
|
|
$this->name = $data['name']; |
74
|
|
|
} |
75
|
|
|
if (isset($data['type'])) { |
76
|
|
|
$this->type = $data['type']; |
77
|
|
|
} |
78
|
|
|
if (isset($data['show_in_leads'])) { |
79
|
|
|
$this->showInLeads = (bool) $data['show_in_leads']; |
80
|
|
|
} |
81
|
|
|
if (isset($data['show_in_deals'])) { |
82
|
|
|
$this->showInDeals = (bool) $data['show_in_deals']; |
83
|
|
|
} |
84
|
|
|
if (isset($data['is_multi_select'])) { |
85
|
|
|
$this->isMultiSelect = (bool) $data['is_multi_select']; |
86
|
|
|
} |
87
|
|
|
if (isset($data['is_required'])) { |
88
|
|
|
$this->isRequired = (bool) $data['is_required']; |
89
|
|
|
} |
90
|
|
|
if (isset($data['description'])) { |
91
|
|
|
$this->description = $data['description']; |
92
|
|
|
} |
93
|
|
|
if (isset($data['is_multi_line'])) { |
94
|
|
|
$this->isMultiLine = (bool) $data['is_multi_line']; |
95
|
|
|
} |
96
|
|
|
if (!empty($data['categories']) && is_array($data['categories'])) { |
97
|
|
|
foreach ($data['categories'] as $categoryData) { |
98
|
|
|
$categoryModel = new Category($categoryData); |
99
|
|
|
$this->addCategory($categoryModel); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @return array |
106
|
|
|
*/ |
107
|
|
|
public function toArray() |
108
|
|
|
{ |
109
|
|
|
$result = [ |
110
|
|
|
'id' => $this->id, |
111
|
|
|
'project_id' => $this->projectId, |
112
|
|
|
'name' => $this->name, |
113
|
|
|
'type' => $this->type, |
114
|
|
|
'show_in_leads' => $this->showInLeads, |
115
|
|
|
'show_in_deals' => $this->showInDeals, |
116
|
|
|
'is_multi_select' => $this->isMultiSelect, |
117
|
|
|
'is_required' => $this->isRequired, |
118
|
|
|
'description' => $this->description, |
119
|
|
|
'is_multi_line' => $this->isMultiLine, |
120
|
|
|
]; |
121
|
|
|
foreach ($this->getCategories() as $category) { |
122
|
|
|
$result['categories'][] = $category->toArray(); |
123
|
|
|
} |
124
|
|
|
return $result; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @return bool |
129
|
|
|
* @throws LPTrackerSDKException |
130
|
|
|
*/ |
131
|
|
|
public function validate() |
132
|
|
|
{ |
133
|
|
|
if (empty($this->id)) { |
134
|
|
|
throw new LPTrackerSDKException('Id is required'); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
return true; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @return int |
142
|
|
|
*/ |
143
|
|
|
public function getId() |
144
|
|
|
{ |
145
|
|
|
return $this->id; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @param int $id |
150
|
|
|
* @return CustomField |
151
|
|
|
*/ |
152
|
|
|
public function setId($id) |
153
|
|
|
{ |
154
|
|
|
$this->id = $id; |
155
|
|
|
return $this; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @return int |
160
|
|
|
*/ |
161
|
|
|
public function getProjectId() |
162
|
|
|
{ |
163
|
|
|
return $this->projectId; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @param int $projectId |
168
|
|
|
* @return CustomField |
169
|
|
|
*/ |
170
|
|
|
public function setProjectId($projectId) |
171
|
|
|
{ |
172
|
|
|
$this->projectId = $projectId; |
173
|
|
|
return $this; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @return string |
178
|
|
|
*/ |
179
|
|
|
public function getName() |
180
|
|
|
{ |
181
|
|
|
return $this->name; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @param string $name |
186
|
|
|
* @return CustomField |
187
|
|
|
*/ |
188
|
|
|
public function setName($name) |
189
|
|
|
{ |
190
|
|
|
$this->name = $name; |
191
|
|
|
return $this; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* @return string |
196
|
|
|
*/ |
197
|
|
|
public function getType() |
198
|
|
|
{ |
199
|
|
|
return $this->type; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* @param string $type |
204
|
|
|
* @return CustomField |
205
|
|
|
*/ |
206
|
|
|
public function setType($type) |
207
|
|
|
{ |
208
|
|
|
$this->type = $type; |
209
|
|
|
return $this; |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* @return bool |
214
|
|
|
*/ |
215
|
|
|
public function isShowInLeads() |
216
|
|
|
{ |
217
|
|
|
return $this->showInLeads; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* @param bool $showInLeads |
222
|
|
|
* @return CustomField |
223
|
|
|
*/ |
224
|
|
|
public function setShowInLeads($showInLeads) |
225
|
|
|
{ |
226
|
|
|
$this->showInLeads = (bool) $showInLeads; |
227
|
|
|
return $this; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* @return bool |
232
|
|
|
*/ |
233
|
|
|
public function isShowInDeals() |
234
|
|
|
{ |
235
|
|
|
return $this->showInDeals; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @param bool $showInDeals |
240
|
|
|
* @return CustomField |
241
|
|
|
*/ |
242
|
|
|
public function setShowInDeals($showInDeals) |
243
|
|
|
{ |
244
|
|
|
$this->showInDeals = (bool) $showInDeals; |
245
|
|
|
return $this; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* @return bool |
250
|
|
|
*/ |
251
|
|
|
public function isMultiSelect() |
252
|
|
|
{ |
253
|
|
|
return $this->isMultiSelect; |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
/** |
257
|
|
|
* @param bool $isMultiSelect |
258
|
|
|
* @return CustomField |
259
|
|
|
*/ |
260
|
|
|
public function setIsMultiSelect($isMultiSelect) |
261
|
|
|
{ |
262
|
|
|
$this->isMultiSelect = (bool) $isMultiSelect; |
263
|
|
|
return $this; |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* @return bool |
268
|
|
|
*/ |
269
|
|
|
public function isRequired() |
270
|
|
|
{ |
271
|
|
|
return $this->isRequired; |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* @param bool $isRequired |
276
|
|
|
* @return CustomField |
277
|
|
|
*/ |
278
|
|
|
public function setIsRequired($isRequired) |
279
|
|
|
{ |
280
|
|
|
$this->isRequired = (bool) $isRequired; |
281
|
|
|
return $this; |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* @return string |
286
|
|
|
*/ |
287
|
|
|
public function getDescription() |
288
|
|
|
{ |
289
|
|
|
return $this->description; |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
/** |
293
|
|
|
* @param string $description |
294
|
|
|
* @return CustomField |
295
|
|
|
*/ |
296
|
|
|
public function setDescription($description) |
297
|
|
|
{ |
298
|
|
|
$this->description = $description; |
299
|
|
|
return $this; |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
/** |
303
|
|
|
* @return bool |
304
|
|
|
*/ |
305
|
|
|
public function isMultiLine() |
306
|
|
|
{ |
307
|
|
|
return $this->isMultiLine; |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
/** |
311
|
|
|
* @param bool $isMultiLine |
312
|
|
|
* @return CustomField |
313
|
|
|
*/ |
314
|
|
|
public function setIsMultiLine($isMultiLine) |
315
|
|
|
{ |
316
|
|
|
$this->isMultiLine = (bool) $isMultiLine; |
317
|
|
|
return $this; |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
/** |
321
|
|
|
* @return Category[] |
322
|
|
|
*/ |
323
|
|
|
public function getCategories() |
324
|
|
|
{ |
325
|
|
|
return $this->categories; |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
/** |
329
|
|
|
* @param Category[] $categories |
330
|
|
|
* @return $this |
331
|
|
|
*/ |
332
|
|
|
public function setCategories(array $categories) |
333
|
|
|
{ |
334
|
|
|
$this->categories = $categories; |
335
|
|
|
return $this; |
336
|
|
|
} |
337
|
|
|
|
338
|
|
|
/** |
339
|
|
|
* @param Category $category |
340
|
|
|
* @return $this |
341
|
|
|
*/ |
342
|
|
|
public function addCategory(Category $category) |
343
|
|
|
{ |
344
|
|
|
$this->categories[] = $category; |
345
|
|
|
return $this; |
346
|
|
|
} |
347
|
|
|
} |
348
|
|
|
|