LTI Integration Library  3.1.0
PHP class library for building LTI integrations
UserResult.php
Go to the documentation of this file.
1 <?php
2 
3 namespace ceLTIc\LTI;
4 
6 
15 class UserResult extends User
16 {
17 
23  public $ltiResultSourcedId = null;
24 
30  public $created = null;
31 
37  public $updated = null;
38 
44  private $resourceLink = null;
45 
51  private $resourceLinkId = null;
52 
58  private $id = null;
59 
65  private $dataConnector = null;
66 
70  public function __construct()
71  {
72  $this->initialize();
73  }
74 
78  public function initialize()
79  {
80  parent::initialize();
81  $this->ltiResultSourcedId = null;
82  $this->created = null;
83  $this->updated = null;
84  }
85 
91  public function save()
92  {
93  if (!empty($this->ltiResultSourcedId) && !is_null($this->resourceLinkId)) {
94  $ok = $this->getDataConnector()->saveUserResult($this);
95  } else {
96  $ok = true;
97  }
98 
99  return $ok;
100  }
101 
107  public function delete()
108  {
109  $ok = $this->getDataConnector()->deleteUserResult($this);
110 
111  return $ok;
112  }
113 
119  public function getResourceLink()
120  {
121  if (is_null($this->resourceLink) && !is_null($this->resourceLinkId)) {
122  $this->resourceLink = ResourceLink::fromRecordId($this->resourceLinkId, $this->getDataConnector());
123  }
124 
125  return $this->resourceLink;
126  }
127 
133  public function setResourceLink($resourceLink)
134  {
135  $this->resourceLink = $resourceLink;
136  }
137 
143  public function getRecordId()
144  {
145  return $this->id;
146  }
147 
153  public function setRecordId($id)
154  {
155  $this->id = $id;
156  }
157 
163  public function setResourceLinkId($resourceLinkId)
164  {
165  $this->resourceLinkId = $resourceLinkId;
166  }
167 
173  public function getDataConnector()
174  {
175  return $this->dataConnector;
176  }
177 
183  public function setDataConnector($dataConnector)
184  {
185  $this->dataConnector = $dataConnector;
186  }
187 
195  public function getId($idScope = null)
196  {
197  if (empty($idScope)) {
198  if (!is_null($this->resourceLink)) {
199  $idScope = $this->resourceLink->getConsumer()->idScope;
200  } else {
202  }
203  }
204  switch ($idScope) {
207  break;
209  $id = $this->getResourceLink()->getKey();
210  if ($this->resourceLink->ltiContextId) {
211  $id .= ToolProvider::ID_SCOPE_SEPARATOR . $this->resourceLink->ltiContextId;
212  }
214  break;
216  $id = $this->getResourceLink()->getKey();
217  if ($this->resourceLink->ltiResourceLinkId) {
218  $id .= ToolProvider::ID_SCOPE_SEPARATOR . $this->resourceLink->ltiResourceLinkId;
219  }
221  break;
222  default:
223  $id = $this->ltiUserId;
224  break;
225  }
226 
227  return $id;
228  }
229 
238  public static function fromRecordId($id, $dataConnector)
239  {
240  $userresult = new UserResult();
241  $userresult->dataConnector = $dataConnector;
242  $userresult->load($id);
243 
244  return $userresult;
245  }
246 
255  public static function fromResourceLink($resourceLink, $ltiUserId)
256  {
257  $userresult = new UserResult();
258  $userresult->resourceLink = $resourceLink;
259  if (!is_null($resourceLink)) {
260  $userresult->resourceLinkId = $resourceLink->getRecordId();
261  $userresult->dataConnector = $resourceLink->getDataConnector();
262  }
263  $userresult->ltiUserId = $ltiUserId;
264  if (!empty($ltiUserId)) {
265  $userresult->load();
266  }
267 
268  return $userresult;
269  }
270 
271 ###
272 ### PRIVATE METHODS
273 ###
274 
282  private function load($id = null)
283  {
284  $this->initialize();
285  $this->id = $id;
286  $dataConnector = $this->getDataConnector();
287  if (!is_null($dataConnector)) {
288  return $dataConnector->loadUserResult($this);
289  }
290 
291  return false;
292  }
293 
294 }
getRecordId()
Get record ID of user.
Definition: UserResult.php:143
static fromResourceLink($resourceLink, $ltiUserId)
Class constructor from resource link.
Definition: UserResult.php:255
$ltiResultSourcedId
UserResult's result sourcedid.
Definition: UserResult.php:23
$ltiUserId
user ID as supplied in the last connection request.
Definition: User.php:77
$created
Date/time the record was created.
Definition: UserResult.php:30
initialize()
Initialise the user.
Definition: UserResult.php:78
const ID_SCOPE_ID_ONLY
Use ID value only.
const ID_SCOPE_SEPARATOR
Character used to separate each element of an ID.
setResourceLink($resourceLink)
Set resource link.
Definition: UserResult.php:133
getResourceLink()
Get resource link.
Definition: UserResult.php:119
const ID_SCOPE_CONTEXT
Prefix the ID with the consumer key and context ID.
const ID_SCOPE_GLOBAL
Prefix an ID with the consumer key.
static fromRecordId($id, $dataConnector)
Load the user from the database.
Definition: UserResult.php:238
__construct()
Class constructor.
Definition: UserResult.php:70
$updated
Date/time the record was last updated.
Definition: UserResult.php:37
getId($idScope=null)
Get the user ID (which may be a compound of the tool consumer and resource link IDs).
Definition: UserResult.php:195
const ID_SCOPE_RESOURCE
Prefix the ID with the consumer key and resource ID.
Class to represent a tool consumer user.
Definition: UserResult.php:15
save()
Save the user to the database.
Definition: UserResult.php:91
setResourceLinkId($resourceLinkId)
Set resource link ID of user.
Definition: UserResult.php:163
setRecordId($id)
Set record ID of user.
Definition: UserResult.php:153
Class to represent a tool consumer user.
Definition: User.php:13
getDataConnector()
Get the data connector.
Definition: UserResult.php:173
setDataConnector($dataConnector)
Set the data connector.
Definition: UserResult.php:183