Merge branch 'wip-MDL-45064-master' of https://github.com/marinaglancy/moodle

This commit is contained in:
David Monllao
2016-04-13 09:38:12 +08:00
13 changed files with 269 additions and 135 deletions
+44 -38
View File
@@ -196,47 +196,53 @@ function lti_delete_instance($id) {
return $DB->delete_records("lti", array("id" => $basiclti->id));
}
function lti_get_types() {
global $OUTPUT;
/**
* 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 to the activity chooser
*
* @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_shortcuts($defaultitem) {
global $CFG, $COURSE;
require_once($CFG->dirroot.'/mod/lti/locallib.php');
$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;
}
+49 -4
View File
@@ -1070,8 +1070,14 @@ function lti_filter_tool_types(array $tools, $state) {
return $return;
}
function lti_get_types_for_add_instance() {
global $DB, $SITE, $COURSE;
/**
* 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
*/
function lti_get_lti_types_by_course($courseid) {
global $DB, $SITE;
$query = "SELECT *
FROM {lti_types}
@@ -1079,8 +1085,18 @@ function lti_get_types_for_add_instance() {
AND (course = :siteid OR course = :courseid)
AND state = :active";
$admintypes = $DB->get_records_sql($query,
array('siteid' => $SITE->id, 'courseid' => $COURSE->id, 'active' => LTI_TOOL_STATE_CONFIGURED));
return $DB->get_records_sql($query,
array('siteid' => $SITE->id, 'courseid' => $courseid, 'active' => LTI_TOOL_STATE_CONFIGURED));
}
/**
* Returns tool types for lti add instance and edit page
*
* @return array Array of lti types
*/
function lti_get_types_for_add_instance() {
global $COURSE;
$admintypes = lti_get_lti_types_by_course($COURSE->id);
$types = array();
$types[0] = (object)array('name' => get_string('automatic', 'lti'), 'course' => 0, 'toolproxyid' => null);
@@ -1092,6 +1108,35 @@ function lti_get_types_for_add_instance() {
return $types;
}
/**
* 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, link
*/
function lti_get_configured_types($courseid, $sectionreturn = 0) {
global $OUTPUT;
$types = array();
$admintypes = lti_get_lti_types_by_course($courseid);
foreach ($admintypes as $ltitype) {
$type = new stdClass();
$type->modclass = MOD_CLASS_ACTIVITY;
$type->name = 'lti_type_' . $ltitype->id;
$type->title = $ltitype->name;
if (empty($ltitype->icon)) {
$type->icon = $OUTPUT->pix_icon('icon', '', 'lti', array('class' => 'icon'));
} else {
$type->icon = html_writer::empty_tag('img', array('src' => $ltitype->icon, 'alt' => $ltitype->name, 'class' => 'icon'));
}
$type->link = new moodle_url('/course/modedit.php', array('add' => 'lti', 'return' => 0, 'course' => $courseid,
'sr' => $sectionreturn, 'typeid' => $ltitype->id));
$types[] = $type;
}
return $types;
}
function lti_get_domain_from_url($url) {
$matches = array();
+8
View File
@@ -96,6 +96,8 @@ class mod_lti_mod_form extends moodleform_mod {
// Tool settings.
$tooltypes = $mform->addElement('select', 'typeid', get_string('external_tool_type', 'lti'), array());
$typeid = optional_param('typeid', false, PARAM_INT);
$mform->getElement('typeid')->setValue($typeid);
$mform->addHelpButton('typeid', 'external_tool_type', 'lti');
$toolproxy = array();
@@ -149,6 +151,7 @@ class mod_lti_mod_form extends moodleform_mod {
$mform->addElement('select', 'launchcontainer', get_string('launchinpopup', 'lti'), $launchoptions);
$mform->setDefault('launchcontainer', LTI_LAUNCH_CONTAINER_DEFAULT);
$mform->addHelpButton('launchcontainer', 'launchinpopup', 'lti');
$mform->setAdvanced('launchcontainer');
$mform->addElement('text', 'resourcekey', get_string('resourcekey', 'lti'));
$mform->setType('resourcekey', PARAM_TEXT);
@@ -243,6 +246,11 @@ class mod_lti_mod_form extends moodleform_mod {
),
);
if (!empty($typeid)) {
$mform->setAdvanced('typeid');
$mform->setAdvanced('toolurl');
}
$PAGE->requires->js_init_call('M.mod_lti.editor.init', array(json_encode($jsinfo)), true, $module);
}
+7
View File
@@ -0,0 +1,7 @@
This files describes API changes in /mod/lti/source/* - LTI source plugins,
information provided here is intended especially for developers.
=== 3.1 ===
* Callback get_types() is deprecated, instead ltisource plugins can define callback get_shortcuts().
See source code for lti_get_shortcuts() and get_module_metadata().
+37
View File
@@ -0,0 +1,37 @@
@mod @mod_lti
Feature: Add tool types
In order to provide activities for learners
As a teacher
I need to be able to add external tools to a course
Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Terry1 | Teacher1 | teacher1@example.com |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
And I log in as "admin"
And I navigate to "Manage external tool types" node in "Site administration > Plugins > Activity modules > LTI"
And I follow "Add external tool configuration"
And I set the following fields to these values:
| Tool name | Teaching Tool 1 |
| Show tool type when creating tool instances | 1 |
And I set the field "Tool base URL" to local url "/mod/lti/tests/fixtures/tool_provider.html"
And I press "Save changes"
And I log out
@javascript
Scenario: Add a tool via the acitivity picker
When I log in as "teacher1"
And I follow "Course 1"
And I turn editing mode on
And I add a "Teaching Tool 1" to section "1" and I fill the form with:
| Activity name | Test tool activity 1 |
| Launch container | Embed |
And I open "Test tool activity 1" actions menu
And I follow "Edit settings" in the open menu
Then the field "External tool type" matches value "Teaching Tool 1"
+8
View File
@@ -0,0 +1,8 @@
<html>
<head>
<title>Tool provider</title>
</head>
<body>
<p>This represents a tool provider</p>
</body>
</html>
+2
View File
@@ -5,6 +5,8 @@ information provided here is intended especially for developers.
* Old /mod/MODULENAME/pix/icon.gif and enrol/paypal/pix/icon.gif GIF icons have been removed. Please use pix_icon
renderable instead.
* Callback get_types() is deprecated, instead activity modules can define callback get_shortcuts().
See source code for get_module_metadata().
=== 3.0 ===