forked from Furgas/php-api-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kyCustomFieldSelect.php
83 lines (72 loc) · 1.76 KB
/
kyCustomFieldSelect.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/**
* Class for select custom field with single option.
*
* @author Tomasz Sawicki (https://github.com/Furgas)
* @since Kayako version 4.40.1079
* @package Object\CustomField
*
* @noinspection PhpDocSignatureInspection
*/
class kyCustomFieldSelect extends kyCustomField {
/**
* Selected option.
* @var kyCustomFieldOption
*/
protected $option;
protected function parseData($data) {
parent::parseData($data);
$this->option = $this->getOption($data['_contents']);
}
public function buildData($create) {
$this->checkRequiredAPIFields($create);
$data = array();
if ($this->option !== null) {
$data[$this->name] = $this->option->getId();
}
return $data;
}
/**
* Sets the field selected option.
*
* @param kyCustomFieldOption $option Field option.
* @return kyCustomFieldSelect
*/
public function setSelectedOption($option) {
$this->option = ky_assure_object($option, 'kyCustomFieldOption');
$this->raw_value = $this->option !== null ? $this->option->getValue() : null;
return $this;
}
/**
* Returns selected option for this field.
*
* @return kyCustomFieldOption
*/
public function getSelectedOption() {
return $this->option;
}
/**
* Returns selected field option.
*
* @see kyCustomField::getValue()
* @see kyCustomFieldSelect::getSelectedOption()
*
* @return kyCustomFieldOption
*/
public function getValue() {
return $this->option;
}
/**
* Sets the option for this field.
*
* @see kyCustomField::setValue()
* @see kyCustomField::setSelectedOption()
*
* @param mixed $value Identifier of field option OR value of field option OR an option.
* @return kyCustomFieldSelect
*/
public function setValue($value) {
$this->setSelectedOption($this->getOption($value));
return $this;
}
}