Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401]

   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   * This page lets users to manage site wide competencies.
  19   *
  20   * @package    report_competency
  21   * @copyright  2015 Damyon Wiese
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  use core\report_helper;
  26  
  27  require_once(__DIR__ . '/../../config.php');
  28  
  29  $id = required_param('id', PARAM_INT);
  30  
  31  $params = array('id' => $id);
  32  $course = $DB->get_record('course', $params, '*', MUST_EXIST);
  33  require_login($course);
  34  $context = context_course::instance($course->id);
  35  $currentuser = optional_param('user', null, PARAM_INT);
  36  $currentmodule = optional_param('mod', null, PARAM_INT);
  37  if ($currentmodule > 0) {
  38      $cm = get_coursemodule_from_id('', $currentmodule, 0, false, MUST_EXIST);
  39      $context = context_module::instance($cm->id);
  40  }
  41  
  42  // Fetch current active group.
  43  $groupmode = groups_get_course_groupmode($course);
  44  $currentgroup = groups_get_course_group($course, true);
  45  if (empty($currentuser)) {
  46      $gradable = get_enrolled_users($context, 'moodle/competency:coursecompetencygradable', $currentgroup, 'u.id', null, 0, 1);
  47      if (empty($gradable)) {
  48          $currentuser = 0;
  49      } else {
  50          $currentuser = array_pop($gradable)->id;
  51      }
  52  } else {
  53      $gradable = get_enrolled_users($context, 'moodle/competency:coursecompetencygradable', $currentgroup, 'u.id');
  54      if (count($gradable) == 0) {
  55          $currentuser = 0;
  56      } else if (!in_array($currentuser, array_keys($gradable))) {
  57          $currentuser = array_shift($gradable)->id;
  58      }
  59  }
  60  
  61  $urlparams = array('id' => $id);
  62  $navurl = new moodle_url('/report/competency/index.php', $urlparams);
  63  $urlparams['user'] = $currentuser;
  64  $urlparams['mod'] = $currentmodule;
  65  $url = new moodle_url('/report/competency/index.php', $urlparams);
  66  
  67  $title = get_string('pluginname', 'report_competency');
  68  $coursename = format_string($course->fullname, true, array('context' => $context));
  69  
  70  $PAGE->navigation->override_active_url($navurl);
  71  $PAGE->set_url($url);
  72  $PAGE->set_title($title);
  73  $PAGE->set_heading($coursename);
  74  $PAGE->set_pagelayout('incourse');
  75  
  76  $output = $PAGE->get_renderer('report_competency');
  77  
  78  echo $output->header();
  79  $pluginname = get_string('pluginname', 'report_competency');
  80  report_helper::print_report_selector($pluginname);
  81  
  82  $baseurl = new moodle_url('/report/competency/index.php');
  83  $nav = new \report_competency\output\user_course_navigation($currentuser, $course->id, $baseurl, $currentmodule);
  84  $top = $output->render($nav);
  85  if ($currentuser > 0) {
  86      $user = core_user::get_user($currentuser);
  87      $usercontext = context_user::instance($currentuser);
  88      $userheading = array(
  89          'heading' => fullname($user, has_capability('moodle/site:viewfullnames', $context)),
  90          'user' => $user,
  91          'usercontext' => $usercontext
  92      );
  93      if ($currentmodule > 0) {
  94          $title = get_string('filtermodule', 'report_competency', format_string($cm->name));
  95      }
  96      $top .= $output->context_header($userheading, 3);
  97  }
  98  echo $output->container($top, 'clearfix');
  99  
 100  if ($currentuser > 0) {
 101      $page = new \report_competency\output\report($course->id, $currentuser, $currentmodule);
 102      echo $output->render($page);
 103  } else {
 104      echo $output->container('', 'clearfix');
 105      echo $output->notify_problem(get_string('noparticipants', 'tool_lp'));
 106  }
 107  echo $output->footer();