ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
IMSGlobal\LTI\ToolProvider\User Class Reference

Class to represent a tool consumer user. More...

+ Collaboration diagram for IMSGlobal\LTI\ToolProvider\User:

Public Member Functions

 __construct ()
 Class constructor. More...
 
 initialize ()
 Initialise the user. More...
 
 initialise ()
 Initialise the user. More...
 
 save ()
 Save the user to the database. More...
 
 delete ()
 Delete the user from the database. More...
 
 getResourceLink ()
 Get resource link. More...
 
 getRecordId ()
 Get record ID of user. More...
 
 setRecordId ($id)
 Set record ID of user. More...
 
 setResourceLinkId ($resourceLinkId)
 Set resource link ID of user. More...
 
 getDataConnector ()
 Get the data connector. More...
 
 getId ($idScope=null)
 Get the user ID (which may be a compound of the tool consumer and resource link IDs). More...
 
 setNames ($firstname, $lastname, $fullname)
 Set the user's name. More...
 
 setEmail ($email, $defaultEmail=null)
 Set the user's email address. More...
 
 isAdmin ()
 Check if the user is an administrator (at any of the system, institution or context levels). More...
 
 isStaff ()
 Check if the user is staff. More...
 
 isLearner ()
 Check if the user is a learner. More...
 

Static Public Member Functions

static fromRecordId ($id, $dataConnector)
 Load the user from the database. More...
 
static fromResourceLink ($resourceLink, $ltiUserId)
 Class constructor from resource link. More...
 

Data Fields

 $firstname = ''
 User's first name. More...
 
 $lastname = ''
 User's last name (surname or family name). More...
 
 $fullname = ''
 User's fullname. More...
 
 $email = ''
 User's email address. More...
 
 $image = ''
 User's image URI. More...
 
 $roles = array()
 Roles for user. More...
 
 $groups = array()
 Groups for user. More...
 
 $ltiResultSourcedId = null
 User's result sourcedid. More...
 
 $created = null
 Date/time the record was created. More...
 
 $updated = null
 Date/time the record was last updated. More...
 
 $ltiUserId = null
 user ID as supplied in the last connection request. More...
 

Private Member Functions

 hasRole ($role)
 Check whether the user has a specified role name. More...
 
 load ($id=null)
 Load the user from the database. More...
 

Private Attributes

 $resourceLink = null
 Resource link object. More...
 
 $resourceLinkId = null
 Resource link record ID. More...
 
 $id = null
 User record ID value. More...
 
 $dataConnector = null
 Data connector object or string. More...
 

Detailed Description

Class to represent a tool consumer user.

Author
Stephen P Vickers svick.nosp@m.ers@.nosp@m.imsgl.nosp@m.obal.nosp@m..org
Date
2016
Version
3.0.2 @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0

Definition at line 15 of file User.php.

Constructor & Destructor Documentation

◆ __construct()

IMSGlobal\LTI\ToolProvider\User::__construct ( )

Class constructor.

Definition at line 113 of file User.php.

114 {
115
116 $this->initialize();
117
118 }
initialize()
Initialise the user.
Definition: User.php:123

References IMSGlobal\LTI\ToolProvider\User\initialize().

+ Here is the call graph for this function:

Member Function Documentation

◆ delete()

IMSGlobal\LTI\ToolProvider\User::delete ( )

Delete the user from the database.

Returns
boolean True if the user object was successfully deleted

Definition at line 174 of file User.php.

175 {
176
177 $ok = $this->getDataConnector()->deleteUser($this);
178
179 return $ok;
180
181 }
getDataConnector()
Get the data connector.
Definition: User.php:240

References $ok, and IMSGlobal\LTI\ToolProvider\User\getDataConnector().

+ Here is the call graph for this function:

◆ fromRecordId()

static IMSGlobal\LTI\ToolProvider\User::fromRecordId (   $id,
  $dataConnector 
)
static

Load the user from the database.

Parameters
int$idRecord ID of user
DataConnector$dataConnectorDatabase connection object
Returns
User User object

Definition at line 395 of file User.php.

396 {
397
398 $user = new User();
399 $user->dataConnector = $dataConnector;
400 $user->load($id);
401
402 return $user;
403
404 }
$id
User record ID value.
Definition: User.php:96
$dataConnector
Data connector object or string.
Definition: User.php:108
$user
Definition: migrateto20.php:57

