15
15
class LineItem extends AssignmentGrade
16
16
{
17
17
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
+
18
28
/**
19
29
* Access scope.
20
30
*/
@@ -26,14 +36,9 @@ class LineItem extends AssignmentGrade
26
36
public static $ SCOPE_READONLY = 'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem.readonly ' ;
27
37
28
38
/**
29
- * Line item media type .
39
+ * Default limit on size of container to be returned from requests .
30
40
*/
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 ;
37
42
38
43
/**
39
44
* Limit on size of container to be returned from requests.
@@ -95,16 +100,20 @@ public function getAll($ltiResourceLinkId = null, $resourceId = null, $tag = nul
95
100
if (!empty ($ tag )) {
96
101
$ params ['tag ' ] = $ tag ;
97
102
}
103
+ if (is_null ($ limit )) {
104
+ $ limit = $ this ->limit ;
105
+ }
106
+ if (is_null ($ limit )) {
107
+ $ limit = self ::$ defaultLimit ;
108
+ }
98
109
if (!empty ($ limit )) {
99
110
$ params ['limit ' ] = $ limit ;
100
- } elseif (!empty ($ this ->limit )) {
101
- $ params ['limit ' ] = $ this ->limit ;
102
111
}
103
112
$ lineItems = array ();
104
113
$ endpoint = $ this ->endpoint ;
105
114
do {
106
115
$ this ->scope = self ::$ SCOPE_READONLY ;
107
- $ this ->mediaType = self ::$ MEDIA_TYPE_LINE_ITEMS ;
116
+ $ this ->mediaType = self ::MEDIA_TYPE_LINE_ITEMS ;
108
117
$ http = $ this ->send ('GET ' , $ params );
109
118
$ this ->scope = self ::$ SCOPE ;
110
119
$ url = '' ;
@@ -138,7 +147,7 @@ public function getAll($ltiResourceLinkId = null, $resourceId = null, $tag = nul
138
147
public function createLineItem ($ lineItem )
139
148
{
140
149
$ lineItem ->endpoint = null ;
141
- $ this ->mediaType = self ::$ MEDIA_TYPE_LINE_ITEM ;
150
+ $ this ->mediaType = self ::MEDIA_TYPE_LINE_ITEM ;
142
151
$ http = $ this ->send ('POST ' , null , self ::toJson ($ lineItem ));
143
152
$ ok = $ http ->ok && !empty ($ http ->responseJson );
144
153
if ($ ok ) {
@@ -160,7 +169,7 @@ public function createLineItem($lineItem)
160
169
*/
161
170
public function saveLineItem ($ lineItem )
162
171
{
163
- $ this ->mediaType = self ::$ MEDIA_TYPE_LINE_ITEM ;
172
+ $ this ->mediaType = self ::MEDIA_TYPE_LINE_ITEM ;
164
173
$ http = $ this ->send ('PUT ' , null , self ::toJson ($ lineItem ));
165
174
$ ok = $ http ->ok ;
166
175
if ($ ok && !empty ($ http ->responseJson )) {
@@ -182,7 +191,7 @@ public function saveLineItem($lineItem)
182
191
*/
183
192
public function deleteLineItem ($ lineItem )
184
193
{
185
- $ this ->mediaType = self ::$ MEDIA_TYPE_LINE_ITEM ;
194
+ $ this ->mediaType = self ::MEDIA_TYPE_LINE_ITEM ;
186
195
$ http = $ this ->send ('DELETE ' );
187
196
188
197
return $ http ->ok ;
@@ -200,7 +209,7 @@ public static function getLineItem($platform, $endpoint)
200
209
{
201
210
$ service = new self ($ platform , $ endpoint );
202
211
$ service ->scope = self ::$ SCOPE_READONLY ;
203
- $ service ->mediaType = self ::$ MEDIA_TYPE_LINE_ITEM ;
212
+ $ service ->mediaType = self ::MEDIA_TYPE_LINE_ITEM ;
204
213
$ http = $ service ->send ('GET ' );
205
214
$ service ->scope = self ::$ SCOPE ;
206
215
if ($ http ->ok && !empty ($ http ->responseJson )) {
0 commit comments