forked from Furgas/php-api-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kyCustomFieldGroupBase.php
138 lines (117 loc) · 2.85 KB
/
kyCustomFieldGroupBase.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
/**
* Base class for custom field group.
*
* @author Tomasz Sawicki (https://github.com/Furgas)
* @since Kayako version 4.40.1079
* @package Object\Base
*/
abstract class kyCustomFieldGroupBase extends kyObjectBase {
const TYPE_TICKET = 0;
const TYPE_USER = 1;
const TYPE_USER_ORGANIZATION = 2;
const TYPE_USER_LIVECHAT = 3;
const TYPE_USER_TIME_TRACK = 4;
static protected $object_xml_name = 'group';
protected $read_only = true;
/**
* Custom field group identifier.
* @apiField
* @var int
*/
protected $id;
/**
* Custom field group title.
* @apiField
* @var string
*/
protected $title;
/**
* Custom field group displayorder.
* @apiField
* @var int
*/
protected $displayorder;
/**
* List of custom fields in this group.
* @var kyCustomField[]
*/
protected $fields;
/**
* Type of custom field group.
* @see kyCustomFieldGroupBase::TYPE constants
* @var int
*/
protected $type;
protected function parseData($data) {
$this->id = intval($data['_attributes']['id']);
$this->title = $data['_attributes']['title'];
$this->displayorder = intval($data['_attributes']['displayorder']);
$this->fields = array();
if (array_key_exists('field', $data)) {
foreach ($data['field'] as $custom_field_data) {
$this->fields[] = kyCustomField::createByType($this, $custom_field_data);
}
}
}
public function buildData($create) {
$this->checkRequiredAPIFields($create);
$data = array();
foreach ($this->getFields() as $field) {
/* @var $field kyCustomField */
$data = array_merge_recursive($data, $field->buildData($create));
}
return $data;
}
static public function get($id) {
throw new BadMethodCallException(sprintf("You can't get single object of type %s.", get_called_class()));
}
public function refresh() {
throw new BadMethodCallException(sprintf("You can't refresh object of type %s.", get_called_class()));
}
public function toString() {
return sprintf("%s (%d fields)", $this->getTitle(), count($this->getFields()));
}
public function getId($complete = false) {
return $complete ? array($this->id) : $this->id;
}
/**
* Returns type of this custom fields group (one of kyCustomFieldGroupBase::TYPE_ constants).
*
* @return int
* @filterBy
* @orderBy
*/
public function getType() {
return $this->type;
}
/**
* Returns title of this custom fields group.
*
* @return string
* @filterBy
* @orderBy
*/
public function getTitle() {
return $this->title;
}
/**
* Returns displayorder of this custom fields group.
*
* @return int
* @filterBy
* @orderBy
*/
public function getDisplayOrder() {
return $this->displayorder;
}
/**
* Returns list of custom fields for this group.
*
* @return kyResultSet
*/
public function getFields() {
/** @noinspection PhpParamsInspection */
return new kyResultSet($this->fields, 'kyCustomField');
}
}