-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathkyUserGroup.php
139 lines (121 loc) · 3.25 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
<?php
require_once('kyObjectBase.php');
/**
* Part of PHP client to REST API of Kayako v4 (Kayako Fusion).
* Compatible with Kayako version >= 4.01.204.
*
* Kayako UserGroup object.
*
* @author Tomasz Sawicki (https://github.com/Furgas)
*/
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';
private $id = null;
private $title = null;
private $type = null;
private $is_master = null;
protected function parseData($data) {
$this->id = intval($data['id']);
$this->title = $data['title'];
$this->type = $data['grouptype'];
$this->is_master = intval($data['ismaster']) === 0 ? false : true;
}
protected function buildData($method) {
$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 = $title;
return $this;
}
/**
* Returns type of the user group - one of kyUserGroup::TYPE_* constants.
*
* @return string
* @filterBy()
* @orderBy()
*/
public function getType() {
return $this->type;
}
/**
* Sets type of the user group.
*
* @param string $type Type of the user group - one of kyUserGroup::TYPE_* constants
* @return kyUserGroup
*/
public function setType($type) {
$this->type = $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);
}
}