MDL-36224: Add support for pluggable extensions to add new LTI services
This commit is contained in:
committed by
Damyon Wiese
parent
2e84b4b323
commit
976b5bca31
@@ -172,6 +172,22 @@ function lti_delete_instance($id) {
|
||||
return $DB->delete_records("lti", array("id" => $basiclti->id));
|
||||
}
|
||||
|
||||
function lti_get_types() {
|
||||
$type = new stdClass();
|
||||
$type->modclass = MOD_CLASS_ACTIVITY;
|
||||
$type->type = 'lti';
|
||||
$type->typestr = get_string('modulename', 'mod_lti');
|
||||
|
||||
$types = array($type);
|
||||
|
||||
foreach (get_plugin_list('ltisource') as $name => $dir) {
|
||||
if ($moretypes = component_callback("ltisource_$name", 'get_types')) {
|
||||
$types = array_merge($types, $moretypes);
|
||||
}
|
||||
}
|
||||
return $types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a coursemodule object, this function returns the extra
|
||||
* information needed to print this activity in various places.
|
||||
|
||||
@@ -57,6 +57,10 @@ class mod_lti_mod_form extends moodleform_mod {
|
||||
public function definition() {
|
||||
global $DB, $PAGE, $OUTPUT, $USER, $COURSE;
|
||||
|
||||
if ($type = optional_param('type', false, PARAM_ALPHA)) {
|
||||
component_callback("ltisource_$type", 'add_instance_hook');
|
||||
}
|
||||
|
||||
$this->typeid = 0;
|
||||
|
||||
$mform =& $this->_form;
|
||||
|
||||
@@ -150,10 +150,16 @@ switch ($messagetype) {
|
||||
$eventdata = array();
|
||||
$eventdata['other'] = array();
|
||||
$eventdata['other']['body'] = $rawbody;
|
||||
$eventdata['other']['messageid'] = lti_parse_message_id($xml);
|
||||
$eventdata['other']['messagetype'] = $messagetype;
|
||||
$eventdata['other']['consumerkey'] = $consumerkey;
|
||||
$eventdata['other']['sharedsecret'] = $sharedsecret;
|
||||
|
||||
// Before firing the event, allow subplugins a chance to handle.
|
||||
if (lti_extend_lti_services((object) $eventdata['other'])) {
|
||||
break;
|
||||
}
|
||||
|
||||
//If an event handler handles the web service, it should set this global to true
|
||||
//So this code knows whether to send an "operation not supported" or not.
|
||||
global $lti_web_service_handled;
|
||||
|
||||
@@ -223,3 +223,38 @@ function lti_verify_sourcedid($ltiinstance, $parsed) {
|
||||
throw new Exception('SourcedId hash not valid');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extend the LTI services through the ltisource plugins
|
||||
*
|
||||
* @param stdClass $data LTI request data
|
||||
* @return bool
|
||||
* @throws coding_exception
|
||||
*/
|
||||
function lti_extend_lti_services($data) {
|
||||
$plugins = get_plugin_list_with_function('ltisource', $data->messagetype);
|
||||
if (!empty($plugins)) {
|
||||
try {
|
||||
// There can only be one
|
||||
if (count($plugins) > 1) {
|
||||
throw new coding_exception('More than one ltisource plugin handler found');
|
||||
}
|
||||
$callback = current($plugins);
|
||||
call_user_func($callback, $data);
|
||||
} catch (moodle_exception $e) {
|
||||
$error = $e->getMessage();
|
||||
if (debugging('', DEBUG_DEVELOPER)) {
|
||||
$error .= ' '.format_backtrace(get_exception_info($e)->backtrace);
|
||||
}
|
||||
$responsexml = lti_get_response_xml(
|
||||
'failure',
|
||||
$error,
|
||||
$data->messageid,
|
||||
$data->messagetype
|
||||
);
|
||||
echo $responsexml->asXML();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user