Differences Between: [Versions 310 and 311] [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403] [Versions 39 and 311]
This file contains the library of functions and constants for the lti module
Author: | Marc Alier |
Author: | Jordi Piguillem |
Author: | Nikolas Galanis |
Author: | Chris Scribner |
Author: | Stephen Vickers |
Copyright: | 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis |
Copyright: | 2009 Universitat Politecnica de Catalunya http://www.upc.edu |
Copyright: | 2015 Vital Source Technologies http://vitalsource.com |
License: | http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
File Size: | 4517 lines (158 kb) |
Included or required: | 1 time |
Referenced: | 24 times |
Includes or requires: | 0 files |
lti_get_jwt_message_type_mapping() X-Ref |
Return the mapping for standard message types to JWT message_type claim. return: array |
lti_get_jwt_claim_mapping() X-Ref |
Return the mapping for standard message parameters to JWT claim. return: array |
lti_get_instance_type(object $instance) X-Ref |
Return the type of the instance, using domain matching if no explicit type is set. param: object $instance the external tool activity settings return: object|null |
lti_get_launch_data($instance, $nonce = '') X-Ref |
Return the launch data required for opening the external tool. param: stdClass $instance the external tool activity settings param: string $nonce the nonce value to use (applies to LTI 1.3 only) return: array the endpoint URL and parameters (including the signature) |
lti_launch_tool($instance) X-Ref |
Launch an external tool activity. param: stdClass $instance the external tool activity settings return: string The HTML code containing the javascript code for the launch |
lti_register($toolproxy) X-Ref |
Prepares an LTI registration request message param: object $toolproxy Tool Proxy instance object |
lti_build_registration_request($toolproxy) X-Ref |
Gets the parameters for the regirstration request param: object $toolproxy Tool Proxy instance object return: array Registration request parameters |
lti_get_organizationid($typeconfig) X-Ref |
No description |
lti_build_sourcedid($instanceid, $userid, $servicesalt, $typeid = null, $launchid = null) X-Ref |
Build source ID param: int $instanceid param: int $userid param: string $servicesalt param: null|int $typeid param: null|int $launchid return: stdClass |
lti_build_request($instance, $typeconfig, $course, $typeid = null, $islti2 = false) X-Ref |
This function builds the request that must be sent to the tool producer param: object $instance Basic LTI instance object param: array $typeconfig Basic LTI tool configuration param: object $course Course object param: int|null $typeid Basic LTI tool ID param: boolean $islti2 True if an LTI 2 tool is being launched return: array Request details |
lti_build_request_lti2($tool, $params) X-Ref |
This function builds the request that must be sent to an LTI 2 tool provider param: object $tool Basic LTI tool object param: array $params Custom launch parameters return: array Request details |
lti_build_standard_request($instance, $orgid, $islti2, $messagetype = 'basic-lti-launch-request') X-Ref |
This function builds the standard parameters for an LTI 1 or 2 request that must be sent to the tool producer param: stdClass $instance Basic LTI instance object param: string $orgid Organisation ID param: boolean $islti2 True if an LTI 2 tool is being launched param: string $messagetype The request message type. Defaults to basic-lti-launch-request if empty. return: array Request details |
lti_build_standard_message($instance, $orgid, $ltiversion, $messagetype = 'basic-lti-launch-request') X-Ref |
This function builds the standard parameters for an LTI message that must be sent to the tool producer param: stdClass $instance Basic LTI instance object param: string $orgid Organisation ID param: boolean $ltiversion LTI version to be used for tool messages param: string $messagetype The request message type. Defaults to basic-lti-launch-request if empty. return: array Message parameters |
lti_build_custom_parameters($toolproxy, $tool, $instance, $params, $customstr, $instructorcustomstr, $islti2) X-Ref |
This function builds the custom parameters param: object $toolproxy Tool proxy instance object param: object $tool Tool instance object param: object $instance Tool placement instance object param: array $params LTI launch parameters param: string $customstr Custom parameters defined for tool param: string $instructorcustomstr Custom parameters defined for this placement param: boolean $islti2 True if an LTI 2 tool is being launched return: array Custom parameters |
lti_build_content_item_selection_request($id, $course, moodle_url $returnurl, $title = '', $text = '', $mediatypes = [],$presentationtargets = [], $autocreate = false, $multiple = true,$unsigned = false, $canconfirm = false, $copyadvice = false, $nonce = '') X-Ref |
Builds a standard LTI Content-Item selection request. param: int $id The tool type ID. param: stdClass $course The course object. param: moodle_url $returnurl The return URL in the tool consumer (TC) that the tool provider (TP) param: string $title The tool's title, if available. param: string $text The text to display to represent the content item. This value may be a long description of the content item. param: array $mediatypes Array of MIME types types supported by the TC. If empty, the TC will support ltilink by default. param: array $presentationtargets Array of ways in which the selected content item(s) can be requested to be opened param: bool $autocreate Indicates whether any content items returned by the TP would be automatically persisted without param: bool $multiple Indicates whether the user should be permitted to select more than one item. False by default. param: bool $unsigned Indicates whether the TC is willing to accept an unsigned return message, or not. param: bool $canconfirm Flag for can_confirm parameter. False by default. param: bool $copyadvice Indicates whether the TC is able and willing to make a local copy of a content item. False by default. param: string $nonce return: stdClass The object containing the signed request parameters and the URL to the TP's Content-Item selection interface. |
lti_verify_oauth_signature($typeid, $consumerkey) X-Ref |
Verifies the OAuth signature of an incoming message. param: int $typeid The tool type ID. param: string $consumerkey The consumer key. return: stdClass Tool type |
lti_verify_with_keyset($jwtparam, $keyseturl, $clientid) X-Ref |
Verifies the JWT signature using a JWK keyset. param: string $jwtparam JWT parameter value. param: string $keyseturl The tool keyseturl. param: string $clientid The tool client id. return: object The JWT's payload as a PHP object |
lti_verify_jwt_signature($typeid, $consumerkey, $jwtparam) X-Ref |
Verifies the JWT signature of an incoming message. param: int $typeid The tool type ID. param: string $consumerkey The consumer key. param: string $jwtparam JWT parameter value return: stdClass Tool type |
content_item_to_form(object $tool, object $typeconfig, object $item) X-Ref |
Converts LTI 1.1 Content Item for LTI Link to Form data. param: object $tool Tool for which the item is created for. param: object $typeconfig The tool configuration. param: object $item Item populated from JSON to be converted to Form form return: stdClass Form config for the item |
lti_tool_configuration_from_content_item($typeid, $messagetype, $ltiversion, $consumerkey, $contentitemsjson) X-Ref |
Processes the tool provider's response to the ContentItemSelectionRequest and builds the configuration data from the selected content item. This configuration data can be then used when adding a tool into the course. param: int $typeid The tool type ID. param: string $messagetype The value for the lti_message_type parameter. param: string $ltiversion The value for the lti_version parameter. param: string $consumerkey The consumer key. param: string $contentitemsjson The JSON string for the content_items parameter. return: stdClass The array of module information objects. |
lti_convert_content_items($param) X-Ref |
Converts the new Deep-Linking format for Content-Items to the old format. param: string $param JSON string representing new Deep-Linking format return: string JSON representation of content-items |
lti_get_tool_table($tools, $id) X-Ref |
No description |
lti_get_tool_proxy_table($toolproxies, $id) X-Ref |
This function builds the tab for a category of tool proxies param: object $toolproxies Tool proxy instance objects param: string $id Category ID return: string HTML for tab |
lti_get_enabled_capabilities($tool) X-Ref |
Extracts the enabled capabilities into an array, including those implicitly declared in a parameter param: object $tool Tool instance object return: array List of enabled capabilities |
lti_split_custom_parameters($toolproxy, $tool, $params, $customstr, $islti2 = false) X-Ref |
Splits the custom parameters field to the various parameters param: object $toolproxy Tool proxy instance object param: object $tool Tool instance object param: array $params LTI launch parameters param: string $customstr String containing the parameters param: boolean $islti2 True if an LTI 2 tool is being launched return: array of custom parameters |
lti_get_custom_parameters($toolproxy, $tool, $params, $parameters) X-Ref |
Adds the custom parameters to an array param: object $toolproxy Tool proxy instance object param: object $tool Tool instance object param: array $params LTI launch parameters param: array $parameters Array containing the parameters return: array Array of custom parameters |
lti_parse_custom_parameter($toolproxy, $tool, $params, $value, $islti2) X-Ref |
Parse a custom parameter to replace any substitution variables param: object $toolproxy Tool proxy instance object param: object $tool Tool instance object param: array $params LTI launch parameters param: string $value Custom parameter value param: boolean $islti2 True if an LTI 2 tool is being launched return: string Parsed value of custom parameter |
lti_calculate_custom_parameter($value) X-Ref |
Calculates the value of a custom parameter that has not been specified earlier param: string $value Custom parameter value return: string Calculated value of custom parameter |
get_course_history($course) X-Ref |
Build the history chain for this course using the course originalcourseid. param: object $course course for which the history is returned. return: array ids of the source course in ancestry order, immediate parent 1st. |
lti_map_keyname($key, $tolower = true) X-Ref |
Used for building the names of the different custom parameters param: string $key Parameter name param: bool $tolower Do we want to convert the key into lower case? return: string Processed name |
lti_get_ims_role($user, $cmid, $courseid, $islti2) X-Ref |
Gets the IMS role string for the specified user and LTI course module. param: mixed $user User object or user id param: int $cmid The course module id of the LTI activity param: int $courseid The course id of the LTI activity param: boolean $islti2 True if an LTI 2 tool is being launched return: string A role string suitable for passing with an LTI launch |
lti_get_type_config($typeid) X-Ref |
Returns configuration details for the tool param: int $typeid Basic LTI tool typeid return: array Tool Configuration |
lti_get_tools_by_url($url, $state, $courseid = null) X-Ref |
No description |
lti_get_tools_by_domain($domain, $state = null, $courseid = null) X-Ref |
No description |
lti_filter_get_types($course) X-Ref |
Returns all basicLTI tools configured by the administrator param: int $course return: array |
lti_filter_tool_types(array $tools, $state) X-Ref |
Given an array of tools, filter them based on their state param: array $tools An array of lti_types records param: int $state One of the LTI_TOOL_STATE_* constants return: array |
lti_get_lti_types_by_course($courseid, $coursevisible = null) X-Ref |
Returns all lti types visible in this course param: int $courseid The id of the course to retieve types for param: array $coursevisible options for 'coursevisible' field, return: stdClass[] All the lti types visible in the given course |
lti_get_types_for_add_instance() X-Ref |
Returns tool types for lti add instance and edit page return: array Array of lti types |
lti_get_configured_types($courseid, $sectionreturn = 0) X-Ref |
Returns a list of configured types in the given course param: int $courseid The id of the course to retieve types for param: int $sectionreturn section to return to for forming the URLs return: array Array of lti types. Each element is object with properties: name, title, icon, help, helplink, link |
lti_get_domain_from_url($url) X-Ref |
No description |
lti_get_tool_by_url_match($url, $courseid = null, $state = LTI_TOOL_STATE_CONFIGURED) X-Ref |
No description |
lti_get_url_thumbprint($url) X-Ref |
No description |
lti_get_best_tool_by_url($url, $tools, $courseid = null) X-Ref |
No description |
lti_get_shared_secrets_by_key($key) X-Ref |
No description |
lti_delete_type($id) X-Ref |
Delete a Basic LTI configuration param: int $id Configuration id |
lti_set_state_for_type($id, $state) X-Ref |
No description |
lti_get_config($ltiobject) X-Ref |
Transforms a basic LTI object to an array param: object $ltiobject Basic LTI object return: array Basic LTI configuration details |
lti_get_type_config_from_instance($id) X-Ref |
Generates some of the tool configuration based on the instance details param: int $id return: object configuration |
lti_get_type_type_config($id) X-Ref |
Generates some of the tool configuration based on the admin configuration details param: int $id return: stdClass Configuration details |
lti_prepare_type_for_save($type, $config) X-Ref |
No description |
lti_update_type($type, $config) X-Ref |
No description |
lti_add_type($type, $config) X-Ref |
No description |
lti_filter_tool_proxy_types(array $toolproxies, $state) X-Ref |
Given an array of tool proxies, filter them based on their state param: array $toolproxies An array of lti_tool_proxies records param: int $state One of the LTI_TOOL_PROXY_STATE_* constants return: array |
lti_get_tool_proxy_from_guid($toolproxyguid) X-Ref |
Get the tool proxy instance given its GUID param: string $toolproxyguid Tool proxy GUID value return: object |
lti_get_tool_proxies_from_registration_url($regurl) X-Ref |
Get the tool proxy instance given its registration URL param: string $regurl Tool proxy registration URL return: array The record of the tool proxy with this url |
lti_get_tool_proxy($id) X-Ref |
Generates some of the tool proxy configuration based on the admin configuration details param: int $id return: mixed Tool Proxy details |
lti_get_tool_proxies($orphanedonly) X-Ref |
Returns lti tool proxies. param: bool $orphanedonly Only retrieves tool proxies that have no type associated with them return: array of basicLTI types |
lti_get_tool_proxy_config($id) X-Ref |
Generates some of the tool proxy configuration based on the admin configuration details param: int $id return: mixed Tool Proxy details |
lti_add_tool_proxy($config) X-Ref |
Update the database with a tool proxy instance param: object $config Tool proxy definition return: int Record id number |
lti_update_tool_proxy($toolproxy) X-Ref |
Updates a tool proxy in the database param: object $toolproxy Tool proxy return: int Record id number |
lti_delete_tool_proxy($id) X-Ref |
Delete a Tool Proxy param: int $id Tool Proxy id |
lti_add_config($config) X-Ref |
Add a tool configuration in the database param: object $config Tool configuration return: int Record id number |
lti_update_config($config) X-Ref |
Updates a tool configuration in the database param: object $config Tool configuration return: mixed Record id number |
lti_get_tool_settings($toolproxyid, $courseid = null, $instanceid = null) X-Ref |
Gets the tool settings param: int $toolproxyid Id of tool proxy record (or tool ID if negative) param: int $courseid Id of course (null if system settings) param: int $instanceid Id of course module (null if system or context settings) return: array Array settings |
lti_set_tool_settings($settings, $toolproxyid, $courseid = null, $instanceid = null) X-Ref |
Sets the tool settings ( param: array $settings Array of settings param: int $toolproxyid Id of tool proxy record (or tool ID if negative) param: int $courseid Id of course (null if system settings) param: int $instanceid Id of course module (null if system or context settings) |
lti_sign_parameters($oldparms, $endpoint, $method, $oauthconsumerkey, $oauthconsumersecret) X-Ref |
Signs the petition to launch the external tool using OAuth param: array $oldparms Parameters to be passed for signing param: string $endpoint url of the external tool param: string $method Method for sending the parameters (e.g. POST) param: string $oauthconsumerkey param: string $oauthconsumersecret return: array|null |
lti_sign_jwt($parms, $endpoint, $oauthconsumerkey, $typeid = 0, $nonce = '') X-Ref |
Converts the message paramters to their equivalent JWT claim and signs the payload to launch the external tool using JWT param: array $parms Parameters to be passed for signing param: string $endpoint url of the external tool param: string $oauthconsumerkey param: string $typeid ID of LTI tool type param: string $nonce Nonce value to use return: array|null |
lti_convert_from_jwt($typeid, $jwtparam) X-Ref |
Verfies the JWT and converts its claims to their equivalent message parameter. param: int $typeid param: string $jwtparam JWT parameter return: array message parameters |
lti_post_launch_html($newparms, $endpoint, $debug=false) X-Ref |
Posts the launch petition HTML param: array $newparms Signed parameters param: string $endpoint URL of the external tool param: bool $debug Debug (true/false) return: string |
lti_initiate_login($courseid, $id, $instance, $config, $messagetype = 'basic-lti-launch-request', $title = '',$text = '') X-Ref |
Generate the form for initiating a login request for an LTI 1.3 message param: int $courseid Course ID param: int $id LTI instance ID param: stdClass|null $instance LTI instance param: stdClass $config Tool type configuration param: string $messagetype LTI message type param: string $title Title of content item param: string $text Description of content item return: string |
lti_build_login_request($courseid, $id, $instance, $config, $messagetype) X-Ref |
Prepares an LTI 1.3 login request param: int $courseid Course ID param: int $id LTI instance ID param: stdClass|null $instance LTI instance param: stdClass $config Tool type configuration param: string $messagetype LTI message type return: array Login request parameters |
lti_get_type($typeid) X-Ref |
No description |
lti_get_launch_container($lti, $toolconfig) X-Ref |
No description |
lti_request_is_using_ssl() X-Ref |
No description |
lti_ensure_url_is_https($url) X-Ref |
No description |
lti_should_log_request($rawbody) X-Ref |
Determines if we should try to log the request param: string $rawbody return: bool |
lti_log_request($rawbody) X-Ref |
Logs the request to a file in temp dir. param: string $rawbody |
lti_log_response($responsexml, $e = null) X-Ref |
Log an LTI response. param: string $responsexml The response XML param: Exception $e If there was an exception, pass that too |
lti_get_type_config_by_instance($instance) X-Ref |
Fetches LTI type configuration for an LTI instance param: stdClass $instance return: array Can be empty if no type is found |
lti_force_type_config_settings($instance, array $typeconfig) X-Ref |
Enforce type config settings onto the LTI instance param: stdClass $instance param: array $typeconfig |
lti_get_capabilities() X-Ref |
Initializes an array with the capabilities supported by the LTI module return: array List of capability names (without a dollar sign prefix) |
lti_get_services() X-Ref |
Initializes an array with the services supported by the LTI module return: array List of services |
lti_get_service_by_name($servicename) X-Ref |
Initializes an instance of the named service param: string $servicename Name of service return: bool|\mod_lti\local\ltiservice\service_base Service |
lti_get_service_by_resource_id($services, $resourceid) X-Ref |
Finds a service by id param: \mod_lti\local\ltiservice\service_base[] $services Array of services param: string $resourceid ID of resource return: mod_lti\local\ltiservice\service_base Service |
lti_get_permitted_service_scopes($type, $typeconfig) X-Ref |
Initializes an array with the scopes for services supported by the LTI module and authorized for this particular tool instance. param: object $type LTI tool type param: array $typeconfig LTI tool type configuration return: array List of scopes |
lti_get_contexts($json) X-Ref |
Extracts the named contexts from a tool proxy param: object $json return: array Contexts |
lti_get_fqid($contexts, $id) X-Ref |
Converts an ID to a fully-qualified ID param: array $contexts param: string $id return: string Fully-qualified ID |
get_tool_type_icon_url(stdClass $type) X-Ref |
Returns the icon for the given tool type param: stdClass $type The tool type return: string The url to the tool type's corresponding icon |
get_tool_type_edit_url(stdClass $type) X-Ref |
Returns the edit url for the given tool type param: stdClass $type The tool type return: string The url to edit the tool type |
get_tool_proxy_edit_url(stdClass $proxy) X-Ref |
Returns the edit url for the given tool proxy. param: stdClass $proxy The tool proxy return: string The url to edit the tool type |
get_tool_type_course_url(stdClass $type) X-Ref |
Returns the course url for the given tool type param: stdClass $type The tool type return: string The url to the course of the tool type, void if it is a site wide type |
get_tool_type_urls(stdClass $type) X-Ref |
Returns the icon and edit urls for the tool type and the course url if it is a course type. param: stdClass $type The tool type return: array The urls of the tool type |
get_tool_proxy_urls(stdClass $proxy) X-Ref |
Returns the icon and edit urls for the tool proxy. param: stdClass $proxy The tool proxy return: array The urls of the tool proxy |
get_tool_type_state_info(stdClass $type) X-Ref |
Returns information on the current state of the tool type param: stdClass $type The tool type return: array An array with a text description of the state, and boolean for whether it is in each state: |
get_tool_type_config($type) X-Ref |
Returns information on the configuration of the tool type param: stdClass $type The tool type return: array An array with configuration details |
get_tool_type_capability_groups($type) X-Ref |
Returns a summary of each LTI capability this tool type requires in plain language param: stdClass $type The tool type return: array An array of text descriptions of each of the capabilities this tool type requires |
get_tool_type_instance_ids($type) X-Ref |
Returns the ids of each instance of this tool type param: stdClass $type The tool type return: array An array of ids of the instances of this tool type |
serialise_tool_type(stdClass $type) X-Ref |
Serialises this tool type param: stdClass $type The tool type return: array An array of values representing this type |
serialise_tool_proxy(stdClass $proxy) X-Ref |
Serialises this tool proxy. param: stdClass $proxy The tool proxy return: array An array of values representing this type |
lti_load_type_if_cartridge($type) X-Ref |
Loads the cartridge information into the tool type, if the launch url is for a cartridge file param: stdClass $type The tool type object to be filled in |
lti_load_tool_if_cartridge($lti) X-Ref |
Loads the cartridge information into the new tool, if the launch url is for a cartridge file param: stdClass $lti The tools config |
lti_is_cartridge($url) X-Ref |
Determines if the given url is for a IMS basic cartridge param: string $url The url to be checked return: True if the url is for a cartridge |
lti_load_type_from_cartridge($url, $type) X-Ref |
Allows you to load settings for an external tool type from an IMS cartridge. param: string $url The URL to the cartridge param: stdClass $type The tool type object to be filled in |
lti_load_tool_from_cartridge($url, $lti) X-Ref |
Allows you to load in the configuration for an external tool from an IMS cartridge. param: string $url The URL to the cartridge param: stdClass $lti LTI object |
lti_load_cartridge($url, $map, $propertiesmap = array() X-Ref |
Search for a tag within an XML DOMDocument param: string $url The url of the cartridge to be loaded param: array $map The map of tags to keys in the return array param: array $propertiesmap The map of properties to keys in the return array return: array An associative array with the given keys and their values from the cartridge |
get_tag($tagname, $xpath, $attribute = null) X-Ref |
Search for a tag within an XML DOMDocument param: stdClass $tagname The name of the tag to search for param: XPath $xpath The XML to find the tag in param: XPath $attribute The attribute to search for (if we should search for a child node with the given |
lti_new_access_token($typeid, $scopes) X-Ref |
Create a new access token. param: int $typeid Tool type ID param: string[] $scopes Scopes permitted for new token return: stdClass Access token |
lti_libxml_disable_entity_loader(bool $value) X-Ref |
Wrapper for function libxml_disable_entity_loader() deprecated in PHP 8 Method was deprecated in PHP 8 and it shows deprecation message. However it is still required in the previous versions on PHP. While Moodle supports both PHP 7 and 8 we need to keep it. param: bool $value return: bool |