Permalink
Browse files

MDL-36224: Add support for pluggable extensions to add new LTI services

  • Loading branch information...
scriby authored and damyon committed Oct 29, 2012
1 parent 2e84b4b commit 976b5bca315f6dc430b71c6794ffcc645bc892fe
Showing with 61 additions and 0 deletions.
  1. +16 −0 mod/lti/lib.php
  2. +4 −0 mod/lti/mod_form.php
  3. +6 −0 mod/lti/service.php
  4. +35 −0 mod/lti/servicelib.php
View
@@ -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.
View
@@ -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;
View
@@ -150,10 +150,16 @@
$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;
View
@@ -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;
+}

0 comments on commit 976b5bc

Please sign in to comment.