Skip to content

Commit cd07ee0

Browse files
committed
Add default limit property to relevant services
1 parent a0ea045 commit cd07ee0

File tree

4 files changed

+56
-17
lines changed

4 files changed

+56
-17
lines changed

src/Service/Groups.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace ceLTIc\LTI\Service;
44

5-
use ceLTIc\LTI;
65
use ceLTIc\LTI\Context;
76

87
/**
@@ -30,6 +29,11 @@ class Groups extends Service
3029
*/
3130
public static $SCOPE = 'https://purl.imsglobal.org/spec/lti-gs/scope/contextgroup.readonly';
3231

32+
/**
33+
* Default limit on size of container to be returned from requests.
34+
*/
35+
public static $defaultLimit = null;
36+
3337
/**
3438
* The context to which the course groups apply.
3539
*
@@ -131,6 +135,9 @@ public function getGroupSets($limit = null)
131135
if (is_null($limit)) {
132136
$limit = $this->limit;
133137
}
138+
if (is_null($limit)) {
139+
$limit = self::$defaultLimit;
140+
}
134141
if (!empty($limit)) {
135142
$parameters['limit'] = strval($limit);
136143
}
@@ -190,6 +197,9 @@ public function getGroups($allowNonSets = false, $user = null, $limit = null)
190197
if (is_null($limit)) {
191198
$limit = $this->limit;
192199
}
200+
if (is_null($limit)) {
201+
$limit = self::$defaultLimit;
202+
}
193203
if (!empty($limit)) {
194204
$parameters['limit'] = strval($limit);
195205
}

src/Service/LineItem.php

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@
1515
class LineItem extends AssignmentGrade
1616
{
1717

18+
/**
19+
* Line item media type.
20+
*/
21+
const MEDIA_TYPE_LINE_ITEM = 'application/vnd.ims.lis.v2.lineitem+json';
22+
23+
/**
24+
* Line item container media type.
25+
*/
26+
const MEDIA_TYPE_LINE_ITEMS = 'application/vnd.ims.lis.v2.lineitemcontainer+json';
27+
1828
/**
1929
* Access scope.
2030
*/
@@ -26,14 +36,9 @@ class LineItem extends AssignmentGrade
2636
public static $SCOPE_READONLY = 'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem.readonly';
2737

2838
/**
29-
* Line item media type.
39+
* Default limit on size of container to be returned from requests.
3040
*/
31-
private static $MEDIA_TYPE_LINE_ITEM = 'application/vnd.ims.lis.v2.lineitem+json';
32-
33-
/**
34-
* Line item container media type.
35-
*/
36-
private static $MEDIA_TYPE_LINE_ITEMS = 'application/vnd.ims.lis.v2.lineitemcontainer+json';
41+
public static $defaultLimit = null;
3742

