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  declare(strict_types=1);
  18  
  19  namespace core_reportbuilder\external\conditions;
  20  
  21  use external_api;
  22  use external_function_parameters;
  23  use external_single_structure;
  24  use external_value;
  25  use core_reportbuilder\manager;
  26  use core_reportbuilder\permission;
  27  use core_reportbuilder\external\custom_report_conditions_exporter;
  28  
  29  defined('MOODLE_INTERNAL') || die();
  30  
  31  global $CFG;
  32  require_once("{$CFG->libdir}/externallib.php");
  33  
  34  /**
  35   * External method for resetting report conditions
  36   *
  37   * @package     core_reportbuilder
  38   * @copyright   2021 Paul Holden <paulh@moodle.com>
  39   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  40   */
  41  class reset extends external_api {
  42  
  43      /**
  44       * External method parameters
  45       *
  46       * @return external_function_parameters
  47       */
  48      public static function execute_parameters(): external_function_parameters {
  49          return new external_function_parameters([
  50              'reportid' => new external_value(PARAM_INT, 'Report ID'),
  51          ]);
  52      }
  53  
  54      /**
  55       * External method execution
  56       *
  57       * @param int $reportid
  58       * @return array
  59       */
  60      public static function execute(int $reportid): array {
  61          global $PAGE, $OUTPUT;
  62  
  63          [
  64              'reportid' => $reportid,
  65          ] = self::validate_parameters(self::execute_parameters(), [
  66              'reportid' => $reportid,
  67          ]);
  68  
  69          $report = manager::get_report_from_id($reportid);
  70  
  71          self::validate_context($report->get_context());
  72          permission::require_can_edit_report($report->get_report_persistent());
  73  
  74          $report->set_condition_values([]);
  75  
  76          // Set current URL and force bootstrap_renderer to initiate moodle page.
  77          $PAGE->set_url('/');
  78          $OUTPUT->header();
  79          $PAGE->start_collecting_javascript_requirements();
  80  
  81          $exporter = new custom_report_conditions_exporter(null, ['report' => $report]);
  82  
  83          $export = $exporter->export($PAGE->get_renderer('core'));
  84          $export->javascript = $PAGE->requires->get_end_code();
  85  
  86          return (array) $export;
  87      }
  88  
  89      /**
  90       * External method return value
  91       *
  92       * @return external_value
  93       */
  94      public static function execute_returns(): external_single_structure {
  95          return custom_report_conditions_exporter::get_read_structure();
  96      }
  97  }