Commit 01e8bfd7 authored by John Okely's avatar John Okely Committed by Marina Glancy
Browse files

MDL-45064 lti: LTI types in activity chooser

parent f40b444e
......@@ -1257,6 +1257,15 @@ function get_module_metadata($course, $modnames, $sectionreturn = null) {
}
include_once($libfile);
$aliases = component_callback($modname, 'get_aliases', array(), array());
if (count($aliases) > 0) {
foreach ($aliases as $alias) {
$module = $alias;
$module->archetype = plugin_supports('mod', $modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER);
$return[$alias->name] = $module;
}
}
// NOTE: this is legacy stuff, module subtypes are very strongly discouraged!!
$gettypesfunc = $modname.'_get_types';
$types = MOD_SUBTYPE_NO_CHILDREN;
......
......@@ -143,6 +143,20 @@ class behat_forms extends behat_base {
}
/**
* Sets the field to wwwroot plus the given path. Include the first slash.
*
* @Given /^I set the field "(?P<field_string>(?:[^"]|\\")*)" to local url "(?P<field_path_string>(?:[^"]|\\")*)"$/
* @throws ElementNotFoundException Thrown by behat_base::find
* @param string $field
* @param string $path
* @return void
*/
public function i_set_the_field_to_local_url($field, $path) {
global $CFG;
$this->set_field_value($field, $CFG->wwwroot . $path);
}
/**
* Sets the specified value to the field.
*
......
......@@ -196,6 +196,21 @@ function lti_delete_instance($id) {
return $DB->delete_records("lti", array("id" => $basiclti->id));
}
/**
* 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
*
* @return array An array of aliases for this activity
**/
function lti_get_aliases() {
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;
......
......@@ -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,37 @@ 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
* @return array Array of lti types
*/
function lti_get_configured_types($courseid) {
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'));
}
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));
$types[] = $type;
}
return $types;
}
function lti_get_domain_from_url($url) {
$matches = array();
......
......@@ -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);
}
......
@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"
<html>
<head>
<title>Tool provider</title>
</head>
<body>
<p>This represents a tool provider</p>
</body>
</html>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment