Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 400 and 402] [Versions 400 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   * Web service to fetch module data.
  19   *
  20   * @package    block_accessreview
  21   * @copyright  2020 onward Brickfield Education Labs Ltd, https://www.brickfield.ie
  22   * @author     2020 Max Larkin <max@brickfieldlabs.ie>
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  namespace block_accessreview\external;
  27  
  28  use external_api;
  29  use external_function_parameters;
  30  use external_multiple_structure;
  31  use external_single_structure;
  32  use external_value;
  33  use tool_brickfield\manager;
  34  
  35  defined('MOODLE_INTERNAL') || die();
  36  require_once($CFG->libdir . '/externallib.php');
  37  
  38  /**
  39   * Web service to fetch module data.
  40   *
  41   * @package    block_accessreview
  42   * @copyright  2020 onward Brickfield Education Labs Ltd, https://www.brickfield.ie
  43   * @author     2020 Max Larkin <max@brickfieldlabs.ie>
  44   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  45   */
  46  class get_module_data extends external_api {
  47      /**
  48       * Describes the parameters.
  49       *
  50       * @return external_function_parameters
  51       */
  52      public static function execute_parameters() {
  53          return new external_function_parameters([
  54              'courseid' => new external_value(PARAM_INT, 'The course id to obtain results for.', VALUE_REQUIRED),
  55          ]);
  56      }
  57  
  58      /**
  59       * Execute the service.
  60       *
  61       * @param int $courseid
  62       * @return array
  63       */
  64      public static function execute(int $courseid) {
  65          [
  66              'courseid' => $courseid,
  67          ] = self::validate_parameters(self::execute_parameters(), [
  68              'courseid' => $courseid,
  69          ]);
  70  
  71          $context = \context_course::instance($courseid);
  72          self::validate_context($context);
  73  
  74          require_capability('block/accessreview:view', $context);
  75  
  76          return array_values(manager::get_cm_summary_for_course($courseid));
  77      }
  78  
  79      /**
  80       * Describes the return structure of the service..
  81       *
  82       * @return external_multiple_structure
  83       */
  84      public static function execute_returns() {
  85          return new external_multiple_structure(
  86              new external_single_structure(
  87                  [
  88                      'cmid' => new external_value(PARAM_INT, 'ID'),
  89                      'numerrors' => new external_value(PARAM_INT, 'Number of errors.'),
  90                      'numchecks' => new external_value(PARAM_INT, 'Number of checks.'),
  91                  ]
  92              )
  93          );
  94      }
  95  }