References IMSGlobal\LTI\ToolProvider\User\$dataConnector, IMSGlobal\LTI\ToolProvider\User\$id, and $user.

Referenced by IMSGlobal\LTI\ToolProvider\DataConnector\DataConnector_pdo\getUserResultSourcedIDsResourceLink().

+ Here is the caller graph for this function:

◆ fromResourceLink()

static IMSGlobal\LTI\ToolProvider\User::fromResourceLink (   $resourceLink,
  $ltiUserId 
)
static

Class constructor from resource link.

Parameters
ResourceLink$resourceLinkResource_Link object
string$ltiUserIdUser ID value
Returns
User

Definition at line 413 of file User.php.

414 {
415
416 $user = new User();
417 $user->resourceLink = $resourceLink;
418 if (!is_null($resourceLink)) {
419 $user->resourceLinkId = $resourceLink->getRecordId();
420 $user->dataConnector = $resourceLink->getDataConnector();
421 }
422 $user->ltiUserId = $ltiUserId;
423 if (!empty($ltiUserId)) {
424 $user->load();
425 }
426
427 return $user;
428
429 }
$ltiUserId
user ID as supplied in the last connection request.
Definition: User.php:102
$resourceLink
Resource link object.
Definition: User.php:84

References IMSGlobal\LTI\ToolProvider\User\$ltiUserId, IMSGlobal\LTI\ToolProvider\User\$resourceLink, and $user.

Referenced by IMSGlobal\LTI\ToolProvider\ToolProvider\authenticate(), IMSGlobal\LTI\ToolProvider\ResourceLink\doMembershipsService(), IMSGlobal\LTI\ToolProvider\Service\Membership\get(), IMSGlobal\LTI\ToolProvider\DataConnector\DataConnector_mysql\getUserResultSourcedIDsResourceLink(), ilLTIAppEventListener\handleOutcomeWithoutLP(), and ilLTIAppEventListener\tryOutcomeService().

+ Here is the caller graph for this function:

◆ getDataConnector()

IMSGlobal\LTI\ToolProvider\User::getDataConnector ( )

Get the data connector.

Returns
mixed Data connector object or string

Definition at line 240 of file User.php.

241 {
242
244
245 }

References IMSGlobal\LTI\ToolProvider\User\$dataConnector.

Referenced by IMSGlobal\LTI\ToolProvider\User\delete(), IMSGlobal\LTI\ToolProvider\User\getResourceLink(), IMSGlobal\LTI\ToolProvider\User\load(), and IMSGlobal\LTI\ToolProvider\User\save().

+ Here is the caller graph for this function:

◆ getId()

IMSGlobal\LTI\ToolProvider\User::getId (   $idScope = null)

Get the user ID (which may be a compound of the tool consumer and resource link IDs).

Parameters
int$idScopeScope to use for user ID (optional, default is null for consumer default setting)
Returns
string User ID value

Definition at line 254 of file User.php.

255 {
256
257 if (empty($idScope)) {
258 if (!is_null($this->resourceLink)) {
259 $idScope = $this->resourceLink->getConsumer()->idScope;
260 } else {
262 }
263 }
264 switch ($idScope) {
267 break;
269 $id = $this->getResourceLink()->getKey();
270 if ($this->resourceLink->ltiContextId) {
271 $id .= ToolProvider::ID_SCOPE_SEPARATOR . $this->resourceLink->ltiContextId;
272 }
274 break;
276 $id = $this->getResourceLink()->getKey();
277 if ($this->resourceLink->ltiResourceLinkId) {
278 $id .= ToolProvider::ID_SCOPE_SEPARATOR . $this->resourceLink->ltiResourceLinkId;
279 }
281 break;
282 default:
284 break;
285 }
286
287 return $id;
288
289 }
const ID_SCOPE_SEPARATOR
Character used to separate each element of an ID.
const ID_SCOPE_ID_ONLY
Use ID value only.
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.
const ID_SCOPE_RESOURCE
Prefix the ID with the consumer key and resource ID.
getResourceLink()
Get resource link.
Definition: User.php:188

