Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

(no description)

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

Defines 1 class


Class: user  - X-Ref

Class user, instances of which represent a specific lti user in the tool.

A user is always associated with a resource, as lti users cannot exist without a tool-published-resource. A user will
always come from either:
- a resource link launch or
- a membership sync
Both of which required a published resource.

Additionally, a user may be associated with a given resource_link instance, to signify that the user originated from
that resource_link. If a user is not associated with a resource_link, such as when creating a user during a member
sync, that param is nullable. This can be achieved via the factory method user::create_from_resource_link() or set
after instantiation via the user::set_resource_link_id() method.

__construct(int $resourceid, int $userid, int $deploymentid, string $sourceid,string $lang, string $city, string $country,string $institution, string $timezone, ?int $maildisplay, ?float $lastgrade, ?int $lastaccess,?int $resourcelinkid = null, ?int $id = null)   X-Ref
Private constructor.

param: int $resourceid the id of the published resource to which this user belongs.
param: int $userid the id of the Moodle user to which this LTI user relates.
param: int $deploymentid the local id of the deployment instance to which this user belongs.
param: string $sourceid the id of the user in the platform site.
param: string $lang the user's language code.
param: string $city the user's city.
param: string $country the user's country.
param: string $institution the user's institution.
param: string $timezone the user's timezone.
param: int|null $maildisplay the user's maildisplay, or null to select defaults.
param: float|null $lastgrade the user's last grade value.
param: int|null $lastaccess the user's last access time, or null if they haven't accessed the resource.
param: int|null $resourcelinkid the id of the resource link to link to the user, or null if not applicable.
param: int|null $id the id of this object instance, or null if it's a not-yet-persisted object.

create_from_resource_link(int $resourcelinkid, int $resourceid, int $userid,int $deploymentid, string $sourceid, string $lang, string $timezone,string $city = '', string $country = '', string $institution = '',?int $maildisplay = null)   X-Ref
Factory method for creating a user instance associated with a given resource_link instance.

param: int $resourcelinkid the local id of the resource link instance to link to the user.
param: int $resourceid the id of the published resource to which this user belongs.
param: int $userid the id of the Moodle user to which this LTI user relates.
param: int $deploymentid the local id of the deployment instance to which this user belongs.
param: string $sourceid the id of the user in the platform site.
param: string $lang the user's language code.
param: string $timezone the user's timezone.
param: string $city the user's city.
param: string $country the user's country.
param: string $institution the user's institution.
param: int|null $maildisplay the user's maildisplay, or null to select defaults.
return: user the user instance.

create(int $resourceid, int $userid, int $deploymentid, string $sourceid,string $lang, string $timezone, string $city = '',string $country = '', string $institution = '', ?int $maildisplay = null, ?float $lastgrade = null,?int $lastaccess = null, ?int $resourcelinkid = null, int $id = null)   X-Ref
Factory method for creating a user.

param: int $resourceid the id of the published resource to which this user belongs.
param: int $userid the id of the Moodle user to which this LTI user relates.
param: int $deploymentid the local id of the deployment instance to which this user belongs.
param: string $sourceid the id of the user in the platform site.
param: string $lang the user's language code.
param: string $timezone the user's timezone.
param: string $city the user's city.
param: string $country the user's country.
param: string $institution the user's institution.
param: int|null $maildisplay the user's maildisplay, or null to select defaults.
param: float|null $lastgrade the user's last grade value.
param: int|null $lastaccess the user's last access time, or null if they haven't accessed the resource.
param: int|null $resourcelinkid the local id of the resource link instance associated with the user.
param: int|null $id the id of this lti user instance, or null if it's a not-yet-persisted object.
return: user the user instance.

get_id()   X-Ref
Get the id of this user instance.

return: int|null the object id, or null if not yet persisted.

get_resourcelinkid()   X-Ref
Get the id of the resource_link instance to which this user is associated.

return: int|null the object id, or null if the user isn't associated with one.

set_resourcelinkid(int $resourcelinkid)   X-Ref
Associate this user with the given resource_link instance, denoting that this user launched from the instance.

param: int $resourcelinkid the id of the resource_link instance.

get_resourceid()   X-Ref
Get the id of the published resource to which this user is associated.

return: int the resource id.

get_deploymentid()   X-Ref
Get the id of the deployment instance to which this user belongs.

return: int id of the deployment instance.

get_sourceid()   X-Ref
Get the id of the user in the platform.

return: string the source id.

get_localid()   X-Ref
Get the id of the user in the tool.

return: int|null the id, or null if the object instance hasn't yet been persisted.

get_city()   X-Ref
Get the user's city.

return: string the city.

set_city(string $city)   X-Ref
Set the user's city.

param: string $city the city string.

get_country()   X-Ref
Get the user's country code.

return: string the country code.

set_country(string $countrycode)   X-Ref
Set the user's country.

param: string $countrycode the 2 digit country code representing the country, or '' to denote none.

get_institution()   X-Ref
Get the instituation of the user.

return: string the institution.

set_institution(string $institution)   X-Ref
Set the user's institution.

param: string $institution the name of the institution.

get_timezone()   X-Ref
Get the timezone of the user.

return: string the user timezone.

set_timezone(string $timezone)   X-Ref
Set the user's timezone, or set '99' to specify server timezone.

param: string $timezone the timezone string, or '99' to use server timezone.

get_maildisplay()   X-Ref
Get the maildisplay of the user.

return: int the maildisplay.

set_maildisplay(int $maildisplay)   X-Ref
Set the user's mail display preference from a range of supported options.

0 - hide from non privileged users
1 - allow everyone to see
2 - allow only course participants to see

param: int $maildisplay the maildisplay preference to set.

get_lang()   X-Ref
Get the lang code of the user.

return: string the user's language code.

set_lang(string $langcode)   X-Ref
Set the user's language.

param: string $langcode the language code representing the user's language.

get_lastgrade()   X-Ref
Get the last grade value for this user.

return: float the float grade.

set_lastgrade(float $lastgrade)   X-Ref
Set the last grade for the user.

param: float $lastgrade the last grade the user received.

get_lastaccess()   X-Ref
Get the last access timestamp for this user.

return: int|null the last access timestampt, or null if the user hasn't accessed the resource.

set_lastaccess(int $time)   X-Ref
Set the last access time for the user.

param: int $time unix timestamp representing the last time the user accessed the published resource.