Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
 * Class implementing WS tool_courserating_course_rating_popup
19
 *
20
 * @package    tool_courserating
21
 * @copyright  2023 Marina Glancy
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
namespace tool_courserating\external;
26
 
27
use external_function_parameters;
28
use external_single_structure;
29
use external_api;
30
use external_value;
31
 
32
defined('MOODLE_INTERNAL') || die;
33
 
34
require_once($CFG->libdir . '/externallib.php');
35
 
36
/**
37
 * Implementation of web service tool_courserating_course_rating_popup
38
 *
39
 * @package    tool_courserating
40
 * @copyright  2023 Marina Glancy
41
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
42
 */
43
class course_rating_popup extends external_api {
44
 
45
    /**
46
     * Describes the parameters for tool_courserating_course_rating_popup
47
     *
48
     * @return external_function_parameters
49
     */
50
    public static function execute_parameters(): external_function_parameters {
51
        return new external_function_parameters([
52
            'courseid' => new external_value(PARAM_INT, 'Course id'),
53
        ]);
54
    }
55
 
56
    /**
57
     * Implementation of web service tool_courserating_course_rating_popup
58
     *
59
     * @param mixed $courseid
60
     */
61
    public static function execute($courseid) {
62
        global $PAGE, $OUTPUT, $CFG;
63
        require_once($CFG->dirroot . '/' . $CFG->admin . '/tool/courserating/lib.php');
64
 
65
        // Basically copied from the core_get_fragment WS except for login check.
66
 
67
        // Hack alert: Set a default URL to stop the annoying debug.
68
        $PAGE->set_url('/');
69
        // Hack alert: Forcing bootstrap_renderer to initiate moodle page.
70
        $OUTPUT->header();
71
 
72
        // Overwriting page_requirements_manager with the fragment one so only JS included from
73
        // this point is returned to the user.
74
        $PAGE->start_collecting_javascript_requirements();
75
        $data = tool_courserating_output_fragment_course_ratings_popup(['courseid' => $courseid]);
76
        $jsfooter = $PAGE->requires->get_end_code();
77
        $output = ['html' => $data, 'javascript' => $jsfooter];
78
        return $output;
79
    }
80
 
81
    /**
82
     * Describe the return structure for tool_courserating_course_rating_popup
83
     *
84
     * @return external_single_structure
85
     */
86
    public static function execute_returns(): external_single_structure {
87
        return new external_single_structure(
88
            [
89
                'html' => new external_value(PARAM_RAW, 'HTML fragment.'),
90
                'javascript' => new external_value(PARAM_RAW, 'JavaScript fragment'),
91
            ]
92
        );
93
    }
94
}