References IMSGlobal\LTI\ToolProvider\User\$id, IMSGlobal\LTI\ToolProvider\User\$ltiUserId, IMSGlobal\LTI\ToolProvider\User\getResourceLink(), IMSGlobal\LTI\ToolProvider\ToolProvider\ID_SCOPE_CONTEXT, IMSGlobal\LTI\ToolProvider\ToolProvider\ID_SCOPE_GLOBAL, IMSGlobal\LTI\ToolProvider\ToolProvider\ID_SCOPE_ID_ONLY, IMSGlobal\LTI\ToolProvider\ToolProvider\ID_SCOPE_RESOURCE, and IMSGlobal\LTI\ToolProvider\ToolProvider\ID_SCOPE_SEPARATOR.

Referenced by IMSGlobal\LTI\ToolProvider\User\setEmail().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getRecordId()

IMSGlobal\LTI\ToolProvider\User::getRecordId ( )

Get record ID of user.

Returns
int Record ID of user

Definition at line 204 of file User.php.

205 {
206
207 return $this->id;
208
209 }

References IMSGlobal\LTI\ToolProvider\User\$id.

◆ getResourceLink()

IMSGlobal\LTI\ToolProvider\User::getResourceLink ( )

Get resource link.

Returns
ResourceLink Resource link object

Definition at line 188 of file User.php.

189 {
190
191 if (is_null($this->resourceLink) && !is_null($this->resourceLinkId)) {
192 $this->resourceLink = ResourceLink::fromRecordId($this->resourceLinkId, $this->getDataConnector());
193 }
194
195 return $this->resourceLink;
196
197 }

References IMSGlobal\LTI\ToolProvider\User\$resourceLink, IMSGlobal\LTI\ToolProvider\ResourceLink\fromRecordId(), and IMSGlobal\LTI\ToolProvider\User\getDataConnector().

Referenced by IMSGlobal\LTI\ToolProvider\User\getId().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasRole()

IMSGlobal\LTI\ToolProvider\User::hasRole (   $role)
private

Check whether the user has a specified role name.

Parameters
string$roleName of role
Returns
boolean True if the user has the specified role

Definition at line 442 of file User.php.

442 {
443
444 if (substr($role, 0, 4) !== 'urn:')
445 {
446 $role = 'urn:lti:role:ims/lis/' . $role;
447 }
448
449 return in_array($role, $this->roles);
450
451 }

Referenced by IMSGlobal\LTI\ToolProvider\User\isAdmin(), IMSGlobal\LTI\ToolProvider\User\isLearner(), and IMSGlobal\LTI\ToolProvider\User\isStaff().

+ Here is the caller graph for this function:

◆ initialise()

IMSGlobal\LTI\ToolProvider\User::initialise ( )

Initialise the user.

Pseudonym for initialize().

Definition at line 144 of file User.php.

145 {
146
147 $this->initialize();
148
149 }

References IMSGlobal\LTI\ToolProvider\User\initialize().

+ Here is the call graph for this function:

◆ initialize()

IMSGlobal\LTI\ToolProvider\User::initialize ( )

Initialise the user.

Definition at line 123 of file User.php.

124 {
125
126 $this->firstname = '';
127 $this->lastname = '';
128 $this->fullname = '';
129 $this->email = '';
130 $this->image = '';
131 $this->roles = array();
132 $this->groups = array();
133 $this->ltiResultSourcedId = null;
134 $this->created = null;
135 $this->updated = null;
136
137 }

Referenced by IMSGlobal\LTI\ToolProvider\User\__construct(), IMSGlobal\LTI\ToolProvider\User\initialise(), and IMSGlobal\LTI\ToolProvider\User\load().

+ Here is the caller graph for this function:

◆ isAdmin()

IMSGlobal\LTI\ToolProvider\User::isAdmin ( )

Check if the user is an administrator (at any of the system, institution or context levels).

Returns
boolean True if the user has a role of administrator

Definition at line 355 of file User.php.

356 {
357
358 return $this->hasRole('Administrator') || $this->hasRole('urn:lti:sysrole:ims/lis/SysAdmin') ||
359 $this->hasRole('urn:lti:sysrole:ims/lis/Administrator') || $this->hasRole('urn:lti:instrole:ims/lis/Administrator');
360
361 }
hasRole($role)
Check whether the user has a specified role name.
Definition: User.php:442

References IMSGlobal\LTI\ToolProvider\User\hasRole().

+ Here is the call graph for this function:

◆ isLearner()

IMSGlobal\LTI\ToolProvider\User::isLearner ( )

