LTI Integration Library 4.10.3
PHP class library for building LTI integrations
 
Loading...
Searching...
No Matches
UserResult.php
1<?php
2
3namespace ceLTIc\LTI;
4
8
16class UserResult extends User
17{
18
24 public $ltiResultSourcedId = null;
25
31 public $created = null;
32
38 public $updated = null;
39
45 private $resourceLink = null;
46
52 private $resourceLinkId = null;
53
59 private $id = null;
60
66 private $dataConnector = null;
67
71 public function __construct()
72 {
73 $this->initialize();
74 }
75
79 public function initialize()
80 {
81 parent::initialize();
82 $this->ltiResultSourcedId = null;
83 $this->created = null;
84 $this->updated = null;
85 }
86
92 public function save()
93 {
94 if (!is_null($this->resourceLinkId)) {
95 $ok = $this->getDataConnector()->saveUserResult($this);
96 } else {
97 $ok = true;
98 }
99
100 return $ok;
101 }
102
108 public function delete()
109 {
110 $ok = $this->getDataConnector()->deleteUserResult($this);
111
112 return $ok;
113 }
114
120 public function getResourceLink()
121 {
122 if (is_null($this->resourceLink) && !is_null($this->resourceLinkId)) {
123 $this->resourceLink = ResourceLink::fromRecordId($this->resourceLinkId, $this->getDataConnector());
124 }
125
126 return $this->resourceLink;
127 }
128
134 public function setResourceLink($resourceLink)
135 {
136 $this->resourceLink = $resourceLink;
137 }
138
144 public function getRecordId()
145 {
146 return $this->id;
147 }
148
154 public function setRecordId($id)
155 {
156 $this->id = $id;
157 }
158
164 public function setResourceLinkId($resourceLinkId)
165 {
166 $this->resourceLink = null;
167 $this->resourceLinkId = $resourceLinkId;
168 }
169
175 public function getDataConnector()
176 {
177 return $this->dataConnector;
178 }
179
185 public function setDataConnector($dataConnector)
186 {
187 $this->dataConnector = $dataConnector;
188 }
189
198 public function getId($idScope = null, $source = null)
199 {
200 $resourceLink = $this->getResourceLink();
201 $context = null;
202 $platform = null;
203 if ($source instanceof Context) {
204 $context = $source;
205 $platform = $context->getPlatform();
206 } elseif (!is_null($resourceLink)) {
207 $context = $resourceLink->getContext();
208 $platform = $resourceLink->getPlatform();
209 } elseif ($source instanceof Platform) {
210 $platform = $source;
211 }
212 $key = '';
213 if (!is_null($platform)) {
214 $key = $platform->getId();
215 if (is_null($idScope)) {
216 $idScope = $platform->idScope;
217 }
218 }
219 if (is_null($idScope)) {
220 $idScope = Tool::ID_SCOPE_ID_ONLY;
221 }
222 $ok = !empty($key) || ($idScope === Tool::ID_SCOPE_ID_ONLY);
223 if ($ok) {
224 $id = $key . Tool::ID_SCOPE_SEPARATOR;
225 switch ($idScope) {
227 $id .= $this->ltiUserId;
228 break;
230 $ok = !is_null($context) && !empty($context->ltiContextId);
231 if ($ok) {
232 $id .= $context->ltiContextId . Tool::ID_SCOPE_SEPARATOR . $this->ltiUserId;
233 }
234 break;
236 $ok = !is_null($resourceLink) && !empty($resourceLink->ltiResourceLinkId);
237 if ($ok) {
238 $id .= $resourceLink->ltiResourceLinkId . Tool::ID_SCOPE_SEPARATOR . $this->ltiUserId;
239 }
240 break;
241 default:
242 $id = $this->ltiUserId;
243 break;
244 }
245 }
246 if (!$ok) {
247 $id = null;
248 }
249
250 return $id;
251 }
252
261 public static function fromRecordId($id, $dataConnector)
262 {
263 $userresult = new UserResult();
264 $userresult->dataConnector = $dataConnector;
265 $userresult->load($id);
266
267 return $userresult;
268 }
269
278 public static function fromResourceLink($resourceLink, $ltiUserId)
279 {
280 $userresult = new UserResult();
281 $userresult->resourceLink = $resourceLink;
282 if (!is_null($resourceLink)) {
283 $userresult->resourceLinkId = $resourceLink->getRecordId();
284 $userresult->dataConnector = $resourceLink->getDataConnector();
285 }
286 $userresult->ltiUserId = $ltiUserId;
287 if (!empty($ltiUserId)) {
288 $userresult->load();
289 }
290
291 return $userresult;
292 }
293
294###
295### PRIVATE METHODS
296###
297
305 private function load($id = null)
306 {
307 $this->initialize();
308 $this->id = $id;
309 $dataConnector = $this->getDataConnector();
310 if (!is_null($dataConnector)) {
311 return $dataConnector->loadUserResult($this);
312 }
313
314 return false;
315 }
316
317}
Class to represent a platform context.
Definition Context.php:18
Class to provide a connection to a persistent store for LTI objects.
Class to represent a platform.
Definition Platform.php:18
const ID_SCOPE_RESOURCE
Prefix the ID with the consumer key and resource ID.
Definition Tool.php:49
const ID_SCOPE_SEPARATOR
Character used to separate each element of an ID.
Definition Tool.php:54
const ID_SCOPE_ID_ONLY
Use ID value only.
Definition Tool.php:34
const ID_SCOPE_GLOBAL
Prefix an ID with the consumer key.
Definition Tool.php:39
const ID_SCOPE_CONTEXT
Prefix the ID with the consumer key and context ID.
Definition Tool.php:44
Class to represent a platform user association with a resource link.
__construct()
Class constructor.
$updated
Date/time the record was last updated.
getId($idScope=null, $source=null)
Get the user ID (which may be a compound of the platform and resource link IDs).
setDataConnector($dataConnector)
Set the data connector.
getDataConnector()
Get the data connector.
getResourceLink()
Get resource link.
initialize()
Initialise the user.
$created
Date/time the record was created.
$ltiResultSourcedId
UserResult's result sourcedid.
setResourceLink($resourceLink)
Set resource link.
setResourceLinkId($resourceLinkId)
Set resource link ID of user.
getRecordId()
Get record ID of user.
setRecordId($id)
Set record ID of user.
static fromResourceLink($resourceLink, $ltiUserId)
Class constructor from resource link.
save()
Save the user to the database.
static fromRecordId($id, $dataConnector)
Load the user from the database.
Class to represent a platform user.
Definition User.php:13
$ltiUserId
user ID as supplied in the last connection request.
Definition User.php:132