Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]

   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.
  13  //
  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/>.
  16  
  17  /**
  18   * List the tool provided in a course
  19   *
  20   * @package    enrol_lti
  21   * @copyright  2016 Mark Nelson <markn@moodle.com>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  require_once(__DIR__ . '/../../config.php');
  26  require_once($CFG->dirroot.'/enrol/lti/lib.php');
  27  
  28  $courseid = required_param('courseid', PARAM_INT);
  29  $action = optional_param('action', '', PARAM_ALPHA);
  30  if ($action) {
  31      require_sesskey();
  32      $instanceid = required_param('instanceid', PARAM_INT);
  33      $instance = $DB->get_record('enrol', array('id' => $instanceid), '*', MUST_EXIST);
  34  }
  35  $confirm = optional_param('confirm', 0, PARAM_INT);
  36  
  37  $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
  38  
  39  $context = context_course::instance($course->id);
  40  
  41  require_login($course);
  42  require_capability('moodle/course:enrolreview', $context);
  43  
  44  $ltiplugin = enrol_get_plugin('lti');
  45  $canconfig = has_capability('moodle/course:enrolconfig', $context);
  46  $pageurl = new moodle_url('/enrol/lti/index.php', array('courseid' => $courseid));
  47  
  48  $PAGE->set_url($pageurl);
  49  $PAGE->set_title(get_string('course') . ': ' . $course->fullname);
  50  $PAGE->set_pagelayout('admin');
  51  
  52  // Check if we want to perform any actions.
  53  if ($action) {
  54      if ($action === 'delete') {
  55          if ($ltiplugin->can_delete_instance($instance)) {
  56              if ($confirm) {
  57                  $ltiplugin->delete_instance($instance);
  58                  redirect($PAGE->url);
  59              }
  60  
  61              $yesurl = new moodle_url('/enrol/lti/index.php',
  62                  array('courseid' => $course->id,
  63                      'action' => 'delete',
  64                      'instanceid' => $instance->id,
  65                      'confirm' => 1,
  66                      'sesskey' => sesskey())
  67                  );
  68              $displayname = $ltiplugin->get_instance_name($instance);
  69              $users = $DB->count_records('user_enrolments', array('enrolid' => $instance->id));
  70              if ($users) {
  71                  $message = markdown_to_html(get_string('deleteinstanceconfirm', 'enrol',
  72                      array('name' => $displayname,
  73                            'users' => $users)));
  74              } else {
  75                  $message = markdown_to_html(get_string('deleteinstancenousersconfirm', 'enrol',
  76                      array('name' => $displayname)));
  77              }
  78              echo $OUTPUT->header();
  79              echo $OUTPUT->confirm($message, $yesurl, $PAGE->url);
  80              echo $OUTPUT->footer();
  81              die();
  82          }
  83      } else if ($action === 'disable') {
  84          if ($ltiplugin->can_hide_show_instance($instance)) {
  85              if ($instance->status != ENROL_INSTANCE_DISABLED) {
  86                  $ltiplugin->update_status($instance, ENROL_INSTANCE_DISABLED);
  87                  redirect($PAGE->url);
  88              }
  89          }
  90      } else if ($action === 'enable') {
  91          if ($ltiplugin->can_hide_show_instance($instance)) {
  92              if ($instance->status != ENROL_INSTANCE_ENABLED) {
  93                  $ltiplugin->update_status($instance, ENROL_INSTANCE_ENABLED);
  94                  redirect($PAGE->url);
  95              }
  96          }
  97      }
  98  }
  99  
 100  echo $OUTPUT->header();
 101  echo $OUTPUT->heading(get_string('toolsprovided', 'enrol_lti'));
 102  echo "<p>" .get_string('toolsprovided_help', 'enrol_lti') . "</p>";
 103  echo "<p class=helplink>" . $OUTPUT->doc_link('enrol/lti/index',
 104      get_string('morehelp')) ."</p>";
 105  
 106  if (\enrol_lti\helper::count_lti_tools(array('courseid' => $courseid)) > 0) {
 107      $table = new \enrol_lti\manage_table($courseid);
 108      $table->define_baseurl($pageurl);
 109      $table->out(50, false);
 110  } else {
 111      $notify = new \core\output\notification(get_string('notoolsprovided', 'enrol_lti'),
 112          \core\output\notification::NOTIFY_WARNING);
 113      echo $OUTPUT->render($notify);
 114  }
 115  
 116  if ($ltiplugin->can_add_instance($course->id)) {
 117      echo $OUTPUT->single_button(new moodle_url('/enrol/editinstance.php',
 118          array(
 119              'type' => 'lti',
 120              'courseid' => $course->id,
 121              'returnurl' => new moodle_url('/enrol/lti/index.php', array('courseid' => $course->id)))
 122          ),
 123          get_string('add'));
 124  }
 125  
 126  echo $OUTPUT->footer();