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 mod_quiz\external; 18 19 defined('MOODLE_INTERNAL') || die(); 20 21 require_once($CFG->libdir . '/externallib.php'); 22 require_once($CFG->dirroot . '/question/editlib.php'); 23 require_once($CFG->dirroot . '/mod/quiz/locallib.php'); 24 25 use external_function_parameters; 26 use external_single_structure; 27 use external_value; 28 use external_api; 29 30 /** 31 * Update the filter condition for a random question. 32 * 33 * @package mod_quiz 34 * @copyright 2022 Catalyst IT Australia Pty Ltd 35 * @author Nathan Nguyen <nathannguyen@catalyst-au.net> 36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 37 */ 38 class update_filter_condition extends external_api { 39 40 /** 41 * Parameters for the web service function 42 * 43 * @return external_function_parameters 44 */ 45 public static function execute_parameters(): external_function_parameters { 46 return new external_function_parameters ([ 47 'cmid' => new external_value(PARAM_INT, 'The cmid of the quiz'), 48 'slotid' => new external_value(PARAM_INT, 'The quiz slot ID for the random question.'), 49 'filtercondition' => new external_value(PARAM_TEXT, 'Filter condition'), 50 ]); 51 } 52 53 /** 54 * Add random questions. 55 * 56 * @param int $cmid course module id 57 * @param int $slotid The quiz slot id 58 * @param string $filtercondition 59 * @return array result 60 */ 61 public static function execute( 62 int $cmid, 63 int $slotid, 64 string $filtercondition, 65 ): array { 66 global $DB; 67 68 [ 69 'cmid' => $cmid, 70 'slotid' => $slotid, 71 'filtercondition' => $filtercondition, 72 ] = self::validate_parameters(self::execute_parameters(), [ 73 'cmid' => $cmid, 74 'slotid' => $slotid, 75 'filtercondition' => $filtercondition, 76 ]); 77 78 // Validate context. 79 $thiscontext = \context_module::instance($cmid); 80 self::validate_context($thiscontext); 81 require_capability('mod/quiz:manage', $thiscontext); 82 83 // Update filter condition. 84 $setparams = [ 85 'itemid' => $slotid, 86 'questionarea' => 'slot', 87 'component' => 'mod_quiz', 88 ]; 89 $DB->set_field('question_set_references', 'filtercondition', $filtercondition, $setparams); 90 91 return ['message' => get_string('updatefilterconditon_success', 'mod_quiz')]; 92 } 93 94 /** 95 * Returns description of method result value. 96 * 97 * @return external_value 98 */ 99 public static function execute_returns() { 100 return new external_single_structure([ 101 'message' => new external_value(PARAM_TEXT, 'Message', VALUE_OPTIONAL) 102 ]); 103 } 104 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body