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