forked from Furgas/php-api-library
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkyUserGroup.php
executable file
·171 lines (150 loc) · 3.56 KB
/
kyUserGroup.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
/**
* Kayako UserGroup object.
*
* @author Tomasz Sawicki (https://github.com/Furgas)
* @link http://wiki.kayako.com/display/DEV/REST+-+UserGroup
* @since Kayako version 4.01.204
* @package Object\User
*
* @noinspection PhpDocSignatureInspection
*/
class kyUserGroup extends kyObjectBase {
/**
* Type of user group - guest.
* @var int
*/
const TYPE_GUEST = 'guest';
/**
* Type of user group - registered.
* @var int
*/
const TYPE_REGISTERED = 'registered';
static protected $controller = '/Base/UserGroup';
static protected $object_xml_name = 'usergroup';
/**
* User group identifier.
* @apiField
* @var int
*/
protected $id;
/**
* User group title.
* @apiField required=true
* @var string
*/
protected $title;
/**
* User group type.
*
* @see kyUserGroup::TYPE constants.
*
* @apiField required_create=true alias=grouptype
* @var string
*/
protected $type;
/**
* Whether this user group is master group (built-in).
* @apiField
* @var bool
*/
protected $is_master;
protected function parseData($data) {
$this->id = intval($data['id']);
$this->title = $data['title'];
$this->type = $data['grouptype'];
$this->is_master = ky_assure_bool($data['ismaster']);
}
public function buildData($create) {
$this->checkRequiredAPIFields($create);
$data = array();
$data['title'] = $this->title;
$data['grouptype'] = $this->type;
return $data;
}
public function toString() {
return sprintf("%s (type: %s)", $this->getTitle(), $this->getType());
}
public function getId($complete = false) {
return $complete ? array($this->id) : $this->id;
}
/**
* Returns title of the user group.
*
* @return string
* @filterBy
* @orderBy
*/
public function getTitle() {
return $this->title;
}
/**
* Sets title of the user group.
*
* @param string $title Title of the user group.
* @return kyUserGroup
*/
public function setTitle($title) {
$this->title = ky_assure_string($title);
return $this;
}
/**
* Returns type of the user group.
*
* @see kyUserGroup::TYPE constants.
*
* @return string
* @filterBy
* @orderBy
*/
public function getType() {
return $this->type;
}
/**
* Sets type of the user group.
*
* @see kyUserGroup::TYPE constants.
*
* @param string $type Type of the user group.
* @return kyUserGroup
*/
public function setType($type) {
$this->type = ky_assure_constant($type, $this, 'TYPE');
return $this;
}
/**
* Returns whether the user group is master group (built-in).
*
* @return bool
* @filterBy
*/
public function getIsMaster() {
return $this->is_master;
}
/**
* Creates new user group.
* WARNING: Data is not sent to Kayako unless you explicitly call create() on this method's result.
*
* @param string $title Title of new user group.
* @param string $type Type of new user group - one of kyUserGroup::TYPE_* constants.
* @return kyUserGroup
*/
static public function createNew($title, $type = self::TYPE_REGISTERED) {
$new_user_group = new kyUserGroup();
$new_user_group->setTitle($title);
$new_user_group->setType($type);
return $new_user_group;
}
/**
* Creates new user in this user group.
* WARNING: Data is not sent to Kayako unless you explicitly call create() on this method's result.
*
* @param string $full_name Full name of new user.
* @param string $email E-mail address of new user.
* @param string $password Password of new user.
* @return kyUser
*/
public function newUser($full_name, $email, $password) {
return kyUser::createNew($full_name, $email, $this, $password);
}
}