LTI Integration Library 4.10.3
PHP class library for building LTI integrations
 
Loading...
Searching...
No Matches
Result.php
1<?php
2
3namespace ceLTIc\LTI\Service;
4
8
17{
18
24 public static $SCOPE = 'https://purl.imsglobal.org/spec/lti-ags/scope/result.readonly';
25
31 public static $defaultLimit = 500;
32
40 private $limit;
41
49 private $pagingMode;
50
59 public function __construct($platform, $endpoint, $limit = null, $pagingMode = false)
60 {
61 parent::__construct($platform, $endpoint, '/results');
62 $this->limit = $limit;
63 $this->pagingMode = $pagingMode;
64 $this->scope = self::$SCOPE;
65 $this->mediaType = 'application/vnd.ims.lis.v2.resultcontainer+json';
66 }
67
75 public function getAll($limit = null)
76 {
77 $params = array();
78 if (is_null($limit)) {
79 $limit = $this->limit;
80 }
81 if (is_null($limit)) {
82 $limit = self::$defaultLimit;
83 }
84 if (!empty($limit)) {
85 $params['limit'] = $limit;
86 }
87 $outcomes = array();
89 do {
90 $http = $this->send('GET', $params);
91 $url = '';
92 if ($http->ok) {
93 if (!empty($http->responseJson)) {
94 foreach ($http->responseJson as $outcome) {
95 $outcomes[] = self::getOutcome($outcome);
96 }
97 }
98 if (!$this->pagingMode && $http->hasRelativeLink('next')) {
99 $url = $http->getRelativeLink('next');
100 $this->endpoint = $url;
101 $params = array();
102 }
103 } else {
104 $outcomes = false;
105 }
106 } while ($url);
107 $this->endpoint = $endpoint;
108
109 return $outcomes;
110 }
111
119 public function get($user)
120 {
121 $params = array('user_id' => $user->ltiUserId);
122 $http = $this->send('GET', $params);
123 if ($http->ok) {
124 if (!empty($http->responseJson)) {
125 $outcome = self::getOutcome(reset($http->responseJson));
126 } else {
127 $outcome = null;
128 }
129 return $outcome;
130 } else {
131 return false;
132 }
133 }
134
135###
136### PRIVATE METHOD
137###
138
146 private static function getOutcome($json)
147 {
148 $outcome = new Outcome();
149 $outcome->ltiUserId = $json->userId;
150 if (isset($json->resultScore)) {
151 $outcome->setValue($json->resultScore);
152 }
153 if (isset($json->resultMaximum)) {
154 $outcome->setPointsPossible($json->resultMaximum);
155 }
156 if (isset($json->comment)) {
157 $outcome->comment = $json->comment;
158 }
159
160 return $outcome;
161 }
162
163}
Class to represent an outcome.
Definition Outcome.php:13
Class to represent a platform.
Definition Platform.php:18
Class to implement the Assignment and Grade services.
Class to implement the Result service.
Definition Result.php:17
static $SCOPE
Access scope.
Definition Result.php:24
getAll($limit=null)
Retrieve all outcomes for a line-item.
Definition Result.php:75
__construct($platform, $endpoint, $limit=null, $pagingMode=false)
Class constructor.
Definition Result.php:59
static $defaultLimit
Default limit on size of container to be returned from requests.
Definition Result.php:31
Class to implement a service.
Definition Service.php:19
send($method, $parameters=array(), $body=null)
Send a service request.
Definition Service.php:119
$endpoint
Service endpoint.
Definition Service.php:33
Class to represent a platform user.
Definition User.php:13