3843
/**
3944
* Limit on size of container to be returned from requests.
@@ -95,16 +100,20 @@ public function getAll($ltiResourceLinkId = null, $resourceId = null, $tag = nul
95100
if (!empty($tag)) {
96101
$params['tag'] = $tag;
97102
}
103+
if (is_null($limit)) {
104+
$limit = $this->limit;
105+
}
106+
if (is_null($limit)) {
107+
$limit = self::$defaultLimit;
108+
}
98109
if (!empty($limit)) {
99110
$params['limit'] = $limit;
100-
} elseif (!empty($this->limit)) {
101-
$params['limit'] = $this->limit;
102111
}
103112
$lineItems = array();
104113
$endpoint = $this->endpoint;
105114
do {
106115
$this->scope = self::$SCOPE_READONLY;
107-
$this->mediaType = self::$MEDIA_TYPE_LINE_ITEMS;
116+
$this->mediaType = self::MEDIA_TYPE_LINE_ITEMS;
108117
$http = $this->send('GET', $params);
109118
$this->scope = self::$SCOPE;
110119
$url = '';
@@ -138,7 +147,7 @@ public function getAll($ltiResourceLinkId = null, $resourceId = null, $tag = nul
138147
public function createLineItem($lineItem)
139148
{
140149
$lineItem->endpoint = null;
141-
$this->mediaType = self::$MEDIA_TYPE_LINE_ITEM;
150+
$this->mediaType = self::MEDIA_TYPE_LINE_ITEM;
142151
$http = $this->send('POST', null, self::toJson($lineItem));
143152
$ok = $http->ok && !empty($http->responseJson);
144153
if ($ok) {
@@ -160,7 +169,7 @@ public function createLineItem($lineItem)
160169
*/
161170
public function saveLineItem($lineItem)
162171
{
163-
$this->mediaType = self::$MEDIA_TYPE_LINE_ITEM;
172+
$this->mediaType = self::MEDIA_TYPE_LINE_ITEM;
164173
$http = $this->send('PUT', null, self::toJson($lineItem));
165174
$ok = $http->ok;
166175
if ($ok && !empty($http->responseJson)) {
@@ -182,7 +191,7 @@ public function saveLineItem($lineItem)
182191
*/
183192
public function deleteLineItem($lineItem)
184193
{
185-
$this->mediaType = self::$MEDIA_TYPE_LINE_ITEM;
194+
$this->mediaType = self::MEDIA_TYPE_LINE_ITEM;
186195
$http = $this->send('DELETE');
187196

188197
return $http->ok;
@@ -200,7 +209,7 @@ public static function getLineItem($platform, $endpoint)
200209
{
201210
$service = new self($platform, $endpoint);
202211
$service->scope = self::$SCOPE_READONLY;
203-
$service->mediaType = self::$MEDIA_TYPE_LINE_ITEM;
212+
$service->mediaType = self::MEDIA_TYPE_LINE_ITEM;
204213
$http = $service->send('GET');
205214
$service->scope = self::$SCOPE;
206215
if ($http->ok && !empty($http->responseJson)) {

src/Service/Membership.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ class Membership extends Service
3131
*/
3232
public static $SCOPE = 'https://purl.imsglobal.org/spec/lti-nrps/scope/contextmembership.readonly';
3333

34+
/**
35+
* Default limit on size of container to be returned from requests.
36+
*/
37+
public static $defaultLimit = null;
38+
3439
/**
3540
* The object to which the memberships apply (ResourceLink or Context).
3641
*
@@ -121,6 +126,9 @@ private function getMembers($withGroups, $role = null, $limit = null)
121126
if (is_null($limit)) {
122127
$limit = $this->limit;
123128
}
129+
if (is_null($limit)) {
130+
$limit = self::$defaultLimit;
131+
}
124132
if (!empty($limit)) {
125133
$parameters['limit'] = strval($limit);
126134
}
@@ -151,6 +159,9 @@ private function getMembers($withGroups, $role = null, $limit = null)
151159
isset($http->responseJson->pageOf->membershipSubject->membership)) {
152160
$isjsonld = true;
153161
$memberships = array_merge($memberships, $http->responseJson->pageOf->membershipSubject->membership);
162+
if (!empty($http->responseJson->nextPage)) {
163+
$http->relativeLinks['next'] = $http->responseJson->nextPage;
164+
}
154165
} elseif (isset($http->responseJson->members)) {
155166
$memberships = array_merge($memberships, $http->responseJson->members);
156167
}

src/Service/Result.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ class Result extends AssignmentGrade
2020
*/
2121
public static $SCOPE = 'https://purl.imsglobal.org/spec/lti-ags/scope/result.readonly';
2222

23+
/**
24+
* Default limit on size of container to be returned from requests.
25+
*/
26+
public static $defaultLimit = null;
27+
2328
/**
2429
* Limit on size of container to be returned from requests.
2530
*
@@ -65,10 +70,14 @@ public function __construct($platform, $endpoint, $limit = null, $pagingMode = f
6570
public function getAll($limit = null)
6671
{
6772
$params = array();
73+
if (is_null($limit)) {
74+
$limit = $this->limit;
75+
}
76+
if (is_null($limit)) {
77+
$limit = self::$defaultLimit;
78+
}
6879
if (!empty($limit)) {
6980
$params['limit'] = $limit;
70-
} elseif (!empty($this->limit)) {
71-
$params['limit'] = $this->limit;
7281
}
7382
$outcomes = array();
7483
$endpoint = $this->endpoint;

0 commit comments

Comments
 (0)