Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 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 core_message\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
 
24
/**
25
 * External service to get unsent messages from the session.
26
 *
27
 * @package   core_message
28
 * @category  external
29
 * @copyright 2024 David Woloszyn <david.woloszyn@moodle.com>
30
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31
 */
32
class get_unsent_message extends external_api {
33
    /**
34
     * Returns description of method parameters.
35
     *
36
     * @return external_function_parameters
37
     */
38
    public static function execute_parameters(): external_function_parameters {
39
        return new external_function_parameters([]);
40
    }
41
 
42
    /**
43
     * Get unsent messages from the session.
44
     */
45
    public static function execute(): array {
46
        global $SESSION, $USER;
47
 
48
        $usercontext = \context_user::instance($USER->id);
49
        self::validate_context($usercontext);
50
 
51
        $message = isset($SESSION->core_message_set_unsent_message) ? $SESSION->core_message_set_unsent_message : [];
52
        // Unset this as we only want to return this once.
53
        unset($SESSION->core_message_set_unsent_message);
54
 
55
        return $message;
56
    }
57
 
58
    /**
59
     * Describe the return structure of the external service.
60
     *
61
     * @return external_value
62
     */
63
    public static function execute_returns(): external_single_structure {
64
        return new external_single_structure([
65
            'message' => new external_value(PARAM_TEXT, 'The message string', VALUE_OPTIONAL, ''),
66
            'conversationid' => new external_value(PARAM_INT, 'The conversation id', VALUE_OPTIONAL, 0),
67
            'otheruserid' => new external_value(PARAM_INT, 'The other user id', VALUE_OPTIONAL, 0),
68
        ]);
69
    }
70
}