1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - https://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 |
* Provides {@see \mod_subcourse\external\view_subcourse} class.
|
|
|
19 |
*
|
|
|
20 |
* @copyright 2020 David Mudrák <david@moodle.com>
|
|
|
21 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
22 |
*/
|
|
|
23 |
|
|
|
24 |
namespace mod_subcourse\external;
|
|
|
25 |
|
|
|
26 |
defined('MOODLE_INTERNAL') || die();
|
|
|
27 |
|
|
|
28 |
require_once($CFG->libdir . '/externallib.php');
|
|
|
29 |
|
|
|
30 |
use external_api;
|
|
|
31 |
use external_function_parameters;
|
|
|
32 |
use external_multiple_structure;
|
|
|
33 |
use external_single_structure;
|
|
|
34 |
use external_value;
|
|
|
35 |
use external_warnings;
|
|
|
36 |
|
|
|
37 |
/**
|
|
|
38 |
* Implements the mod_subcourse_view_subcourse external function.
|
|
|
39 |
*
|
|
|
40 |
* @package mod_subcourse
|
|
|
41 |
* @category external
|
|
|
42 |
* @copyright 2020 David Mudrák <david@moodle.com>
|
|
|
43 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
44 |
*/
|
|
|
45 |
class view_subcourse extends external_api {
|
|
|
46 |
|
|
|
47 |
/**
|
|
|
48 |
* Describes the parameters for view_subcourse.
|
|
|
49 |
*
|
|
|
50 |
* @return external_function_parameters
|
|
|
51 |
*/
|
|
|
52 |
public static function execute_parameters() {
|
|
|
53 |
|
|
|
54 |
return new external_function_parameters([
|
|
|
55 |
'subcourseid' => new external_value(PARAM_INT, 'Subcourse instance id'),
|
|
|
56 |
]);
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
/**
|
|
|
60 |
* Trigger the course module viewed event and update the module completion status.
|
|
|
61 |
*
|
|
|
62 |
* @param int $subcourseid subcourse instance id
|
|
|
63 |
* @return array of warnings and status result
|
|
|
64 |
* @throws moodle_exception
|
|
|
65 |
*/
|
|
|
66 |
public static function execute($subcourseid) {
|
|
|
67 |
global $CFG, $DB;
|
|
|
68 |
require_once($CFG->dirroot . '/mod/subcourse/locallib.php');
|
|
|
69 |
|
|
|
70 |
$params = ['subcourseid' => $subcourseid];
|
|
|
71 |
$params = self::validate_parameters(self::execute_parameters(), $params);
|
|
|
72 |
$warnings = [];
|
|
|
73 |
|
|
|
74 |
$subcourse = $DB->get_record('subcourse', ['id' => $params['subcourseid']], '*', MUST_EXIST);
|
|
|
75 |
list($course, $cm) = get_course_and_cm_from_instance($subcourse, 'subcourse');
|
|
|
76 |
$context = \context_module::instance($cm->id);
|
|
|
77 |
|
|
|
78 |
self::validate_context($context);
|
|
|
79 |
|
|
|
80 |
subcourse_set_module_viewed($subcourse, $context, $course, $cm);
|
|
|
81 |
|
|
|
82 |
$result = [
|
|
|
83 |
'status' => true,
|
|
|
84 |
'warnings' => $warnings,
|
|
|
85 |
];
|
|
|
86 |
|
|
|
87 |
return $result;
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
/**
|
|
|
91 |
* Describes the view_subcourse return value.
|
|
|
92 |
*
|
|
|
93 |
* @return external_single_structure
|
|
|
94 |
*/
|
|
|
95 |
public static function execute_returns() {
|
|
|
96 |
return new external_single_structure(
|
|
|
97 |
[
|
|
|
98 |
'status' => new external_value(PARAM_BOOL, 'Status: true if success'),
|
|
|
99 |
'warnings' => new external_warnings(),
|
|
|
100 |
]
|
|
|
101 |
);
|
|
|
102 |
}
|
|
|
103 |
}
|