Skip to content

Commit acc3045

Browse files
author
Timo Laine
committed
Functionality for creating groups, listing them and listing their members.
1 parent 1e0106b commit acc3045

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

lib/DiscourseAPI.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,67 @@ private function _putpostRequest($reqString, $paramArray, $apiUser = 'system', $
9191
return $resObj;
9292
}
9393

94+
/**
95+
* group
96+
*
97+
* @param string $groupname name of group
98+
* @param string $usernames users to add to group
99+
*
100+
* @return mixed HTTP return code and API return object
101+
*/
102+
103+
function group($groupname, $usernames = array())
104+
{
105+
$obj = $this->_getRequest("/admin/groups.json");
106+
if ($obj->http_code != 200) {
107+
return false;
108+
}
109+
110+
foreach($obj->apiresult as $group) {
111+
if($group->name === $groupname) {
112+
$groupId = $group->id;
113+
break;
114+
}
115+
$groupId = false;
116+
}
117+
118+
$params = array(
119+
'group' => array(
120+
'name' => $groupname,
121+
'usernames' => implode(',', $usernames)
122+
)
123+
);
124+
125+
if($groupId) {
126+
return $this->_putRequest('/admin/groups/' . $groupId, $params);
127+
} else {
128+
return $this->_postRequest('/admin/groups', $params);
129+
}
130+
}
131+
132+
/**
133+
* getGroups
134+
*
135+
* @return mixed HTTP return code and API return object
136+
*/
137+
138+
function getGroups()
139+
{
140+
return $this->_getRequest("/admin/groups.json");
141+
}
142+
143+
/**
144+
* getGroupMembers
145+
*
146+
* @param string $group name of group
147+
* @return mixed HTTP return code and API return object
148+
*/
149+
150+
function getGroupMembers($group)
151+
{
152+
return $this->_getRequest("/groups/{$group}/members.json");
153+
}
154+
94155
/**
95156
* createUser
96157
*

0 commit comments

Comments
 (0)