31 public static $SCOPE =
'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem';
36 public static $SCOPE_READONLY =
'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem.readonly';
71 parent::__construct($platform,
$endpoint);
72 $this->limit = $limit;
73 $this->pagingMode = $pagingMode;
74 $this->scope = self::$SCOPE;
101 $params[
'tag'] =
$tag;
103 if (is_null($limit)) {
104 $limit = $this->limit;
106 if (is_null($limit)) {
107 $limit = self::$defaultLimit;
109 if (!empty($limit)) {
110 $params[
'limit'] = $limit;
112 $lineItems = array();
115 $this->scope = self::$SCOPE_READONLY;
116 $this->mediaType = self::MEDIA_TYPE_LINE_ITEMS;
117 $http = $this->
send(
'GET', $params);
118 $this->scope = self::$SCOPE;
121 if (!empty($http->responseJson)) {
122 foreach ($http->responseJson as $lineItem) {
123 $lineItems[] = self::toLineItem($this->
getPlatform(), $lineItem);
126 if (!$this->pagingMode && $http->hasRelativeLink(
'next')) {
127 $url = $http->getRelativeLink(
'next');
128 $this->endpoint = $url;
149 $lineItem->endpoint =
null;
150 $this->mediaType = self::MEDIA_TYPE_LINE_ITEM;
151 $http = $this->
send(
'POST',
null, self::toJson($lineItem));
152 $ok = $http->ok && !empty($http->responseJson);
154 $newLineItem = self::toLineItem($this->
getPlatform(), $http->responseJson);
155 foreach (get_object_vars($newLineItem) as $key => $value) {
156 $lineItem->$key = $value;
172 $this->mediaType = self::MEDIA_TYPE_LINE_ITEM;
173 $http = $this->
send(
'PUT',
null, self::toJson($lineItem));
175 if ($ok && !empty($http->responseJson)) {
176 $savedLineItem = self::toLineItem($this->
getPlatform(), $http->responseJson);
177 foreach (get_object_vars($savedLineItem) as $key => $value) {
178 $lineItem->$key = $value;
194 $this->mediaType = self::MEDIA_TYPE_LINE_ITEM;
195 $http = $this->
send(
'DELETE');
210 $service =
new self($platform,
$endpoint);
211 $service->scope = self::$SCOPE_READONLY;
212 $service->mediaType = self::MEDIA_TYPE_LINE_ITEM;
213 $http = $service->send(
'GET');
214 $service->scope = self::$SCOPE;
215 if ($http->ok && !empty($http->responseJson)) {
216 $lineItem = self::toLineItem($platform, $http->responseJson);
236 private static function toLineItem($platform, $json)
238 if (!empty($json->id) && !empty($json->label) && !empty($json->scoreMaximum)) {
239 $lineItem =
new LTI\LineItem($platform, $json->label, $json->scoreMaximum);
240 if (!empty($json->id)) {
241 $lineItem->endpoint = $json->id;
243 if (!empty($json->resourceLinkId)) {
244 $lineItem->ltiResourceLinkId = $json->resourceLinkId;
246 if (!empty($json->resourceId)) {
247 $lineItem->resourceId = $json->resourceId;
249 if (!empty($json->tag)) {
250 $lineItem->tag = $json->tag;
252 if (!empty($json->startDateTime)) {
253 $lineItem->submitFrom = strtotime($json->startDateTime);
255 if (!empty($json->endDateTime)) {
256 $lineItem->submitUntil = strtotime($json->endDateTime);
258 if (!empty($json->submissionReview)) {
259 $lineItem->submissionReview = LTI\SubmissionReview::fromJsonObject($json->submissionReview);
275 private static function toJson($lineItem)
277 $json = new \stdClass();
278 if (!empty($lineItem->endpoint)) {
279 $json->id = $lineItem->endpoint;
281 if (!empty($lineItem->label)) {
282 $json->label = $lineItem->label;
284 if (!empty($lineItem->pointsPossible)) {
285 $json->scoreMaximum = $lineItem->pointsPossible;
287 if (!empty($lineItem->ltiResourceLinkId)) {
288 $json->resourceLinkId = $lineItem->ltiResourceLinkId;
290 if (!empty($lineItem->resourceId)) {
291 $json->resourceId = $lineItem->resourceId;
293 if (!empty($lineItem->tag)) {
294 $json->tag = $lineItem->tag;
296 if (!empty($lineItem->submitFrom)) {
297 $json->startDateTime = date(
'Y-m-d\TH:i:sP', $lineItem->submitFrom);
299 if (!empty($lineItem->submitUntil)) {
300 $json->endDateTime = date(
'Y-m-d\TH:i:sP', $lineItem->submitUntil);
302 if (!empty($lineItem->submissionReview)) {
303 $json->submissionReview = $lineItem->submissionReview->toJsonObject();
306 return json_encode($json);
Class to represent a line-item.
$endpoint
Line-item endpoint.
$ltiResourceLinkId
LTI Resource Link ID with which the line item is associated.
$resourceId
Tool resource ID associated with the line-item.
getPlatform()
Get platform.
Class to implement the Assignment and Grade services.
const MEDIA_TYPE_LINE_ITEMS
Line-item container media type.
static $defaultLimit
Default limit on size of container to be returned from requests.
getAll($ltiResourceLinkId=null, $resourceId=null, $tag=null, $limit=null)
Retrieve all line-items.
__construct($platform, $endpoint, $limit=null, $pagingMode=false)
Class constructor.
static $SCOPE_READONLY
Read-only access scope.
static getLineItem($platform, $endpoint)
Retrieve a line item.
const MEDIA_TYPE_LINE_ITEM
Line-item media type.
deleteLineItem($lineItem)
Delete a line-item.
static $SCOPE
Access scope.
saveLineItem($lineItem)
Save a line-item.
createLineItem($lineItem)
Create a new line-item.
Class to implement a service.
send($method, $parameters=array(), $body=null)
Send a service request.