Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

Differences Between: [Versions 310 and 403] [Versions 311 and 403] [Versions 39 and 403] [Versions 400 and 403] [Versions 401 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  namespace mod_h5pactivity\external;
  18  
  19  use core_external\external_api;
  20  use core_external\external_function_parameters;
  21  use core_external\external_single_structure;
  22  use core_external\external_value;
  23  use core_external\external_warnings;
  24  use context_module;
  25  use mod_h5pactivity\local\manager;
  26  
  27  /**
  28   * This is the external method for triggering the course module viewed event.
  29   *
  30   * @package    mod_h5pactivity
  31   * @since      Moodle 3.9
  32   * @copyright  2020 Carlos Escobedo <carlos@moodle.com>
  33   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  34   */
  35  class view_h5pactivity extends external_api {
  36      /**
  37       * Parameters.
  38       *
  39       * @return external_function_parameters
  40       */
  41      public static function execute_parameters(): external_function_parameters {
  42          return new external_function_parameters(
  43              [
  44                  'h5pactivityid' => new external_value(PARAM_INT, 'H5P activity instance id')
  45              ]
  46          );
  47      }
  48  
  49      /**
  50       * Trigger the course module viewed event and update the module completion status.
  51       *
  52       * @param  int $h5pactivityid The h5p activity id.
  53       * @return array of warnings and the access information
  54       * @since Moodle 3.9
  55       * @throws  moodle_exception
  56       */
  57      public static function execute(int $h5pactivityid): array {
  58  
  59          $params = external_api::validate_parameters(self::execute_parameters(), [
  60              'h5pactivityid' => $h5pactivityid
  61          ]);
  62          $warnings = [];
  63  
  64          // Request and permission validation.
  65          list($course, $cm) = get_course_and_cm_from_instance($params['h5pactivityid'], 'h5pactivity');
  66  
  67          $context = context_module::instance($cm->id);
  68          self::validate_context($context);
  69  
  70          $manager = manager::create_from_coursemodule($cm);
  71          $manager->set_module_viewed($course);
  72  
  73          $result = array(
  74              'status' => true,
  75              'warnings' => $warnings,
  76          );
  77          return $result;
  78      }
  79  
  80      /**
  81       * Describes the view_h5pactivity return value.
  82       *
  83       * @return external_single_structure
  84       * @since Moodle 3.9
  85       */
  86      public static function execute_returns() {
  87          return new external_single_structure(
  88              [
  89                  'status' => new external_value(PARAM_BOOL, 'status: true if success'),
  90                  'warnings' => new external_warnings()
  91              ]
  92          );
  93      }
  94  }