2 // This file is part of Moodle - http://moodle.org/
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.
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/>.
18 * List the tool provided in a course
21 * @copyright 2016 Mark Nelson <markn@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 use enrol_lti\local\ltiadvantage\table\published_resources_table
;
27 require_once(__DIR__
. '/../../config.php');
28 require_once($CFG->dirroot
.'/enrol/lti/lib.php');
30 $courseid = required_param('courseid', PARAM_INT
);
31 $action = optional_param('action', '', PARAM_ALPHA
);
32 $legacy = optional_param('legacy', false, PARAM_BOOL
);
35 $instanceid = required_param('instanceid', PARAM_INT
);
36 $instance = $DB->get_record('enrol', array('id' => $instanceid), '*', MUST_EXIST
);
38 $confirm = optional_param('confirm', 0, PARAM_INT
);
40 $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST
);
42 $context = context_course
::instance($course->id
);
44 require_login($course);
45 require_capability('moodle/course:enrolreview', $context);
47 $ltiplugin = enrol_get_plugin('lti');
48 $canconfig = has_capability('moodle/course:enrolconfig', $context);
49 $pageurl = new moodle_url('/enrol/lti/index.php', array('courseid' => $courseid, 'legacy' => $legacy));
51 $PAGE->set_url($pageurl);
52 $PAGE->set_title(get_string('course') . ': ' . $course->fullname
);
53 $PAGE->set_pagelayout('admin');
55 // Check if we want to perform any actions.
57 if ($action === 'delete') {
58 if ($ltiplugin->can_delete_instance($instance)) {
60 $ltiplugin->delete_instance($instance);
64 $yesurl = new moodle_url('/enrol/lti/index.php',
65 array('courseid' => $course->id
,
67 'instanceid' => $instance->id
,
69 'sesskey' => sesskey())
71 $displayname = $ltiplugin->get_instance_name($instance);
72 $users = $DB->count_records('user_enrolments', array('enrolid' => $instance->id
));
74 $message = markdown_to_html(get_string('deleteinstanceconfirm', 'enrol',
75 array('name' => $displayname,
78 $message = markdown_to_html(get_string('deleteinstancenousersconfirm', 'enrol',
79 array('name' => $displayname)));
81 echo $OUTPUT->header();
82 echo $OUTPUT->confirm($message, $yesurl, $PAGE->url
);
83 echo $OUTPUT->footer();
86 } else if ($action === 'disable') {
87 if ($ltiplugin->can_hide_show_instance($instance)) {
88 if ($instance->status
!= ENROL_INSTANCE_DISABLED
) {
89 $ltiplugin->update_status($instance, ENROL_INSTANCE_DISABLED
);
93 } else if ($action === 'enable') {
94 if ($ltiplugin->can_hide_show_instance($instance)) {
95 if ($instance->status
!= ENROL_INSTANCE_ENABLED
) {
96 $ltiplugin->update_status($instance, ENROL_INSTANCE_ENABLED
);
103 echo $OUTPUT->header();
105 echo $OUTPUT->heading(get_string('toolsprovided', 'enrol_lti'));
106 echo html_writer
::tag('p', get_string('toolsprovided_help', 'enrol_lti'));
108 echo $OUTPUT->heading(get_string('publishedcontent', 'enrol_lti'));
109 echo html_writer
::tag('p', get_string('publishedcontent_help', 'enrol_lti'));
111 echo html_writer
::tag('p', $OUTPUT->doc_link('enrol/lti/index', get_string('morehelp')), ['class' => 'helplink']);
114 // Distinguish between legacy published tools and LTI-Advantage published resources.
117 new tabobject('0', new moodle_url('/enrol/lti/index.php', ['courseid' => $courseid]),
118 get_string('lti13', 'enrol_lti')),
119 new tabobject('1', new moodle_url('/enrol/lti/index.php', ['legacy' => 1, 'courseid' => $courseid]),
120 get_string('ltilegacy', 'enrol_lti')),
123 $selected = $legacy ?
'1' : '0';
124 echo html_writer
::div(print_tabs($tabs, $selected, null, null, true), 'lti-resource-publication');
127 $notify = new \core\output\notification
(get_string('ltilegacydeprecatednotice', 'enrol_lti'),
128 \core\output\notification
::NOTIFY_WARNING
);
129 echo $OUTPUT->render($notify);
131 if (\enrol_lti\helper
::count_lti_tools(array('courseid' => $courseid, 'ltiversion' => 'LTI-1p0/LTI-2p0')) > 0) {
133 $table = new \enrol_lti\
manage_table($courseid);
134 $table->define_baseurl($pageurl);
135 $table->out(50, false);
137 $notify = new \core\output\notification
(get_string('notoolsprovided', 'enrol_lti'),
138 \core\output\notification
::NOTIFY_INFO
);
139 echo $OUTPUT->render($notify);
142 if (\enrol_lti\helper
::count_lti_tools(array('courseid' => $courseid, 'ltiversion' => 'LTI-1p3')) > 0) {
143 $table = new published_resources_table($courseid);
144 $table->define_baseurl($pageurl);
145 $table->out(50, false);
147 $notify = new \core\output\notification
(get_string('nopublishedcontent', 'enrol_lti'),
148 \core\output\notification
::NOTIFY_INFO
);
149 echo $OUTPUT->render($notify);
153 if ($ltiplugin->can_add_instance($course->id
)) {
154 echo $OUTPUT->single_button(new moodle_url('/enrol/editinstance.php',
158 'courseid' => $course->id
,
159 'returnurl' => new moodle_url('/enrol/lti/index.php', ['courseid' => $course->id
, 'legacy' => $legacy]))
164 echo $OUTPUT->footer();