Check if the user is a learner.

Returns
boolean True if the user has a role of learner

Definition at line 380 of file User.php.

381 {
382
383 return $this->hasRole('Learner');
384
385 }

References IMSGlobal\LTI\ToolProvider\User\hasRole().

+ Here is the call graph for this function:

◆ isStaff()

IMSGlobal\LTI\ToolProvider\User::isStaff ( )

Check if the user is staff.

Returns
boolean True if the user has a role of instructor, contentdeveloper or teachingassistant

Definition at line 368 of file User.php.

369 {
370
371 return ($this->hasRole('Instructor') || $this->hasRole('ContentDeveloper') || $this->hasRole('TeachingAssistant'));
372
373 }

References IMSGlobal\LTI\ToolProvider\User\hasRole().

+ Here is the call graph for this function:

◆ load()

IMSGlobal\LTI\ToolProvider\User::load (   $id = null)
private

Load the user from the database.

Parameters
int$idRecord ID of user (optional, default is null)
Returns
boolean True if the user object was successfully loaded

Definition at line 460 of file User.php.

461 {
462
463 $this->initialize();
464 $this->id = $id;
466 if (!is_null($dataConnector)) {
467 return $dataConnector->loadUser($this);
468 }
469
470 return false;
471 }

References IMSGlobal\LTI\ToolProvider\User\$dataConnector, IMSGlobal\LTI\ToolProvider\User\$id, IMSGlobal\LTI\ToolProvider\User\getDataConnector(), and IMSGlobal\LTI\ToolProvider\User\initialize().

+ Here is the call graph for this function:

◆ save()

IMSGlobal\LTI\ToolProvider\User::save ( )

Save the user to the database.

Returns
boolean True if the user object was successfully saved

Definition at line 156 of file User.php.

157 {
158
159 if (!empty($this->ltiResultSourcedId) && !is_null($this->resourceLinkId)) {
160 $ok = $this->getDataConnector()->saveUser($this);
161 } else {
162 $ok = true;
163 }
164
165 return $ok;
166
167 }

References $ok, and IMSGlobal\LTI\ToolProvider\User\getDataConnector().

+ Here is the call graph for this function:

◆ setEmail()

IMSGlobal\LTI\ToolProvider\User::setEmail (   $email,
  $defaultEmail = null 
)

Set the user's email address.

Parameters
string$emailEmail address value
string$defaultEmailValue to use if no email is provided (optional, default is none)

Definition at line 334 of file User.php.

335 {
336
337 if (!empty($email)) {
338 $this->email = $email;
339 } else if (!empty($defaultEmail)) {
340 $this->email = $defaultEmail;
341 if (substr($this->email, 0, 1) === '@') {
342 $this->email = $this->getId() . $this->email;
343 }
344 } else {
345 $this->email = '';
346 }
347
348 }
getId($idScope=null)
Get the user ID (which may be a compound of the tool consumer and resource link IDs).
Definition: User.php:254
$email
User's email address.
Definition: User.php:41

References IMSGlobal\LTI\ToolProvider\User\$email, and IMSGlobal\LTI\ToolProvider\User\getId().

+ Here is the call graph for this function:

◆ setNames()

IMSGlobal\LTI\ToolProvider\User::setNames (   $firstname,
  $lastname,
  $fullname 
)

Set the user's name.

Parameters
string$firstnameUser's first name.
string$lastnameUser's last name.
string$fullnameUser's full name.

Definition at line 298 of file User.php.

299 {
300
301 $names = array(0 => '', 1 => '');
302 if (!empty($fullname)) {
303 $this->fullname = trim($fullname);
304 $names = preg_split("/[\s]+/", $this->fullname, 2);
305 }
306 if (!empty($firstname)) {
307 $this->firstname = trim($firstname);
308 $names[0] = $this->firstname;
309 } else if (!empty($names[0])) {
310 $this->firstname = $names[0];
311 } else {
312 $this->firstname = 'User';
313 }
314 if (!empty($lastname)) {
315 $this->lastname = trim($lastname);
316 $names[1] = $this->lastname;
317 } else if (!empty($names[1])) {
318 $this->lastname = $names[1];
319 } else {
320 $this->lastname = $this->ltiUserId;
321 }
322 if (empty($this->fullname)) {
323 $this->fullname = "{$this->firstname} {$this->lastname}";
324 }
325
326 }
$fullname
User's fullname.
Definition: User.php:35
$lastname
User's last name (surname or family name).
Definition: User.php:29
$firstname
User's first name.
Definition: User.php:23

