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 311 and 402] [Versions 311 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   * This is the external API for this report.
  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  namespace report_competency;
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  require_once("$CFG->libdir/externallib.php");
  29  
  30  use context_course;
  31  use external_api;
  32  use external_function_parameters;
  33  use external_multiple_structure;
  34  use external_single_structure;
  35  use external_value;
  36  use core_competency\external\user_competency_course_exporter;
  37  use core_user\external\user_summary_exporter;
  38  use tool_lp\external\competency_summary_exporter;
  39  use core_course\external\course_summary_exporter;
  40  
  41  /**
  42   * This is the external API for this report.
  43   *
  44   * @copyright  2015 Damyon Wiese
  45   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  46   */
  47  class external extends external_api {
  48  
  49      /**
  50       * Returns description of data_for_competency_frameworks_manage_page() parameters.
  51       *
  52       * @return \external_function_parameters
  53       */
  54      public static function data_for_report_parameters() {
  55          $courseid = new external_value(
  56              PARAM_INT,
  57              'The course id',
  58              VALUE_REQUIRED
  59          );
  60          $userid = new external_value(
  61              PARAM_INT,
  62              'The user id',
  63              VALUE_REQUIRED
  64          );
  65          $moduleid = new external_value(
  66              PARAM_INT,
  67              'The module id',
  68              VALUE_REQUIRED
  69          );
  70          $params = array(
  71              'courseid' => $courseid,
  72              'userid' => $userid,
  73              'moduleid' => $moduleid,
  74          );
  75          return new external_function_parameters($params);
  76      }
  77  
  78      /**
  79       * Loads the data required to render the report.
  80       *
  81       * @param int $courseid The course id
  82       * @param int $userid The user id
  83       * @param int $moduleid The module id
  84       * @return \stdClass
  85       */
  86      public static function data_for_report($courseid, $userid, $moduleid) {
  87          global $PAGE;
  88  
  89          $params = self::validate_parameters(
  90              self::data_for_report_parameters(),
  91              array(
  92                  'courseid' => $courseid,
  93                  'userid' => $userid,
  94                  'moduleid' => $moduleid
  95              )
  96          );
  97          $context = context_course::instance($params['courseid']);
  98          self::validate_context($context);
  99          if (!is_enrolled($context, $params['userid'], 'moodle/competency:coursecompetencygradable')) {
 100              throw new coding_exception('invaliduser');
 101          }
 102  
 103          $renderable = new output\report($params['courseid'], $params['userid'], $params['moduleid']);
 104          $renderer = $PAGE->get_renderer('report_competency');
 105  
 106          $data = $renderable->export_for_template($renderer);
 107  
 108          return $data;
 109      }
 110  
 111      /**
 112       * Returns description of data_for_report() result value.
 113       *
 114       * @return \external_description
 115       */
 116      public static function data_for_report_returns() {
 117          return new external_single_structure(array (
 118              'courseid' => new external_value(PARAM_INT, 'Course id'),
 119              'user' => user_summary_exporter::get_read_structure(),
 120              'course' => course_summary_exporter::get_read_structure(),
 121              'usercompetencies' => new external_multiple_structure(
 122                  new external_single_structure(array(
 123                      'usercompetencycourse' => user_competency_course_exporter::get_read_structure(),
 124                      'competency' => competency_summary_exporter::get_read_structure()
 125                  ))
 126              ),
 127              'pushratingstouserplans' => new external_value(PARAM_BOOL, 'True if rating is push to user plans')
 128          ));
 129      }
 130  
 131  }