ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
ILIAS\LTI\ToolProvider\User Class Reference

Class to represent a platform user. More...

+ Inheritance diagram for ILIAS\LTI\ToolProvider\User:
+ Collaboration diagram for ILIAS\LTI\ToolProvider\User:

Public Member Functions

 __construct ()
 Class constructor. More...
 
 initialize ()
 Initialise the user. More...
 
 initialise ()
 Initialise the user. More...
 
 setNames (string $firstname, string $lastname, string $fullname)
 Set the user's name. More...
 
 setEmail (string $email, string $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...
 

Data Fields

string $firstname = ''
 User's first name. More...
 
string $lastname = ''
 User's last name (surname or family name). More...
 
string $fullname = ''
 User's fullname. More...
 
string $sourcedId = null
 User's sourcedId. More...
 
string $username = null
 User's username. More...
 
string $email = ''
 User's email address. More...
 
string $image = ''
 User's image URI. More...
 
array $roles = array()
 Roles for user. More...
 
array $groups = array()
 Groups for user. More...
 
string $ltiUserId = null
 user ID as supplied in the last connection request. More...
 

Static Public Attributes

static bool $allowEmptyName = false
 Allow user name field to be empty? More...
 

Private Member Functions

 hasRole (string $role)
 Check whether the user has a specified role name. More...
 

Detailed Description

Class to represent a platform user.

Author
Stephen P Vickers steph.nosp@m.en@s.nosp@m.pvsof.nosp@m.twar.nosp@m.eprod.nosp@m.ucts.nosp@m..com

Definition at line 30 of file User.php.

Constructor & Destructor Documentation

◆ __construct()

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

Class constructor.

Definition at line 112 of file User.php.

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

113  {
114  $this->initialize();
115  }
initialize()
Initialise the user.
Definition: User.php:120
+ Here is the call graph for this function:

Member Function Documentation

◆ hasRole()

ILIAS\LTI\ToolProvider\User::hasRole ( string  $role)
private

Check whether the user has a specified role name.

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

Definition at line 244 of file User.php.

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

244  : bool
245  {
246  $ok = in_array($role, $this->roles);
247  if (!$ok && (strpos($role, 'urn:') !== 0) && (strpos($role, 'http://') !== 0) && (strpos($role, 'https://') !== 0)) {
248  $role = "urn:lti:role:ims/lis/{$role}";
249  $ok = in_array($role, $this->roles);
250  }
251  if (!$ok) {
252  $role2 = null;
253  $role3 = null;
254  if (strpos($role, 'urn:') === 0) {
255  if (strpos($role, 'urn:lti:role:ims/lis/') === 0) {
256  $role2 = 'http://purl.imsglobal.org/vocab/lis/v2/membership#' . substr($role, 21);
257  } elseif (strpos($role, 'urn:lti:instrole:ims/lis/') === 0) {
258  $role2 = 'http://purl.imsglobal.org/vocab/lis/v2/person#' . substr($role, 25);
259  $role3 = 'http://purl.imsglobal.org/vocab/lis/v2/institution/person#' . substr($role, 25);
260  } elseif (strpos($role, 'urn:lti:sysrole:ims/lis/') === 0) {
261  $role2 = 'http://purl.imsglobal.org/vocab/lis/v2/person#' . substr($role, 24);
262  $role3 = 'http://purl.imsglobal.org/vocab/lis/v2/system/person#' . substr($role, 24);
263  }
264  } elseif (strpos($role, 'http://purl.imsglobal.org/vocab/lis/v2/') === 0) {
265  if (strpos($role, 'http://purl.imsglobal.org/vocab/lis/v2/membership#') === 0) {
266  $role2 = 'urn:lti:role:ims/lis/' . substr($role, 50);
267  } elseif (strpos($role, 'http://purl.imsglobal.org/vocab/lis/v2/person#') === 0) {
268  $role2 = 'urn:lti:instrole:ims/lis/' . substr($role, 46);
269  $role3 = 'urn:lti:sysrole:ims/lis/' . substr($role, 46);
270  } elseif (strpos($role, 'http://purl.imsglobal.org/vocab/lis/v2/institution/person#') === 0) {
271  $role2 = 'urn:lti:instrole:ims/lis/' . substr($role, 58);
272  $role3 = 'http://purl.imsglobal.org/vocab/lis/v2/person#' . substr($role, 58);
273  } elseif (strpos($role, 'http://purl.imsglobal.org/vocab/lis/v2/system/person#') === 0) {
274  $role2 = 'urn:lti:sysrole:ims/lis/' . substr($role, 53);
275  $role3 = 'http://purl.imsglobal.org/vocab/lis/v2/person#' . substr($role, 53);
276  }
277  }
278  if (!empty($role2)) {
279  $ok = in_array($role2, $this->roles);
280  if (!$ok && !empty($role3)) {
281  $ok = in_array($role3, $this->roles);
282  }
283  }
284  }
285 
286  return $ok;
287  }
+ Here is the caller graph for this function:

◆ initialise()

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

Initialise the user.

Synonym for initialize().

Definition at line 138 of file User.php.

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

139  {
140  $this->initialize();
141  }
initialize()
Initialise the user.
Definition: User.php:120
+ Here is the call graph for this function:

◆ initialize()

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

Initialise the user.

Definition at line 120 of file User.php.

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

121  {
122  $this->firstname = '';
123  $this->lastname = '';
124  $this->fullname = '';
125  $this->sourcedId = null;
126  $this->username = null;
127  $this->email = '';
128  $this->image = '';
129  $this->roles = array();
130  $this->groups = array();
131  }
+ Here is the caller graph for this function:

◆ isAdmin()

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

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

Returns
bool True if the user has a role of administrator

Definition at line 209 of file User.php.

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

209  : bool
210  {
211  return $this->hasRole('Administrator') || $this->hasRole('urn:lti:sysrole:ims/lis/SysAdmin') ||
212  $this->hasRole('urn:lti:sysrole:ims/lis/Administrator') || $this->hasRole('urn:lti:instrole:ims/lis/Administrator');
213  }
hasRole(string $role)
Check whether the user has a specified role name.
Definition: User.php:244
+ Here is the call graph for this function:

◆ isLearner()

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

Check if the user is a learner.

Returns
bool True if the user has a role of learner

Definition at line 230 of file User.php.

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

230  : bool
231  {
232  return $this->hasRole('Learner');
233  }
hasRole(string $role)
Check whether the user has a specified role name.
Definition: User.php:244
+ Here is the call graph for this function:

◆ isStaff()

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

Check if the user is staff.

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

Definition at line 220 of file User.php.

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

220  : bool
221  {
222  return ($this->hasRole('Instructor') || $this->hasRole('ContentDeveloper') || $this->hasRole('TeachingAssistant'));
223  }
hasRole(string $role)
Check whether the user has a specified role name.
Definition: User.php:244
+ Here is the call graph for this function:

◆ setEmail()

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

Set the user's email address.

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

Definition at line 186 of file User.php.

References ILIAS\LTI\ToolProvider\User\$email.

187  {
188  if (!empty($email)) {
189  $this->email = $email;
190  } elseif (!empty($defaultEmail)) {
191  $this->email = $defaultEmail;
192  if (substr($this->email, 0, 1) === '@') {
193  if (!empty($this->username)) {
194  $this->email = "{$this->username}{$this->email}";
195  } else {
196  $this->email = "{$this->ltiUserId}{$this->email}";
197  }
198  }
199  } else {
200  $this->email = '';
201  }
202  }
string $email
User's email address.
Definition: User.php:79

◆ setNames()

ILIAS\LTI\ToolProvider\User::setNames ( string  $firstname,
string  $lastname,
string  $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 149 of file User.php.

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

150  {
151  $names = array(0 => '', 1 => '');
152  if (!empty($fullname)) {
153  $this->fullname = trim($fullname);
154  $names = preg_split("/[\s]+/", $this->fullname, 2);
155  }
156  if (!empty($firstname)) {
157  $this->firstname = trim($firstname);
158  $names[0] = $this->firstname;
159  } elseif (!empty($names[0])) {
160  $this->firstname = $names[0];
161  } elseif (!static::$allowEmptyName) {
162  $this->firstname = 'User';
163  } else {
164  $this->firstname = '';
165  }
166  if (!empty($lastname)) {
167  $this->lastname = trim($lastname);
168  $names[1] = $this->lastname;
169  } elseif (!empty($names[1])) {
170  $this->lastname = $names[1];
171  } elseif (!static::$allowEmptyName) {
172  $this->lastname = $this->ltiUserId;
173  } else {
174  $this->lastname = '';
175  }
176  if (empty($this->fullname) && (!empty($this->firstname) || !empty($this->lastname))) {
177  $this->fullname = trim("{$this->firstname} {$this->lastname}");
178  }
179  }
string $firstname
User's first name.
Definition: User.php:37
string $lastname
User's last name (surname or family name).
Definition: User.php:44
string $ltiUserId
user ID as supplied in the last connection request.
Definition: User.php:107
string $fullname
User's fullname.
Definition: User.php:51

Field Documentation

◆ $allowEmptyName

bool ILIAS\LTI\ToolProvider\User::$allowEmptyName = false
static

Allow user name field to be empty?

Definition at line 58 of file User.php.

◆ $email

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

User's email address.

Definition at line 79 of file User.php.

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

◆ $firstname

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

User's first name.

Definition at line 37 of file User.php.

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

◆ $fullname

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

User's fullname.

Definition at line 51 of file User.php.

◆ $groups

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

Groups for user.

Definition at line 100 of file User.php.

◆ $image

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

User's image URI.

Definition at line 86 of file User.php.

◆ $lastname

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

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

Definition at line 44 of file User.php.

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

◆ $ltiUserId

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

user ID as supplied in the last connection request.

Definition at line 107 of file User.php.

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

◆ $roles

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

Roles for user.

Definition at line 93 of file User.php.

◆ $sourcedId

string ILIAS\LTI\ToolProvider\User::$sourcedId = null

User's sourcedId.

Definition at line 65 of file User.php.

◆ $username

string ILIAS\LTI\ToolProvider\User::$username = null

User's username.

Definition at line 72 of file User.php.


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