2 // This file is part of Moodle - http://moodle.org/
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.
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
;
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');
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
{
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
),
50 * Returns description of method result value.
52 public static function execute_returns(): void
{
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
{
63 ] = self
::validate_parameters(
64 self
::execute_parameters(),
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('/'));