33 public static $SCOPE =
'https://purl.imsglobal.org/spec/lti-gs/scope/contextgroup.readonly';
47 private $context =
null;
54 private $groupsEndpoint =
null;
61 private $groupSetsEndpoint =
null;
90 public function __construct($context, $groupsEndpoint, $groupSetsEndpoint =
null, $limit =
null, $pagingMode =
false)
92 $platform = $context->getPlatform();
93 parent::__construct($platform, $groupsEndpoint);
96 $this->context = $context;
97 $this->groupsEndpoint = $groupsEndpoint;
98 $this->groupSetsEndpoint = $groupSetsEndpoint;
99 $this->limit = $limit;
100 $this->pagingMode = $pagingMode;
112 public function get($allowNonSets =
false, $user =
null, $limit =
null)
116 $ok = $this->
getGroups($allowNonSets, $user, $limit);
119 $this->context->groupSets =
null;
120 $this->context->groups =
null;
135 $this->endpoint = $this->groupSetsEndpoint;
136 $ok = !empty($this->endpoint);
139 $parameters = array();
140 if (is_null($limit)) {
141 $limit = $this->limit;
143 if (is_null($limit)) {
146 if (!empty($limit)) {
147 $parameters[
'limit'] = strval($limit);
149 $this->context->groupSets = array();
150 $groupSets = array();
153 $http = $this->
send(
'GET', $parameters);
154 $ok = !empty($http) && $http->ok;
157 if (isset($http->responseJson->sets)) {
158 foreach ($http->responseJson->sets as $set) {
159 $groupSets[$set->id] = array(
'title' => $set->name,
'groups' => array(),
160 'num_members' => 0,
'num_staff' => 0,
'num_learners' => 0);
163 if (!$this->pagingMode && $http->hasRelativeLink(
'next')) {
164 $url = $http->getRelativeLink(
'next');
165 $this->endpoint = $url;
166 $parameters = array();
172 $this->context->groupSets = $groupSets;
188 public function getGroups($allowNonSets =
false, $user =
null, $limit =
null)
190 $this->endpoint = $this->groupsEndpoint;
191 $ok = !empty($this->endpoint);
194 $parameters = array();
196 if (!empty($user) && !empty($user->ltiUserId)) {
197 $ltiUserId = $user->ltiUserId;
199 if (!empty($ltiUserId)) {
200 $parameters[
'user_id'] = $ltiUserId;
202 if (is_null($limit)) {
203 $limit = $this->limit;
205 if (is_null($limit)) {
208 if (!empty($limit)) {
209 $parameters[
'limit'] = strval($limit);
211 if (is_null($this->context->groupSets)) {
212 $groupSets = array();
214 $groupSets = $this->context->groupSets;
219 $http = $this->
send(
'GET', $parameters);
220 $ok = !empty($http) && $http->ok;
223 if (isset($http->responseJson->groups)) {
224 foreach ($http->responseJson->groups as $agroup) {
225 if (!$allowNonSets && empty($agroup->set_id)) {
228 $group = array(
'title' => $agroup->name);
229 if (!empty($agroup->set_id)) {
230 if (!array_key_exists($agroup->set_id, $groupSets)) {
231 $groupSets[$agroup->set_id] = array(
'title' =>
"Set {$agroup->set_id}",
'groups' => array(),
232 'num_members' => 0,
'num_staff' => 0,
'num_learners' => 0);
234 $groupSets[$agroup->set_id][
'groups'][] = $agroup->id;
235 $group[
'set'] = $agroup->set_id;
237 if (!empty($agroup->tag)) {
238 $group[
'tag'] = $agroup->tag;
240 $groups[$agroup->id] = $group;
243 if (!$this->pagingMode && $http->hasRelativeLink(
'next')) {
244 $url = $http->getRelativeLink(
'next');
245 $this->endpoint = $url;
246 $parameters = array();
252 $this->context->groupSets = $groupSets;
253 if (empty($ltiUserId)) {
254 $this->context->groups = $groups;
256 $user->groups = $groups;
Class to represent a platform context.
Class to implement the Course Groups service.
static $SCOPE
Access scope.
getGroupSets($limit=null)
Get the course group sets.
__construct($context, $groupsEndpoint, $groupSetsEndpoint=null, $limit=null, $pagingMode=false)
Class constructor.
const MEDIA_TYPE_COURSE_GROUPS
Media type for course groups service.
getGroups($allowNonSets=false, $user=null, $limit=null)
Get the course groups.
const MEDIA_TYPE_COURSE_GROUP_SETS
Media type for course group sets service.
static $defaultLimit
Default limit on size of container to be returned from requests.
Class to implement a service.
send($method, $parameters=array(), $body=null)
Send a service request.
$endpoint
Service endpoint.
Class to represent a platform user.