Moodle release 4.4beta
[moodle.git] / mod / lti / lib.php
blob144df5cf8aaca6d87b1c01cea82b333f3eda77d0
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 // This file is part of BasicLTI4Moodle
19 // BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability)
20 // consumer for Moodle 1.9 and Moodle 2.0. BasicLTI is a IMS Standard that allows web
21 // based learning tools to be easily integrated in LMS as native ones. The IMS BasicLTI
22 // specification is part of the IMS standard Common Cartridge 1.1 Sakai and other main LMS
23 // are already supporting or going to support BasicLTI. This project Implements the consumer
24 // for Moodle. Moodle is a Free Open source Learning Management System by Martin Dougiamas.
25 // BasicLTI4Moodle is a project iniciated and leaded by Ludo(Marc Alier) and Jordi Piguillem
26 // at the GESSI research group at UPC.
27 // SimpleLTI consumer for Moodle is an implementation of the early specification of LTI
28 // by Charles Severance (Dr Chuck) htp://dr-chuck.com , developed by Jordi Piguillem in a
29 // Google Summer of Code 2008 project co-mentored by Charles Severance and Marc Alier.
31 // BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis
32 // of the Universitat Politecnica de Catalunya http://www.upc.edu
33 // Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu.
35 /**
36 * This file contains a library of functions and constants for the lti module
38 * @package mod_lti
39 * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis
40 * marc.alier@upc.edu
41 * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu
42 * @author Marc Alier
43 * @author Jordi Piguillem
44 * @author Nikolas Galanis
45 * @author Chris Scribner
46 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
49 defined('MOODLE_INTERNAL') || die;
51 /**
52 * List of features supported in URL module
53 * @param string $feature FEATURE_xx constant for requested feature
54 * @return mixed True if module supports feature, false if not, null if doesn't know or string for the module purpose.
56 function lti_supports($feature) {
57 switch ($feature) {
58 case FEATURE_GROUPS:
59 case FEATURE_GROUPINGS:
60 return false;
61 case FEATURE_MOD_INTRO:
62 case FEATURE_COMPLETION_TRACKS_VIEWS:
63 case FEATURE_GRADE_HAS_GRADE:
64 case FEATURE_GRADE_OUTCOMES:
65 case FEATURE_BACKUP_MOODLE2:
66 case FEATURE_SHOW_DESCRIPTION:
67 return true;
68 case FEATURE_MOD_PURPOSE:
69 return MOD_PURPOSE_OTHER;
71 default:
72 return null;
76 /**
77 * Given an object containing all the necessary data,
78 * (defined by the form in mod.html) this function
79 * will create a new instance and return the id number
80 * of the new instance.
82 * @param object $instance An object from the form in mod.html
83 * @return int The id of the newly inserted basiclti record
84 **/
85 function lti_add_instance($lti, $mform) {
86 global $DB, $CFG;
87 require_once($CFG->dirroot.'/mod/lti/locallib.php');
89 if (!isset($lti->toolurl)) {
90 $lti->toolurl = '';
93 lti_load_tool_if_cartridge($lti);
95 $lti->timecreated = time();
96 $lti->timemodified = $lti->timecreated;
97 $lti->servicesalt = uniqid('', true);
98 if (!isset($lti->typeid)) {
99 $lti->typeid = null;
102 lti_force_type_config_settings($lti, lti_get_type_config_by_instance($lti));
104 if (empty($lti->typeid) && isset($lti->urlmatchedtypeid)) {
105 $lti->typeid = $lti->urlmatchedtypeid;
108 if (!isset($lti->instructorchoiceacceptgrades) || $lti->instructorchoiceacceptgrades != LTI_SETTING_ALWAYS) {
109 // The instance does not accept grades back from the provider, so set to "No grade" value 0.
110 $lti->grade = 0;
113 $lti->id = $DB->insert_record('lti', $lti);
115 if (isset($lti->instructorchoiceacceptgrades) && $lti->instructorchoiceacceptgrades == LTI_SETTING_ALWAYS) {
116 if (!isset($lti->cmidnumber)) {
117 $lti->cmidnumber = '';
120 lti_grade_item_update($lti);
123 $services = lti_get_services();
124 foreach ($services as $service) {
125 $service->instance_added( $lti );
128 $completiontimeexpected = !empty($lti->completionexpected) ? $lti->completionexpected : null;
129 \core_completion\api::update_completion_date_event($lti->coursemodule, 'lti', $lti->id, $completiontimeexpected);
131 return $lti->id;
135 * Given an object containing all the necessary data,
136 * (defined by the form in mod.html) this function
137 * will update an existing instance with new data.
139 * @param object $instance An object from the form in mod.html
140 * @return boolean Success/Fail
142 function lti_update_instance($lti, $mform) {
143 global $DB, $CFG;
144 require_once($CFG->dirroot.'/mod/lti/locallib.php');
146 lti_load_tool_if_cartridge($lti);
148 $lti->timemodified = time();
149 $lti->id = $lti->instance;
151 if (!isset($lti->showtitlelaunch)) {
152 $lti->showtitlelaunch = 0;
155 if (!isset($lti->showdescriptionlaunch)) {
156 $lti->showdescriptionlaunch = 0;
159 lti_force_type_config_settings($lti, lti_get_type_config_by_instance($lti));
161 if (isset($lti->instructorchoiceacceptgrades) && $lti->instructorchoiceacceptgrades == LTI_SETTING_ALWAYS) {
162 lti_grade_item_update($lti);
163 } else {
164 // Instance is no longer accepting grades from Provider, set grade to "No grade" value 0.
165 $lti->grade = 0;
166 $lti->instructorchoiceacceptgrades = 0;
168 lti_grade_item_delete($lti);
171 if ($lti->typeid == 0 && isset($lti->urlmatchedtypeid)) {
172 $lti->typeid = $lti->urlmatchedtypeid;
175 $services = lti_get_services();
176 foreach ($services as $service) {
177 $service->instance_updated( $lti );
180 $completiontimeexpected = !empty($lti->completionexpected) ? $lti->completionexpected : null;
181 \core_completion\api::update_completion_date_event($lti->coursemodule, 'lti', $lti->id, $completiontimeexpected);
183 return $DB->update_record('lti', $lti);
187 * Given an ID of an instance of this module,
188 * this function will permanently delete the instance
189 * and any data that depends on it.
191 * @param int $id Id of the module instance
192 * @return boolean Success/Failure
194 function lti_delete_instance($id) {
195 global $DB, $CFG;
196 require_once($CFG->dirroot.'/mod/lti/locallib.php');
198 if (! $basiclti = $DB->get_record("lti", array("id" => $id))) {
199 return false;
202 $result = true;
204 // Delete any dependent records here.
205 lti_grade_item_delete($basiclti);
207 $ltitype = $DB->get_record('lti_types', array('id' => $basiclti->typeid));
208 if ($ltitype) {
209 $DB->delete_records('lti_tool_settings',
210 array('toolproxyid' => $ltitype->toolproxyid, 'course' => $basiclti->course, 'coursemoduleid' => $id));
213 $cm = get_coursemodule_from_instance('lti', $id);
214 \core_completion\api::update_completion_date_event($cm->id, 'lti', $id, null);
216 // We must delete the module record after we delete the grade item.
217 if ($DB->delete_records("lti", array("id" => $basiclti->id)) ) {
218 $services = lti_get_services();
219 foreach ($services as $service) {
220 $service->instance_deleted( $id );
222 return true;
224 return false;
229 * Return the preconfigured tools which are configured for inclusion in the activity picker.
231 * @param \core_course\local\entity\content_item $defaultmodulecontentitem reference to the content item for the LTI module.
232 * @param \stdClass $user the user object, to use for cap checks if desired.
233 * @param stdClass $course the course to scope items to.
234 * @return array the array of content items.
236 function lti_get_course_content_items(\core_course\local\entity\content_item $defaultmodulecontentitem, \stdClass $user,
237 \stdClass $course) {
238 global $CFG, $OUTPUT;
239 require_once($CFG->dirroot.'/mod/lti/locallib.php');
241 $types = [];
243 // Use of a tool type, whether site or course level, is controlled by the following cap.
244 if (!has_capability('mod/lti:addpreconfiguredinstance', \core\context\course::instance($course->id), $user)) {
245 return $types;
247 $preconfiguredtools = lti_get_configured_types($course->id, $defaultmodulecontentitem->get_link()->param('sr'));
249 foreach ($preconfiguredtools as $preconfiguredtool) {
251 // Append the help link to the help text.
252 if (isset($preconfiguredtool->help)) {
253 if (isset($preconfiguredtool->helplink)) {
254 $linktext = get_string('morehelp');
255 $preconfiguredtool->help .= html_writer::tag('div',
256 $OUTPUT->doc_link($preconfiguredtool->helplink, $linktext, true), ['class' => 'helpdoclink']);
258 } else {
259 $preconfiguredtool->help = '';
262 // Preconfigured tools take their own id + 1. This logic exists because, previously, the entry permitting manual instance
263 // creation (the $defaultmodulecontentitem, or 'External tool' item) was included and had the id 1. This logic prevented id
264 // collisions.
265 $types[] = new \core_course\local\entity\content_item(
266 $preconfiguredtool->id + 1,
267 $preconfiguredtool->name,
268 new \core_course\local\entity\string_title($preconfiguredtool->title),
269 $preconfiguredtool->link,
270 $preconfiguredtool->icon,
271 $preconfiguredtool->help,
272 $defaultmodulecontentitem->get_archetype(),
273 $defaultmodulecontentitem->get_component_name(),
274 $defaultmodulecontentitem->get_purpose()
277 return $types;
281 * Return all content items which can be added to any course.
283 * @param \core_course\local\entity\content_item $defaultmodulecontentitem
284 * @return array the array of content items.
286 function mod_lti_get_all_content_items(\core_course\local\entity\content_item $defaultmodulecontentitem): array {
287 global $OUTPUT, $CFG;
288 require_once($CFG->dirroot . '/mod/lti/locallib.php'); // For access to constants.
290 $types = [];
292 foreach (lti_get_lti_types() as $ltitype) {
293 if ($ltitype->coursevisible != LTI_COURSEVISIBLE_ACTIVITYCHOOSER) {
294 continue;
296 $type = new stdClass();
297 $type->id = $ltitype->id;
298 $type->modclass = MOD_CLASS_ACTIVITY;
299 $type->name = 'lti_type_' . $ltitype->id;
300 // Clean the name. We don't want tags here.
301 $type->title = clean_param($ltitype->name, PARAM_NOTAGS);
302 $trimmeddescription = trim($ltitype->description ?? '');
303 $type->help = '';
304 if ($trimmeddescription != '') {
305 // Clean the description. We don't want tags here.
306 $type->help = clean_param($trimmeddescription, PARAM_NOTAGS);
307 $type->helplink = get_string('modulename_shortcut_link', 'lti');
309 if (empty($ltitype->icon)) {
310 $type->icon = $OUTPUT->pix_icon('monologo', '', 'lti', array('class' => 'icon'));
311 } else {
312 $type->icon = html_writer::empty_tag('img', array('src' => $ltitype->icon, 'alt' => $ltitype->name, 'class' => 'icon'));
314 $type->link = new moodle_url('/course/modedit.php', array('add' => 'lti', 'return' => 0, 'typeid' => $ltitype->id));
316 // Preconfigured tools take their own id + 1. This logic exists because, previously, the entry permitting manual instance
317 // creation (the $defaultmodulecontentitem, or 'External tool' item) was included and had the id 1. This logic prevented id
318 // collisions.
319 $types[] = new \core_course\local\entity\content_item(
320 $type->id + 1,
321 $type->name,
322 new \core_course\local\entity\string_title($type->title),
323 $type->link,
324 $type->icon,
325 $type->help,
326 $defaultmodulecontentitem->get_archetype(),
327 $defaultmodulecontentitem->get_component_name(),
328 $defaultmodulecontentitem->get_purpose()
332 return $types;
336 * Given a coursemodule object, this function returns the extra
337 * information needed to print this activity in various places.
338 * For this module we just need to support external urls as
339 * activity icons
341 * @param stdClass $coursemodule
342 * @return cached_cm_info info
344 function lti_get_coursemodule_info($coursemodule) {
345 global $DB, $CFG;
346 require_once($CFG->dirroot.'/mod/lti/locallib.php');
348 if (!$lti = $DB->get_record('lti', array('id' => $coursemodule->instance),
349 'icon, secureicon, intro, introformat, name, typeid, toolurl, launchcontainer')) {
350 return null;
353 $info = new cached_cm_info();
355 if ($coursemodule->showdescription) {
356 // Convert intro to html. Do not filter cached version, filters run at display time.
357 $info->content = format_module_intro('lti', $lti, $coursemodule->id, false);
360 if (!empty($lti->typeid)) {
361 $toolconfig = lti_get_type_config($lti->typeid);
362 } else if ($tool = lti_get_tool_by_url_match($lti->toolurl)) {
363 $toolconfig = lti_get_type_config($tool->id);
364 } else {
365 $toolconfig = array();
368 // We want to use the right icon based on whether the
369 // current page is being requested over http or https.
370 if (lti_request_is_using_ssl() &&
371 (!empty($lti->secureicon) || (isset($toolconfig['secureicon']) && !empty($toolconfig['secureicon'])))) {
372 if (!empty($lti->secureicon)) {
373 $info->iconurl = new moodle_url($lti->secureicon);
374 } else {
375 $info->iconurl = new moodle_url($toolconfig['secureicon']);
377 } else if (!empty($lti->icon)) {
378 $info->iconurl = new moodle_url($lti->icon);
379 } else if (isset($toolconfig['icon']) && !empty($toolconfig['icon'])) {
380 $info->iconurl = new moodle_url($toolconfig['icon']);
383 // Does the link open in a new window?
384 $launchcontainer = lti_get_launch_container($lti, $toolconfig);
385 if ($launchcontainer == LTI_LAUNCH_CONTAINER_WINDOW) {
386 $launchurl = new moodle_url('/mod/lti/launch.php', array('id' => $coursemodule->id));
387 $info->onclick = "window.open('" . $launchurl->out(false) . "', 'lti-".$coursemodule->id."'); return false;";
390 $info->name = $lti->name;
392 return $info;
396 * Return a small object with summary information about what a
397 * user has done with a given particular instance of this module
398 * Used for user activity reports.
399 * $return->time = the time they did it
400 * $return->info = a short text description
402 * @return null
403 * @TODO: implement this moodle function (if needed)
405 function lti_user_outline($course, $user, $mod, $basiclti) {
406 return null;
410 * Print a detailed representation of what a user has done with
411 * a given particular instance of this module, for user activity reports.
413 * @return boolean
414 * @TODO: implement this moodle function (if needed)
416 function lti_user_complete($course, $user, $mod, $basiclti) {
417 return true;
421 * Given a course and a time, this module should find recent activity
422 * that has occurred in basiclti activities and print it out.
423 * Return true if there was output, or false is there was none.
425 * @uses $CFG
426 * @return boolean
427 * @TODO: implement this moodle function
429 function lti_print_recent_activity($course, $isteacher, $timestart) {
430 return false; // True if anything was printed, otherwise false.
434 * Function to be run periodically according to the moodle cron
435 * This function searches for things that need to be done, such
436 * as sending out mail, toggling flags etc ...
438 * @uses $CFG
439 * @return boolean
441 function lti_cron () {
442 return true;
446 * Must return an array of grades for a given instance of this module,
447 * indexed by user. It also returns a maximum allowed grade.
449 * Example:
450 * $return->grades = array of grades;
451 * $return->maxgrade = maximum allowed grade;
453 * return $return;
455 * @param int $basicltiid ID of an instance of this module
456 * @return mixed Null or object with an array of grades and with the maximum grade
458 * @TODO: implement this moodle function (if needed)
460 function lti_grades($basicltiid) {
461 return null;
465 * @deprecated since Moodle 3.8
467 function lti_scale_used() {
468 throw new coding_exception('lti_scale_used() can not be used anymore. Plugins can implement ' .
469 '<modname>_scale_used_anywhere, all implementations of <modname>_scale_used are now ignored');
473 * Checks if scale is being used by any instance of basiclti.
474 * This function was added in 1.9
476 * This is used to find out if scale used anywhere
477 * @param $scaleid int
478 * @return boolean True if the scale is used by any basiclti
481 function lti_scale_used_anywhere($scaleid) {
482 global $DB;
484 if ($scaleid and $DB->record_exists('lti', array('grade' => -$scaleid))) {
485 return true;
486 } else {
487 return false;
492 * Execute post-install custom actions for the module
493 * This function was added in 1.9
495 * @return boolean true if success, false on error
497 function lti_install() {
498 return true;
502 * Execute post-uninstall custom actions for the module
503 * This function was added in 1.9
505 * @return boolean true if success, false on error
507 function lti_uninstall() {
508 return true;
512 * Returns available Basic LTI types
514 * @return array of basicLTI types
516 function lti_get_lti_types() {
517 global $DB;
519 return $DB->get_records('lti_types', null, 'state DESC, timemodified DESC');
523 * Returns available Basic LTI types that match the given
524 * tool proxy id
526 * @param int $toolproxyid Tool proxy id
527 * @return array of basicLTI types
529 function lti_get_lti_types_from_proxy_id($toolproxyid) {
530 global $DB;
532 return $DB->get_records('lti_types', array('toolproxyid' => $toolproxyid), 'state DESC, timemodified DESC');
536 * Create grade item for given basiclti
538 * @category grade
539 * @param object $basiclti object with extra cmidnumber
540 * @param mixed optional array/object of grade(s); 'reset' means reset grades in gradebook
541 * @return int 0 if ok, error code otherwise
543 function lti_grade_item_update($basiclti, $grades = null) {
544 global $CFG;
545 require_once($CFG->libdir.'/gradelib.php');
546 require_once($CFG->dirroot.'/mod/lti/servicelib.php');
548 if (!lti_accepts_grades($basiclti)) {
549 return 0;
552 $params = array('itemname' => $basiclti->name, 'idnumber' => $basiclti->cmidnumber);
554 if ($basiclti->grade > 0) {
555 $params['gradetype'] = GRADE_TYPE_VALUE;
556 $params['grademax'] = $basiclti->grade;
557 $params['grademin'] = 0;
559 } else if ($basiclti->grade < 0) {
560 $params['gradetype'] = GRADE_TYPE_SCALE;
561 $params['scaleid'] = -$basiclti->grade;
563 } else {
564 $params['gradetype'] = GRADE_TYPE_TEXT; // Allow text comments only.
567 if ($grades === 'reset') {
568 $params['reset'] = true;
569 $grades = null;
572 return grade_update('mod/lti', $basiclti->course, 'mod', 'lti', $basiclti->id, 0, $grades, $params);
576 * Update activity grades
578 * @param stdClass $basiclti The LTI instance
579 * @param int $userid Specific user only, 0 means all.
580 * @param bool $nullifnone Not used
582 function lti_update_grades($basiclti, $userid=0, $nullifnone=true) {
583 global $CFG;
584 require_once($CFG->dirroot.'/mod/lti/servicelib.php');
585 // LTI doesn't have its own grade table so the only thing to do is update the grade item.
586 if (lti_accepts_grades($basiclti)) {
587 lti_grade_item_update($basiclti);
592 * Delete grade item for given basiclti
594 * @category grade
595 * @param object $basiclti object
596 * @return object basiclti
598 function lti_grade_item_delete($basiclti) {
599 global $CFG;
600 require_once($CFG->libdir.'/gradelib.php');
602 return grade_update('mod/lti', $basiclti->course, 'mod', 'lti', $basiclti->id, 0, null, array('deleted' => 1));
606 * Log post actions
608 * @return array
610 function lti_get_post_actions() {
611 return array();
615 * Log view actions
617 * @return array
619 function lti_get_view_actions() {
620 return array('view all', 'view');
624 * Mark the activity completed (if required) and trigger the course_module_viewed event.
626 * @param stdClass $lti lti object
627 * @param stdClass $course course object
628 * @param stdClass $cm course module object
629 * @param stdClass $context context object
630 * @since Moodle 3.0
632 function lti_view($lti, $course, $cm, $context) {
634 // Trigger course_module_viewed event.
635 $params = array(
636 'context' => $context,
637 'objectid' => $lti->id
640 $event = \mod_lti\event\course_module_viewed::create($params);
641 $event->add_record_snapshot('course_modules', $cm);
642 $event->add_record_snapshot('course', $course);
643 $event->add_record_snapshot('lti', $lti);
644 $event->trigger();
646 // Completion.
647 $completion = new completion_info($course);
648 $completion->set_module_viewed($cm);
652 * Check if the module has any update that affects the current user since a given time.
654 * @param cm_info $cm course module data
655 * @param int $from the time to check updates from
656 * @param array $filter if we need to check only specific updates
657 * @return stdClass an object with the different type of areas indicating if they were updated or not
658 * @since Moodle 3.2
660 function lti_check_updates_since(cm_info $cm, $from, $filter = array()) {
661 global $DB, $USER;
663 $updates = course_check_module_updates_since($cm, $from, array(), $filter);
665 // Check if there is a new submission.
666 $updates->submissions = (object) array('updated' => false);
667 $select = 'ltiid = :id AND userid = :userid AND (datesubmitted > :since1 OR dateupdated > :since2)';
668 $params = array('id' => $cm->instance, 'userid' => $USER->id, 'since1' => $from, 'since2' => $from);
669 $submissions = $DB->get_records_select('lti_submission', $select, $params, '', 'id');
670 if (!empty($submissions)) {
671 $updates->submissions->updated = true;
672 $updates->submissions->itemids = array_keys($submissions);
675 // Now, teachers should see other students updates.
676 if (has_capability('mod/lti:manage', $cm->context)) {
677 $select = 'ltiid = :id AND (datesubmitted > :since1 OR dateupdated > :since2)';
678 $params = array('id' => $cm->instance, 'since1' => $from, 'since2' => $from);
680 if (groups_get_activity_groupmode($cm) == SEPARATEGROUPS) {
681 $groupusers = array_keys(groups_get_activity_shared_group_members($cm));
682 if (empty($groupusers)) {
683 return $updates;
685 list($insql, $inparams) = $DB->get_in_or_equal($groupusers, SQL_PARAMS_NAMED);
686 $select .= ' AND userid ' . $insql;
687 $params = array_merge($params, $inparams);
690 $updates->usersubmissions = (object) array('updated' => false);
691 $submissions = $DB->get_records_select('lti_submission', $select, $params, '', 'id');
692 if (!empty($submissions)) {
693 $updates->usersubmissions->updated = true;
694 $updates->usersubmissions->itemids = array_keys($submissions);
698 return $updates;
702 * Get icon mapping for font-awesome.
704 function mod_lti_get_fontawesome_icon_map() {
705 return [
706 'mod_lti:warning' => 'fa-exclamation text-warning',
711 * This function receives a calendar event and returns the action associated with it, or null if there is none.
713 * This is used by block_myoverview in order to display the event appropriately. If null is returned then the event
714 * is not displayed on the block.
716 * @param calendar_event $event
717 * @param \core_calendar\action_factory $factory
718 * @param int $userid User id to use for all capability checks, etc. Set to 0 for current user (default).
719 * @return \core_calendar\local\event\entities\action_interface|null
721 function mod_lti_core_calendar_provide_event_action(calendar_event $event,
722 \core_calendar\action_factory $factory,
723 int $userid = 0) {
724 global $USER;
726 if (empty($userid)) {
727 $userid = $USER->id;
730 $cm = get_fast_modinfo($event->courseid, $userid)->instances['lti'][$event->instance];
732 if (!$cm->uservisible) {
733 // The module is not visible to the user for any reason.
734 return null;
737 $completion = new \completion_info($cm->get_course());
739 $completiondata = $completion->get_data($cm, false, $userid);
741 if ($completiondata->completionstate != COMPLETION_INCOMPLETE) {
742 return null;
745 return $factory->create_instance(
746 get_string('view'),
747 new \moodle_url('/mod/lti/view.php', ['id' => $cm->id]),
749 true
754 * Extend the course navigation with an "LTI External tools" link which redirects to a list of all tools available for course use.
756 * @param settings_navigation $navigation The settings navigation object
757 * @param stdClass $course The course
758 * @param stdclass $context Course context
759 * @return void
761 function mod_lti_extend_navigation_course($navigation, $course, $context): void {
762 if (has_capability('mod/lti:addpreconfiguredinstance', $context)) {
763 $url = new moodle_url('/mod/lti/coursetools.php', ['id' => $course->id]);
764 $settingsnode = navigation_node::create(get_string('courseexternaltools', 'mod_lti'), $url, navigation_node::TYPE_SETTING,
765 null, 'coursetools', new pix_icon('i/settings', ''));
766 $navigation->add_node($settingsnode);