ILIAS  release_8 Revision v8.24
UserResult.php
Go to the documentation of this file.
1<?php
2
20
22
30class UserResult extends User
31{
37 public ?string $ltiResultSourcedId = null;
38
44 public ?int $created = null;
45
51 public ?int $updated = null;
52
58 private ?ResourceLink $resourceLink = null;
59
65 private ?int $resourceLinkId = null;
66
72 private ?int $id = null;
73
80
84 public function __construct()
85 {
86 $this->initialize();
87 }
88
92 public function initialize()
93 {
94 parent::initialize();
95 $this->ltiResultSourcedId = null;
96 $this->created = null;
97 $this->updated = null;
98 }
99
105 public function save(): bool
106 {
107 if (!is_null($this->resourceLinkId)) {
108 $ok = $this->getDataConnector()->saveUserResult($this);
109 } else {
110 $ok = true;
111 }
112
113 return $ok;
114 }
115
121 public function delete(): bool
122 {
123 $ok = $this->getDataConnector()->deleteUserResult($this);
124
125 return $ok;
126 }
127
133 public function getResourceLink(): ?ResourceLink
134 {
135 if (is_null($this->resourceLink) && !is_null($this->resourceLinkId)) {
136 $this->resourceLink = ResourceLink::fromRecordId($this->resourceLinkId, $this->getDataConnector());
137 }
138
139 return $this->resourceLink;
140 }
141
147 {
148 $this->resourceLink = $resourceLink;
149 }
150
156 public function getRecordId(): ?int
157 {
158 return $this->id;
159 }
160
165 public function setRecordId(int $id)
166 {
167 $this->id = $id;
168 }
169
174 public function setResourceLinkId(int $resourceLinkId)
175 {
176 $this->resourceLink = null;
177 $this->resourceLinkId = $resourceLinkId;
178 }
179
185 public function getDataConnector()
186 {
188 }
189
195 {
196 $this->dataConnector = $dataConnector;
197 }
198
205 public function getId(int $idScope = null, Platform $platform = null): string
206 {
207 $key = '';
208 if (is_null($platform) && !is_null($this->getResourceLink())) {
209 $platform = $this->getResourceLink()->getPlatform();
210 }
211 if (!is_null($platform)) {
212 $key = $platform->getId();
213 }
214 if (is_null($idScope) && !is_null($this->getResourceLink())) {
215 $idScope = $this->resourceLink->getPlatform()->idScope;
216 }
217 if (is_null($idScope)) {
218 $idScope = Tool::ID_SCOPE_ID_ONLY;
219 }
220 switch ($idScope) {
223 break;
225 if ($this->resourceLink->getContext() && $this->resourceLink->getContext()->ltiContextId) {
226 $id = $key . Tool::ID_SCOPE_SEPARATOR . $this->resourceLink->getContext()->ltiContextId;
227 }
229 break;
231 if (!is_null($this->resourceLink) && !empty($this->resourceLink->ltiResourceLinkId)) {
232 $id = $key . Tool::ID_SCOPE_SEPARATOR . $this->resourceLink->ltiResourceLinkId;
233 }
235 break;
236 default:
238 break;
239 }
240
241 return $id;
242 }
243
251 {
252 $userresult = new UserResult();
253 $userresult->dataConnector = $dataConnector;
254 $userresult->load($id);
255
256 return $userresult;
257 }
258
266 {
267 $userresult = new UserResult();
268 $userresult->resourceLink = $resourceLink;
269 if (!is_null($resourceLink)) {
270 $userresult->resourceLinkId = $resourceLink->getRecordId();
271 $userresult->dataConnector = $resourceLink->getDataConnector();
272 }
273 $userresult->ltiUserId = $ltiUserId;
274 if (!empty($ltiUserId)) {
275 $userresult->load();
276 }
277
278 return $userresult;
279 }
280
281 ###
282 ### PRIVATE METHODS
283 ###
284
290 private function load(int $id = null): bool
291 {
292 $this->initialize();
293 $this->id = $id;
294 $dataConnector = $this->getDataConnector();
295 if (!is_null($dataConnector)) {
296 return $dataConnector->loadUserResult($this);
297 }
298
299 return false;
300 }
301}
Class to provide a connection to a persistent store for LTI objects.
loadUserResult(UserResult $userresult)
Load user object.
Class to represent a platform.
Definition: Platform.php:36
const ID_SCOPE_RESOURCE
Prefix the ID with the consumer key and resource ID.
Definition: Tool.php:66
const ID_SCOPE_GLOBAL
Prefix an ID with the consumer key.
Definition: Tool.php:56
const ID_SCOPE_ID_ONLY
Use ID value only.
Definition: Tool.php:51
const ID_SCOPE_SEPARATOR
Character used to separate each element of an ID.
Definition: Tool.php:71
const ID_SCOPE_CONTEXT
Prefix the ID with the consumer key and context ID.
Definition: Tool.php:61
Class to represent a platform user.
Definition: UserResult.php:31
int $id
UserResult record ID value.
Definition: UserResult.php:72
setResourceLinkId(int $resourceLinkId)
Set resource link ID of user.
Definition: UserResult.php:174
int $resourceLinkId
Resource link record ID.
Definition: UserResult.php:65
DataConnector $dataConnector
Data connector object or string.
Definition: UserResult.php:79
getDataConnector()
Get the data connector.
Definition: UserResult.php:185
load(int $id=null)
Load the user from the database.
Definition: UserResult.php:290
string $ltiResultSourcedId
UserResult's result sourcedid.
Definition: UserResult.php:37
int $created
Date/time the record was created.
Definition: UserResult.php:44
initialize()
Initialise the user.
Definition: UserResult.php:92
setRecordId(int $id)
Set record ID of user.
Definition: UserResult.php:165
static fromResourceLink(ResourceLink $resourceLink, string $ltiUserId)
Class constructor from resource link.
Definition: UserResult.php:265
save()
Save the user to the database.
Definition: UserResult.php:105
getResourceLink()
Get resource link.
Definition: UserResult.php:133
ResourceLink $resourceLink
Resource link object.
Definition: UserResult.php:58
__construct()
Class constructor.
Definition: UserResult.php:84
getId(int $idScope=null, Platform $platform=null)
Get the user ID (which may be a compound of the platform and resource link IDs).
Definition: UserResult.php:205
getRecordId()
Get record ID of user.
Definition: UserResult.php:156
static fromRecordId(int $id, DataConnector $dataConnector)
Load the user from the database.
Definition: UserResult.php:250
setResourceLink(ResourceLink $resourceLink)
Set resource link.
Definition: UserResult.php:146
setDataConnector(DataConnector $dataConnector)
Set the data connector.
Definition: UserResult.php:194
int $updated
Date/time the record was last updated.
Definition: UserResult.php:51
Class to represent a platform user.
Definition: User.php:31
string $ltiUserId
user ID as supplied in the last connection request.
Definition: User.php:107
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: AccessToken.php:19
string $key
Consumer key/client ID value.
Definition: System.php:193