-
Notifications
You must be signed in to change notification settings - Fork 6
/
kyCustomField.php
112 lines (103 loc) · 2.47 KB
/
kyCustomField.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
/**
* Part of PHP client to REST API of Kayako v4 (Kayako Fusion).
* Compatible with Kayako version >= 4.01.240.
*
* Base class for custom fields.
*
* @author Tomasz Sawicki (https://github.com/Furgas)
*/
class kyCustomField {
const TYPE_TEXT = 1;
const TYPE_TEXTAREA = 2;
const TYPE_PASSWORD = 3;
const TYPE_CHECKBOX = 4;
const TYPE_RADIO = 5;
const TYPE_SELECT = 6;
const TYPE_MULTI_SELECT = 7;
const TYPE_CUSTOM = 8;
const TYPE_LINKED_SELECT = 9;
const TYPE_DATE = 10;
const TYPE_FILE = 11;
protected $id;
protected $type;
protected $title;
protected $value;
/**
* Default constructor.
*
* @param array $data Object data from XML response converted into array.
*/
function __construct($data = null) {
if ($data !== null)
$this->parseData($data);
}
/**
* Should use passed data to fill object properties.
*
* @param array $data Object data from XML response.
*/
protected function parseData($data) {
$this->id = intval($data['_attributes']['id']);
$this->type = intval($data['_attributes']['type']);
$this->title = $data['_attributes']['title'];
$this->value = $data['_contents'];
}
/**
* Creates proper class based on type of custom field.
*
* @param array $data Object data from XML response.
* @return kyCustomField
*/
static public function createByType($data) {
switch ($data['_attributes']['type']) {
case self::TYPE_TEXT:
case self::TYPE_TEXTAREA:
case self::TYPE_PASSWORD:
case self::TYPE_RADIO:
case self::TYPE_SELECT:
case self::TYPE_CUSTOM:
case self::TYPE_LINKED_SELECT:
return new kyCustomField($data);
case self::TYPE_CHECKBOX:
case self::TYPE_MULTI_SELECT:
return new kyCustomFieldMulti($data);
case self::TYPE_DATE:
return new kyCustomFieldDate($data);
case self::TYPE_FILE:
return new kyCustomFieldFile($data);
}
}
/**
* Returns custom field identifier.
*
* @return int
*/
public function getId() {
return $this->id;
}
/**
* Returns type of this custom field - one of kyCustomFieldBase::TYPE_ constants.
*
* @return int
*/
public function getType() {
return $this->type;
}
/**
* Returns title of this custom field.
*
* @return string
*/
public function getTitle() {
return $this->title;
}
/**
* Returns raw value of this custom field.
*
* @return string
*/
public function getValue() {
return $this->value;
}
}