/**
* Return aliases of this activity. LTI should have an alias for each configured tool type
- * This is so you can add an external tool types directly from the activity chooser
+ * This is so you can add an external tool types directly to the activity chooser
*
- * @return array An array of aliases for this activity
+ * @param stdClass $defaultitem default item that would be added to the activity chooser if this callback was not present.
+ * It has properties: archetype, name, title, help, icon, link
+ * @return array An array of aliases for this activity. Each element is an object with same list of properties as $defaultitem.
+ * Properties title and link are required
**/
-function lti_get_aliases() {
+function lti_get_shortcuts($defaultitem) {
global $CFG, $COURSE;
require_once($CFG->dirroot.'/mod/lti/locallib.php');
- $types = lti_get_configured_types($COURSE->id);
-
- return $types;
-}
-
-function lti_get_types() {
- global $OUTPUT;
-
- $subtypes = array();
- foreach (get_plugin_list('ltisource') as $name => $dir) {
- if ($moretypes = component_callback("ltisource_$name", 'get_types')) {
- $subtypes = array_merge($subtypes, $moretypes);
+ $types = lti_get_configured_types($COURSE->id, $defaultitem->link->param('sr'));
+ $types[] = $defaultitem;
+
+ // Add items defined in ltisource plugins.
+ foreach (core_component::get_plugin_list('ltisource') as $pluginname => $dir) {
+ if ($moretypes = component_callback("ltisource_$pluginname", 'get_types')) {
+ // Callback 'get_types()' in 'ltisource' plugins is deprecated in 3.1 and will be removed in 3.5, TODO MDL-53697.
+ debugging('Deprecated callback get_types() is found in ltisource_' . $pluginname .
+ ', use get_shortcuts() instead', DEBUG_DEVELOPER);
+ $grouptitle = get_string('modulenameplural', 'mod_lti');
+ foreach ($moretypes as $subtype) {
+ // Instead of adding subitems combine the name of the group with the name of the subtype.
+ $subtype->title = get_string('activitytypetitle', '',
+ (object)['activity' => $grouptitle, 'type' => $subtype->typestr]);
+ // Re-implement the logic of get_module_metadata() in Moodle 3.0 and below for converting
+ // subtypes into items in activity chooser.
+ $subtype->type = str_replace('&', '&', $subtype->type);
+ $subtype->name = preg_replace('/.*type=/', '', $subtype->type);
+ $subtype->link = new moodle_url($defaultitem->link, array('type' => $subtype->name));
+ if (empty($subtype->help) && !empty($subtype->name) &&
+ get_string_manager()->string_exists('help' . $subtype->name, $pluginname)) {
+ $subtype->help = get_string('help' . $subtype->name, $pluginname);
+ }
+ unset($subtype->typestr);
+ $types[] = $subtype;
+ }
+ }
+ // LTISOURCE plugins can also implement callback get_shortcuts() to add items to the activity chooser.
+ // The return values are the same as of the 'mod' callbacks except that $defaultitem is only passed for reference and
+ // should not be added to the return value.
+ if ($moretypes = component_callback("ltisource_$pluginname", 'get_shortcuts', array($defaultitem))) {
+ $types = array_merge($types, $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 = '';
- $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;
}
* Returns all lti types visible in this course
*
* @param int $courseid The id of the course to retieve types for
- * @return stdClass All the lti types visible in the given course
+ * @return stdClass[] All the lti types visible in the given course
*/
function lti_get_lti_types_by_course($courseid) {
global $DB, $SITE;
* Returns a list of configured types in the given course
*
* @param int $courseid The id of the course to retieve types for
- * @return array Array of lti types
+ * @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, link
*/
-function lti_get_configured_types($courseid) {
+function lti_get_configured_types($courseid, $sectionreturn = 0) {
global $OUTPUT;
$types = array();
$admintypes = lti_get_lti_types_by_course($courseid);
} else {
$type->icon = html_writer::empty_tag('img', array('src' => $ltitype->icon, 'alt' => $ltitype->name, 'class' => 'icon'));
}
- if (!empty($ltitype->description)) {
- $type->help = $ltitype->description;
- }
- $type->link = new moodle_url('/course/modedit.php', array('add' => 'lti', 'return' => 0, 'course' => $courseid, 'sr' => 0,
- 'typeid' => $ltitype->id));
+ $type->link = new moodle_url('/course/modedit.php', array('add' => 'lti', 'return' => 0, 'course' => $courseid,
+ 'sr' => $sectionreturn, 'typeid' => $ltitype->id));
$types[] = $type;
}
return $types;