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_value;
22
 
23
/**
24
 * External service to store unsent messages in the session.
25
 *
26
 * @package   core_message
27
 * @category  external
28
 * @copyright 2024 David Woloszyn <david.woloszyn@moodle.com>
29
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30
 */
31
class set_unsent_message extends external_api {
32
    /**
33
     * Returns description of method parameters.
34
     *
35
     * @return external_function_parameters
36
     */
37
    public static function execute_parameters(): external_function_parameters {
38
        return new external_function_parameters([
39
            'message' => new external_value(PARAM_TEXT, 'The message string', VALUE_REQUIRED, ''),
40
            'conversationid' => new external_value(PARAM_INT, 'The conversation id', VALUE_REQUIRED, 0),
41
            'otheruserid' => new external_value(PARAM_INT, 'The other user id', VALUE_REQUIRED, 0),
42
        ]);
43
    }
44
 
45
    /**
46
     * Store the unsent message, along with conversation params, in the session for later retrieval.
47
     *
48
     * @param string $message The message string.
49
     * @param int $conversationid The conversation id.
50
     * @param int $otheruserid The other user id.
51
     */
52
    public static function execute(string $message, int $conversationid, int $otheruserid): void {
53
        global $SESSION, $USER;
54
 
55
        self::validate_parameters(self::execute_parameters(), [
56
            'message' => $message,
57
            'conversationid' => $conversationid,
58
            'otheruserid' => $otheruserid,
59
        ]);
60
 
61
        $usercontext = \context_user::instance($USER->id);
62
        self::validate_context($usercontext);
63
 
64
        $SESSION->core_message_set_unsent_message = [
65
            'message' => $message,
66
            'conversationid' => $conversationid,
67
            'otheruserid' => $otheruserid,
68
        ];
69
    }
70
 
71
    /**
72
     * Describes the data returned from the external function.
73
     */
74
    public static function execute_returns(): void {
75
    }
76
}