Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

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.

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

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

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

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

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

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

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

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

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

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

return: \stdClass the tool
param: int $toolid

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

return: array of tools
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

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

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

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

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

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

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

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

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

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

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

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

return: \moodle_url A url to the icon of the tool
param: \stdClass $tool The lti 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.

return: string The url to the cartridge representing the tool
param: \stdClass $tool The lti 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.

return: string The url to the cartridge representing the tool
param: \stdClass $tool The lti 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.

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

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.

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

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

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

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

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

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

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

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

return: void
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)

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

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