MDL-74054 qbank: Miscellaneous coding style fixes
[moodle.git] / question / bank / viewquestiontext / classes / external / set_question_text_format.php
blob4e988c9a3475c2b671972556752111d8d4b3400b
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.
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/>.
17 namespace qbank_viewquestiontext\external;
19 use context_system;
20 use core_external\external_api;
21 use core_external\external_function_parameters;
22 use core_external\external_value;
23 use qbank_viewquestiontext\output\question_text_format;
25 defined('MOODLE_INTERNAL') || die();
27 require_once($CFG->dirroot . '/question/editlib.php');
29 /**
30 * External function for setting the question text format.
32 * @package qbank_viewquestiontext
33 * @copyright 2023 onwards Catalyst IT EU {@link https://catalyst-eu.net}
34 * @author Mark Johnson <mark.johnson@catalyst-eu.net>
35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37 class set_question_text_format extends external_api {
38 /**
39 * Returns description of method parameters.
41 * @return external_function_parameters
43 public static function execute_parameters(): external_function_parameters {
44 return new external_function_parameters([
45 'format' => new external_value(PARAM_INT, 'Format for the question text', VALUE_REQUIRED),
46 ]);
49 /**
50 * Returns description of method result value.
52 public static function execute_returns(): void {
55 /**
56 * Save the question text format preference for the current user.
58 * @param int $format Format for the question text.
60 public static function execute(int $format): void {
62 'format' => $format,
63 ] = self::validate_parameters(
64 self::execute_parameters(),
66 'format' => $format,
70 if (!in_array($format, [question_text_format::OFF, question_text_format::PLAIN, question_text_format::FULL])) {
71 throw new \invalid_parameter_exception('$format must be one of question_text_format::OFF, ::PLAIN or ::FULL.');
74 $context = context_system::instance();
75 self::validate_context($context);
77 \question_set_or_get_user_preference('qbshowtext', $format, 0, new \moodle_url('/'));