Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

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

   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  report_helper::save_selected_report($id, $navurl);
  77  
  78  $output = $PAGE->get_renderer('report_competency');
  79  
  80  echo $output->header();
  81  $pluginname = get_string('pluginname', 'report_competency');
  82  report_helper::print_report_selector($pluginname);
  83  
  84  $baseurl = new moodle_url('/report/competency/index.php');
  85  $nav = new \report_competency\output\user_course_navigation($currentuser, $course->id, $baseurl, $currentmodule);
  86  $top = $output->render($nav);
  87  if ($currentuser > 0) {
  88      $user = core_user::get_user($currentuser);
  89      $usercontext = context_user::instance($currentuser);
  90      $userheading = array(
  91          'heading' => fullname($user, has_capability('moodle/site:viewfullnames', $context)),
  92          'user' => $user,
  93          'usercontext' => $usercontext
  94      );
  95      if ($currentmodule > 0) {
  96          $title = get_string('filtermodule', 'report_competency', format_string($cm->name));
  97      }
  98      $top .= $output->context_header($userheading, 3);
  99  }
 100  echo $output->container($top, 'clearfix');
 101  echo $output->heading($title, 3);
 102  
 103  if ($currentuser > 0) {
 104      $page = new \report_competency\output\report($course->id, $currentuser, $currentmodule);
 105      echo $output->render($page);
 106  } else {
 107      echo $output->container('', 'clearfix');
 108      echo $output->notify_problem(get_string('noparticipants', 'tool_lp'));
 109  }
 110  echo $output->footer();