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.

LTI enrolment plugin helper.

Copyright: 2016 Mark Nelson <markn@moodle.com>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 665 lines (23 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: helper  - X-Ref

LTI enrolment plugin helper class.

create_username($consumerkey, $ltiuserid)   X-Ref
Creates a unique username.

param: string $consumerkey Consumer key
param: string $ltiuserid External tool user id
return: string The new username

assign_user_tool_data($tool, $user)   X-Ref
Adds default values for the user object based on the tool provided.

param: \stdClass $tool
param: \stdClass $user
return: \stdClass The $user class with added default values

user_match($newuser, $olduser)   X-Ref
Compares two users.

param: \stdClass $newuser The new user
param: \stdClass $olduser The old user
return: bool True if both users are the same

update_user_profile_image($userid, $url)   X-Ref
Updates the users profile image.

param: int $userid the id of the user
param: string $url the url of the image
return: bool|string true if successful, else a string explaining why it failed

enrol_user($tool, $userid)   X-Ref
Enrol a user in a course.

param: \stdclass $tool The tool object (retrieved using self::get_lti_tool() or self::get_lti_tools())
param: int $userid The user id
return: bool|string returns true if successful, else an error code

get_lti_tool($toolid)   X-Ref
Returns the LTI tool.

param: int $toolid
return: \stdClass the tool

get_lti_tools($params = array()   X-Ref
Returns the LTI tools requested.

param: array $params The list of SQL params (eg. array('columnname' => value, 'columnname2' => value)).
param: int $limitfrom return a subset of records, starting at this point (optional).
param: int $limitnum return a subset comprising this many records in total
return: array of tools

count_lti_tools($params = array()   X-Ref
Returns the number of LTI tools.

param: array $params The list of SQL params (eg. array('columnname' => value, 'columnname2' => value)).
return: int The number of tools

create_service_body($source, $grade)   X-Ref
Create a IMS POX body request for sync grades.

param: string $source Sourceid required for the request
param: float $grade User final grade
return: string

get_launch_url($toolid)   X-Ref
Returns the url to launch the lti tool.

param: int $toolid the id of the shared tool
return: \moodle_url the url to launch the tool

get_name($tool)   X-Ref
Returns the name of the lti enrolment instance, or the name of the course/module being shared.

param: \stdClass $tool The lti tool
return: string The name of the tool

get_description($tool)   X-Ref
Returns a description of the course or module that this lti instance points to.

param: \stdClass $tool The lti tool
return: string A description of the tool

get_icon($tool)   X-Ref
Returns the icon of the tool.

param: \stdClass $tool The lti tool
return: \moodle_url A url to the icon of the tool

get_cartridge_url($tool)   X-Ref
Returns the url to the cartridge representing the tool.

If you have slash arguments enabled, this will be a nice url ending in cartridge.xml.
If not it will be a php page with some parameters passed.

param: \stdClass $tool The lti tool
return: string The url to the cartridge representing the tool

get_proxy_url($tool)   X-Ref
Returns the url to the tool proxy registration url.

If you have slash arguments enabled, this will be a nice url ending in cartridge.xml.
If not it will be a php page with some parameters passed.

param: \stdClass $tool The lti tool
return: string The url to the cartridge representing the tool

generate_cartridge_token($toolid)   X-Ref
Returns a unique hash for this site and this enrolment instance.

Used to verify that the link to the cartridge has not just been guessed.

param: int $toolid The id of the shared tool
return: string MD5 hash of combined site ID and enrolment instance ID.

generate_proxy_token($toolid)   X-Ref
Returns a unique hash for this site and this enrolment instance.

Used to verify that the link to the proxy has not just been guessed.

param: int $toolid The id of the shared tool
return: string MD5 hash of combined site ID and enrolment instance ID.

verify_cartridge_token($toolid, $token)   X-Ref
Verifies that the given token matches the cartridge token of the given shared tool.

param: int $toolid The id of the shared tool
param: string $token hash for this site and this enrolment instance
return: boolean True if the token matches, false if it does not

verify_proxy_token($toolid, $token)   X-Ref
Verifies that the given token matches the proxy token of the given shared tool.

param: int $toolid The id of the shared tool
param: string $token hash for this site and this enrolment instance
return: boolean True if the token matches, false if it does not

get_cartridge_parameters($toolid)   X-Ref
Returns the parameters of the cartridge as an associative array of partial xpath.

param: int $toolid The id of the shared tool
return: array Recursive associative array with partial xpath to be concatenated into an xpath expression

set_xpath($xpath, $parameters, $prefix = '')   X-Ref
Traverses a recursive associative array, setting the properties of the corresponding
xpath element.

param: \DOMXPath $xpath The xpath with the xml to modify
param: array $parameters The array of xpaths to search through
param: string $prefix The current xpath prefix (gets longer the deeper into the array you go)
return: void

create_cartridge($toolid)   X-Ref
Create an IMS cartridge for the tool.

param: int $toolid The id of the shared tool
return: string representing the generated cartridge