Skip to content

Commit

Permalink
MDL-80141 ltix: moved lti course navigation extension from mod to core
Browse files Browse the repository at this point in the history
  • Loading branch information
godsonahamba authored and snake committed Dec 14, 2023
1 parent bacc3dd commit b53421a
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 57 deletions.
1 change: 1 addition & 0 deletions lang/en/ltix.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
$string['cleanaccesstokens'] = 'External tool removal of expired access tokens';
$string['contentselected'] = 'Content selected';
$string['courseactivitiesorresources'] = 'Course activities or resources';
$string['courseexternaltools'] = 'LTI External tools';
$string['courseinformation'] = 'Course information';
$string['duplicateregurl'] = 'This registration URL is already in use';
$string['errorincorrectconsumerkey'] = 'Consumer key is incorrect.';
Expand Down
11 changes: 6 additions & 5 deletions lib/classes/navigation/views/secondary.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ protected function get_default_course_mapping(): array {
'coursebadges' => 7.1,
'newbadge' => 7.2,
'filtermanagement' => 9,
'unenrolself' => 10,
'coursetags' => 11,
'download' => 12,
'contextlocking' => 13,
'unenrolself' => 11,
'coursetags' => 12,
'download' => 13,
'contextlocking' => 14,
],
];
$nodes['navigation'] = [
Expand All @@ -89,7 +89,8 @@ protected function get_default_course_mapping(): array {
'grades' => 2,
'badgesview' => 7,
'competencies' => 8,
'communication' => 14,
'communication' => 15,
'lticoursetools' => 10,
],
self::TYPE_CUSTOM => [
'contentbank' => 5,
Expand Down
8 changes: 8 additions & 0 deletions lib/navigationlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2996,6 +2996,14 @@ public function add_course_essentials($coursenode, stdClass $course) {
navigation_node::TYPE_SETTING, null, 'communication');
}

// Add link for LTI external tools. May be useful wrapping it with one of the $navoptions attributes.
$url = new moodle_url('/ltix/coursetools.php', ['id' => $course->id]);

$coursenode->add(get_string('courseexternaltools', 'ltix'), $url,
navigation_node::TYPE_SETTING, null, 'lticoursetools',
new pix_icon('i/settings', ''));


return true;
}
/**
Expand Down
66 changes: 33 additions & 33 deletions ltix/classes/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2290,7 +2290,7 @@ public static function get_launch_data($instance, $nonce = '', $messagetype = 'b

return array($endpoint, $parms);
}

/**
* Launch an external tool activity.
*
Expand Down Expand Up @@ -2827,12 +2827,12 @@ public static function params_to_string(object $params) {
public static function get_tool_table($tools, $id) {
global $OUTPUT;
$html = '';

$typename = get_string('typename', 'lti');
$baseurl = get_string('baseurl', 'lti');
$action = get_string('action', 'lti');
$createdon = get_string('createdon', 'lti');

if (!empty($tools)) {
$html .= "
<div id=\"{$id}_tools_container\" style=\"margin-top:.5em;margin-bottom:.5em\">
Expand All @@ -2846,13 +2846,13 @@ public static function get_tool_table($tools, $id) {
</tr>
</thead>
";

foreach ($tools as $type) {
$date = userdate($type->timecreated, get_string('strftimedatefullshort', 'core_langconfig'));
$accept = get_string('accept', 'lti');
$update = get_string('update', 'lti');
$delete = get_string('delete', 'lti');

if (empty($type->toolproxyid)) {
$baseurl = new \moodle_url('/mod/lti/typessettings.php', array(
'action' => 'accept',
Expand All @@ -2870,28 +2870,28 @@ public static function get_tool_table($tools, $id) {
));
$ref = $type->tpname;
}

$accepthtml = $OUTPUT->action_icon($baseurl,
new \pix_icon('t/check', $accept, '', array('class' => 'iconsmall')), null,
array('title' => $accept, 'class' => 'editing_accept'));

$deleteaction = 'delete';

if ($type->state == LTI_TOOL_STATE_CONFIGURED) {
$accepthtml = '';
}

if ($type->state != LTI_TOOL_STATE_REJECTED) {
$deleteaction = 'reject';
$delete = get_string('reject', 'lti');
}

$updateurl = clone($baseurl);
$updateurl->param('action', 'update');
$updatehtml = $OUTPUT->action_icon($updateurl,
new \pix_icon('t/edit', $update, '', array('class' => 'iconsmall')), null,
array('title' => $update, 'class' => 'editing_update'));

if (($type->state != LTI_TOOL_STATE_REJECTED) || empty($type->toolproxyid)) {
$deleteurl = clone($baseurl);
$deleteurl->param('action', $deleteaction);
Expand Down Expand Up @@ -2922,10 +2922,10 @@ public static function get_tool_table($tools, $id) {
} else {
$html .= get_string('no_' . $id, 'lti');
}

return $html;
}

/**
* This function builds the tab for a category of tool proxies
*
Expand All @@ -2936,13 +2936,13 @@ public static function get_tool_table($tools, $id) {
*/
public static function get_tool_proxy_table($toolproxies, $id) {
global $OUTPUT;

if (!empty($toolproxies)) {
$typename = get_string('typename', 'lti');
$url = get_string('registrationurl', 'lti');
$action = get_string('action', 'lti');
$createdon = get_string('createdon', 'lti');

$html = <<< EOD
<div id="{$id}_tool_proxies_container" style="margin-top: 0.5em; margin-bottom: 0.5em">
<table id="{$id}_tool_proxies">
Expand All @@ -2960,40 +2960,40 @@ public static function get_tool_proxy_table($toolproxies, $id) {
$accept = get_string('register', 'lti');
$update = get_string('update', 'lti');
$delete = get_string('delete', 'lti');

$baseurl = new \moodle_url('/mod/lti/registersettings.php', array(
'action' => 'accept',
'id' => $toolproxy->id,
'sesskey' => sesskey(),
'tab' => $id
));

$registerurl = new \moodle_url('/mod/lti/register.php', array(
'id' => $toolproxy->id,
'sesskey' => sesskey(),
'tab' => 'tool_proxy'
));

$accepthtml = $OUTPUT->action_icon($registerurl,
new \pix_icon('t/check', $accept, '', array('class' => 'iconsmall')), null,
array('title' => $accept, 'class' => 'editing_accept'));

$deleteaction = 'delete';

if ($toolproxy->state != LTI_TOOL_PROXY_STATE_CONFIGURED) {
$accepthtml = '';
}

if (($toolproxy->state == LTI_TOOL_PROXY_STATE_CONFIGURED) || ($toolproxy->state == LTI_TOOL_PROXY_STATE_PENDING)) {
$delete = get_string('cancel', 'lti');
}

$updateurl = clone($baseurl);
$updateurl->param('action', 'update');
$updatehtml = $OUTPUT->action_icon($updateurl,
new \pix_icon('t/edit', $update, '', array('class' => 'iconsmall')), null,
array('title' => $update, 'class' => 'editing_update'));

$deleteurl = clone($baseurl);
$deleteurl->param('action', $deleteaction);
$deletehtml = $OUTPUT->action_icon($deleteurl,
Expand All @@ -3020,7 +3020,7 @@ public static function get_tool_proxy_table($toolproxies, $id) {
} else {
$html = get_string('no_' . $id, 'lti');
}

return $html;
}

Expand Down Expand Up @@ -3073,7 +3073,7 @@ public static function get_ims_role($user, $cmid, $courseid, $islti2) {

public static function get_shared_secrets_by_key($key) {
global $DB;

// Look up the shared secret for the specified key in both the types_config table (for configured tools)
// And in the lti resource table for ad-hoc tools.
$lti13 = LTI_VERSION_1P3;
Expand All @@ -3096,14 +3096,14 @@ public static function get_shared_secrets_by_key($key) {
SELECT password AS value
FROM {lti}
WHERE resourcekey = :key3";

$sharedsecrets = $DB->get_records_sql($query, array('configured1' => LTI_TOOL_STATE_CONFIGURED, 'ltiversion' => $lti13,
'configured2' => LTI_TOOL_STATE_CONFIGURED, 'key1' => $key, 'key2' => $key, 'key3' => $key));

$values = array_map(function($item) {
return $item->value;
}, $sharedsecrets);

// There should really only be one shared secret per key. But, we can't prevent
// more than one getting entered. For instance, if the same key is used for two tool providers.
return $values;
Expand Down Expand Up @@ -3326,28 +3326,28 @@ public static function get_launch_container($lti, $toolconfig) {
if (empty($lti->launchcontainer)) {
$lti->launchcontainer = LTI_LAUNCH_CONTAINER_DEFAULT;
}

if ($lti->launchcontainer == LTI_LAUNCH_CONTAINER_DEFAULT) {
if (isset($toolconfig['launchcontainer'])) {
$launchcontainer = $toolconfig['launchcontainer'];
}
} else {
$launchcontainer = $lti->launchcontainer;
}

if (empty($launchcontainer) || $launchcontainer == LTI_LAUNCH_CONTAINER_DEFAULT) {
$launchcontainer = LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS;
}

$devicetype = core_useragent::get_device_type();

// Scrolling within the object element doesn't work on iOS or Android
// Opening the popup window also had some issues in testing
// For mobile devices, always take up the entire screen to ensure the best experience.
if ($devicetype === core_useragent::DEVICETYPE_MOBILE || $devicetype === core_useragent::DEVICETYPE_TABLET ) {
$launchcontainer = LTI_LAUNCH_CONTAINER_REPLACE_MOODLE_WINDOW;
}

return $launchcontainer;
}

Expand Down
2 changes: 1 addition & 1 deletion mod/lti/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function xmldb_lti_upgrade($oldversion) {
WHERE capability = :oldcapname
AND contextid != :sitecontextid
AND id NOT IN (SELECT rc.id
FROM {role_capabilities} rc
FROM (SELECT * FROM {role_capabilities}) AS rc
JOIN {role} r ON r.id = rc.roleid
WHERE rc.capability = :newcapname2
AND rc.contextid = :sitecontextid2)";
Expand Down
19 changes: 1 addition & 18 deletions mod/lti/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -752,21 +752,4 @@ function mod_lti_core_calendar_provide_event_action(calendar_event $event,
1,
true
);
}

/**
* Extend the course navigation with an "LTI External tools" link which redirects to a list of all tools available for course use.
*
* @param settings_navigation $navigation The settings navigation object
* @param stdClass $course The course
* @param stdclass $context Course context
* @return void
*/
function mod_lti_extend_navigation_course($navigation, $course, $context): void {
if (has_capability('mod/lti:addpreconfiguredinstance', $context)) {
$url = new moodle_url('/mod/lti/coursetools.php', ['id' => $course->id]);
$settingsnode = navigation_node::create(get_string('courseexternaltools', 'mod_lti'), $url, navigation_node::TYPE_SETTING,
null, 'coursetools', new pix_icon('i/settings', ''));
$navigation->add_node($settingsnode);
}
}
}

0 comments on commit b53421a

Please sign in to comment.