References IMSGlobal\LTI\ToolProvider\User\$firstname, IMSGlobal\LTI\ToolProvider\User\$fullname, IMSGlobal\LTI\ToolProvider\User\$lastname, and IMSGlobal\LTI\ToolProvider\User\$ltiUserId.

◆ setRecordId()

IMSGlobal\LTI\ToolProvider\User::setRecordId (   $id)

Set record ID of user.

Parameters
int$idRecord ID of user

Definition at line 216 of file User.php.

217 {
218
219 $this->id = $id;
220
221 }

References IMSGlobal\LTI\ToolProvider\User\$id.

◆ setResourceLinkId()

IMSGlobal\LTI\ToolProvider\User::setResourceLinkId (   $resourceLinkId)

Set resource link ID of user.

Parameters
int$resourceLinkIdResource link ID of user

Definition at line 228 of file User.php.

229 {
230
231 $this->resourceLinkId = $resourceLinkId;
232
233 }
$resourceLinkId
Resource link record ID.
Definition: User.php:90

References IMSGlobal\LTI\ToolProvider\User\$resourceLinkId.

Field Documentation

◆ $created

object IMSGlobal\LTI\ToolProvider\User::$created = null

Date/time the record was created.

Definition at line 71 of file User.php.

◆ $dataConnector

mixed IMSGlobal\LTI\ToolProvider\User::$dataConnector = null
private

◆ $email

string IMSGlobal\LTI\ToolProvider\User::$email = ''

User's email address.

Definition at line 41 of file User.php.

Referenced by IMSGlobal\LTI\ToolProvider\User\setEmail().

◆ $firstname

string IMSGlobal\LTI\ToolProvider\User::$firstname = ''

User's first name.

Definition at line 23 of file User.php.

Referenced by IMSGlobal\LTI\ToolProvider\User\setNames().

◆ $fullname

string IMSGlobal\LTI\ToolProvider\User::$fullname = ''

User's fullname.

Definition at line 35 of file User.php.

Referenced by IMSGlobal\LTI\ToolProvider\User\setNames().

◆ $groups

array IMSGlobal\LTI\ToolProvider\User::$groups = array()

Groups for user.

Definition at line 59 of file User.php.

◆ $id

◆ $image

string IMSGlobal\LTI\ToolProvider\User::$image = ''

User's image URI.

Definition at line 47 of file User.php.

◆ $lastname

string IMSGlobal\LTI\ToolProvider\User::$lastname = ''

User's last name (surname or family name).

Definition at line 29 of file User.php.

Referenced by IMSGlobal\LTI\ToolProvider\User\setNames().

◆ $ltiResultSourcedId

string IMSGlobal\LTI\ToolProvider\User::$ltiResultSourcedId = null

User's result sourcedid.

Definition at line 65 of file User.php.

◆ $ltiUserId

string IMSGlobal\LTI\ToolProvider\User::$ltiUserId = null

user ID as supplied in the last connection request.

Definition at line 102 of file User.php.

Referenced by IMSGlobal\LTI\ToolProvider\User\fromResourceLink(), IMSGlobal\LTI\ToolProvider\User\getId(), and IMSGlobal\LTI\ToolProvider\User\setNames().

◆ $resourceLink

ResourceLink IMSGlobal\LTI\ToolProvider\User::$resourceLink = null
private

Resource link object.

Definition at line 84 of file User.php.

Referenced by IMSGlobal\LTI\ToolProvider\User\fromResourceLink(), and IMSGlobal\LTI\ToolProvider\User\getResourceLink().

◆ $resourceLinkId

int IMSGlobal\LTI\ToolProvider\User::$resourceLinkId = null
private

Resource link record ID.

Definition at line 90 of file User.php.

Referenced by IMSGlobal\LTI\ToolProvider\User\setResourceLinkId().

◆ $roles

array IMSGlobal\LTI\ToolProvider\User::$roles = array()

Roles for user.

Definition at line 53 of file User.php.

◆ $updated

object IMSGlobal\LTI\ToolProvider\User::$updated = null

Date/time the record was last updated.

Definition at line 77 of file User.php.


The documentation for this class was generated from the following file: