Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 401 and 402] [Versions 401 and 403]

(no description)

File Size: 473 lines (10 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

User:: (20 methods):
  __construct()
  initialize()
  initialise()
  save()
  delete()
  getResourceLink()
  getRecordId()
  setRecordId()
  setResourceLinkId()
  getDataConnector()
  getId()
  setNames()
  setEmail()
  isAdmin()
  isStaff()
  isLearner()
  fromRecordId()
  fromResourceLink()
  hasRole()
  load()


Class: User  - X-Ref

Class to represent a tool consumer user

__construct()   X-Ref
Class constructor.


initialize()   X-Ref
Initialise the user.


initialise()   X-Ref
Initialise the user.

Pseudonym for initialize().

save()   X-Ref
Save the user to the database.

return: boolean True if the user object was successfully saved

delete()   X-Ref
Delete the user from the database.

return: boolean True if the user object was successfully deleted

getResourceLink()   X-Ref
Get resource link.

return: ResourceLink Resource link object

getRecordId()   X-Ref
Get record ID of user.

return: int Record ID of user

setRecordId($id)   X-Ref
Set record ID of user.

param: int $id  Record ID of user

setResourceLinkId($resourceLinkId)   X-Ref
Set resource link ID of user.

param: int $resourceLinkId  Resource link ID of user

getDataConnector()   X-Ref
Get the data connector.

return: mixed Data connector object or string

getId($idScope = null)   X-Ref
Get the user ID (which may be a compound of the tool consumer and resource link IDs).

param: int $idScope Scope to use for user ID (optional, default is null for consumer default setting)
return: string User ID value

setNames($firstname, $lastname, $fullname)   X-Ref
Set the user's name.

param: string $firstname User's first name.
param: string $lastname User's last name.
param: string $fullname User's full name.

setEmail($email, $defaultEmail = null)   X-Ref
Set the user's email address.

param: string $email        Email address value
param: string $defaultEmail Value to use if no email is provided (optional, default is none)

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

return: boolean True if the user has a role of administrator

isStaff()   X-Ref
Check if the user is staff.

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

isLearner()   X-Ref
Check if the user is a learner.

return: boolean True if the user has a role of learner

fromRecordId($id, $dataConnector)   X-Ref
Load the user from the database.

param: int $id     Record ID of user
param: DataConnector   $dataConnector    Database connection object
return: User  User object

fromResourceLink($resourceLink, $ltiUserId)   X-Ref
Class constructor from resource link.

param: ResourceLink $resourceLink Resource_Link object
param: string $ltiUserId User ID value
return: User

hasRole($role)   X-Ref
Check whether the user has a specified role name.

param: string $role Name of role
return: boolean True if the user has the specified role

load($id = null)   X-Ref
Load the user from the database.

param: int $id     Record ID of user (optional, default is null)
return: boolean True if the user object was successfully loaded