$mform->setType('lti_customparameters', PARAM_TEXT);
$mform->addHelpButton('lti_customparameters', 'custom', 'lti');
- if (!$istool && !empty($this->_customdata->isadmin)) {
- $mform->addElement('advcheckbox', 'lti_coursevisible', ' ', ' ' . get_string('show_in_course', 'lti'));
- $mform->addHelpButton('lti_coursevisible', 'show_in_course', 'lti');
+ if (!empty($this->_customdata->isadmin)) {
+ $options = array(
+ LTI_COURSEVISIBLE_NO => get_string('show_in_course_no', 'lti'),
+ LTI_COURSEVISIBLE_PRECONFIGURED => get_string('show_in_course_preconfigured', 'lti'),
+ LTI_COURSEVISIBLE_ACTIVITYCHOOSER => get_string('show_in_course_activity_chooser', 'lti'),
+ );
+ if ($istool) {
+ // LTI2 tools can not be matched by URL, they have to be either in preconfigured tools or in activity chooser.
+ unset($options[LTI_COURSEVISIBLE_NO]);
+ $stringname = 'show_in_course_lti2';
+ } else {
+ $stringname = 'show_in_course_lti1';
+ }
+ $mform->addElement('select', 'lti_coursevisible', get_string($stringname, 'lti'), $options);
+ $mform->addHelpButton('lti_coursevisible', $stringname, 'lti');
$mform->setDefault('lti_coursevisible', '1');
} else {
- $mform->addElement('hidden', 'lti_coursevisible', '1');
+ $mform->addElement('hidden', 'lti_coursevisible', LTI_COURSEVISIBLE_PRECONFIGURED);
}
- $mform->setType('lti_coursevisible', PARAM_BOOL);
+ $mform->setType('lti_coursevisible', PARAM_INT);
$mform->addElement('hidden', 'typeid');
$mform->setType('typeid', PARAM_INT);
$string['share_roster_help'] = 'Specify whether the tool can access the list of users enrolled in this course.
Note that this setting may be overridden in the tool configuration.';
-$string['show_in_course'] = 'Show tool in activity chooser';
-$string['show_in_course_help'] = 'If ticked, this tool will be shown in the activity chooser for a teacher to select to add to a course. It will also be shown in the preconfigured tool dropdown menu when adding an external tool to a course.
-
-If left unticked, the tool configuration may be used if the correct launch URL is entered when adding an external tool to a course.';
+$string['show_in_course_activity_chooser'] = 'Show in activity chooser and as preconfigured tool';
+$string['show_in_course_lti1'] = 'Show when creating activities';
+$string['show_in_course_lti1_help'] = 'This tool can be shown in the activity chooser for a teacher to select to add to a course. It also can be shown in the preconfigured tool dropdown menu when adding an external tool to a course.
+
+Alternatively, the tool configuration may not show up in the forms but only used if the correct launch URL is entered when adding an external tool to a course.';
+$string['show_in_course_lti2'] = 'Show when creating activities';
+$string['show_in_course_lti2_help'] = 'This tool can be shown in the activity chooser for a teacher to select to add to a course or in the preconfigured tool dropdown menu when adding an external tool to a course.';
+$string['show_in_course_no'] = 'Do not show, use for launch URL matching only';
+$string['show_in_course_preconfigured'] = 'Show as preconfigured tool when adding External tool';
$string['size'] = 'Size parameters';
$string['submission'] = 'Submission';
$string['submissions'] = 'Submissions';
define('LTI_SETTING_ALWAYS', 1);
define('LTI_SETTING_DELEGATE', 2);
+define('LTI_COURSEVISIBLE_NO', 0);
+define('LTI_COURSEVISIBLE_PRECONFIGURED', 1);
+define('LTI_COURSEVISIBLE_ACTIVITYCHOOSER', 2);
+
/**
* Return the launch data required for opening the external tool.
*
* Returns all lti types visible in this course
*
* @param int $courseid The id of the course to retieve types for
+ * @param array $coursevisible options for 'coursevisible' field,
+ * default [LTI_COURSEVISIBLE_PRECONFIGURED, LTI_COURSEVISIBLE_ACTIVITYCHOOSER]
* @return stdClass[] All the lti types visible in the given course
*/
-function lti_get_lti_types_by_course($courseid) {
+function lti_get_lti_types_by_course($courseid, $coursevisible = null) {
global $DB, $SITE;
+ if ($coursevisible === null) {
+ $coursevisible = [LTI_COURSEVISIBLE_PRECONFIGURED, LTI_COURSEVISIBLE_ACTIVITYCHOOSER];
+ }
+
+ list($coursevisiblesql, $coursevisparams) = $DB->get_in_or_equal($coursevisible, SQL_PARAMS_NAMED, 'coursevisible');
$query = "SELECT *
FROM {lti_types}
- WHERE coursevisible = 1
+ WHERE coursevisible $coursevisiblesql
AND (course = :siteid OR course = :courseid)
AND state = :active";
return $DB->get_records_sql($query,
- array('siteid' => $SITE->id, 'courseid' => $courseid, 'active' => LTI_TOOL_STATE_CONFIGURED));
+ array('siteid' => $SITE->id, 'courseid' => $courseid, 'active' => LTI_TOOL_STATE_CONFIGURED) + $coursevisparams);
}
/**
function lti_get_configured_types($courseid, $sectionreturn = 0) {
global $OUTPUT;
$types = array();
- $admintypes = lti_get_lti_types_by_course($courseid);
+ $admintypes = lti_get_lti_types_by_course($courseid, [LTI_COURSEVISIBLE_ACTIVITYCHOOSER]);
foreach ($admintypes as $ltitype) {
$type = new stdClass();
And I follow "Add preconfigured tool"
And I set the following fields to these values:
| Tool name | Teaching Tool 1 |
+ | Show when creating activities | Show in activity chooser and as preconfigured tool |
And I set the field "Tool base URL/cartridge URL" to local url "/mod/lti/tests/fixtures/tool_provider.html"
And I press "Save changes"
And I log out