From 8cf7670e5876e3a205da8991aa20162f2305ae4b Mon Sep 17 00:00:00 2001 From: Mark Nielsen Date: Fri, 26 Apr 2013 16:00:33 -0700 Subject: [PATCH] MDL-36224: Improving lti_get_types If there are no LTI source plugins that need to be added to the activity chooser menu, then fallback to the default activity chooser display. --- mod/lti/lang/en/lti.php | 3 ++- mod/lti/lib.php | 42 ++++++++++++++++++++++++++++++++++------- mod/lti/mod_form.php | 2 +- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/mod/lti/lang/en/lti.php b/mod/lti/lang/en/lti.php index 483292c8677..f8a5d7317e7 100644 --- a/mod/lti/lang/en/lti.php +++ b/mod/lti/lang/en/lti.php @@ -188,6 +188,7 @@ $string['force_ssl_help'] = 'Selecting this option forces all launches to this t In addition, all web service requests from the tool provider will use SSL. If using this option, confirm that this Moodle site and the tool provider support SSL.'; +$string['generaltool'] = 'General tool'; $string['global_tool_types'] = 'Global tool types'; $string['grading'] = 'Grade Routing'; $string['icon_url'] = 'Icon URL'; @@ -267,7 +268,7 @@ External tool activities differ from URL resources in a few ways: * External tools support reading, updating, and deleting grades associated with the activity instance * External tool configurations create a trust relationship between your site and the tool provider, allowing secure communication between them'; $string['modulename_link'] = 'mod/lti/view'; -$string['modulenameplural'] = 'basicltis'; +$string['modulenameplural'] = 'External Tools'; $string['modulenamepluralformatted'] = 'LTI Instances'; $string['never'] = 'Never'; $string['new_window'] = 'New window'; diff --git a/mod/lti/lib.php b/mod/lti/lib.php index fed1e92d80c..895532acf81 100644 --- a/mod/lti/lib.php +++ b/mod/lti/lib.php @@ -173,18 +173,46 @@ function lti_delete_instance($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); + global $OUTPUT; + $subtypes = array(); foreach (get_plugin_list('ltisource') as $name => $dir) { if ($moretypes = component_callback("ltisource_$name", 'get_types')) { - $types = array_merge($types, $moretypes); + $subtypes = array_merge($subtypes, $moretypes); } } + if (empty($subtypes)) { + return MOD_SUBTYPE_NO_CHILDREN; + } + + $types = array(); + + $type = new stdClass(); + $type->modclass = MOD_CLASS_ACTIVITY; + $type->type = 'lti_group_start'; + $type->typestr = '--'.get_string('modulenameplural', 'mod_lti'); + $types[] = $type; + + $link = get_string('modulename_link', 'mod_lti'); + $linktext = get_string('morehelp'); + $help = get_string('modulename_help', 'mod_lti'); + $help .= html_writer::tag('div', $OUTPUT->doc_link($link, $linktext, true), array('class' => 'helpdoclink')); + + $type = new stdClass(); + $type->modclass = MOD_CLASS_ACTIVITY; + $type->type = 'lti'; + $type->typestr = get_string('generaltool', 'mod_lti'); + $type->help = $help; + $types[] = $type; + + $types = array_merge($types, $subtypes); + + $type = new stdClass(); + $type->modclass = MOD_CLASS_ACTIVITY; + $type->type = 'lti_group_end'; + $type->typestr = '--'; + $types[] = $type; + return $types; } diff --git a/mod/lti/mod_form.php b/mod/lti/mod_form.php index 31c7f231277..fbb6b04ca70 100644 --- a/mod/lti/mod_form.php +++ b/mod/lti/mod_form.php @@ -60,7 +60,7 @@ class mod_lti_mod_form extends moodleform_mod { if ($type = optional_param('type', false, PARAM_ALPHA)) { component_callback("ltisource_$type", 'add_instance_hook'); } - + $this->typeid = 0; $mform =& $this->_form;