Skip to content

Commit 74f0ebb

Browse files
committed
Revert "M4.2: external APIs: update to use new base classes #711061"
... while we still support older Moodle versions. This reverts commit cd59beb.
1 parent 96e014a commit 74f0ebb

File tree

2 files changed

+38
-39
lines changed

2 files changed

+38
-39
lines changed

classes/external.php

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@
1616

1717
namespace filter_embedquestion;
1818

19-
use core_external\external_api;
20-
use core_external\external_description;
21-
use core_external\external_function_parameters;
22-
use core_external\external_multiple_structure;
23-
use core_external\external_single_structure;
24-
use core_external\external_value;
19+
defined('MOODLE_INTERNAL') || die();
20+
21+
global $CFG;
22+
require_once($CFG->libdir . '/externallib.php');
2523

2624
/**
2725
* External API for AJAX calls.
@@ -30,29 +28,29 @@
3028
* @copyright 2018 The Open University
3129
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3230
*/
33-
class external extends external_api {
31+
class external extends \external_api {
3432
/**
3533
* Returns parameter types for get_status function.
3634
*
37-
* @return external_function_parameters Parameters
35+
* @return \external_function_parameters Parameters
3836
*/
39-
public static function get_sharable_question_choices_parameters(): external_function_parameters {
40-
return new external_function_parameters([
41-
'courseid' => new external_value(PARAM_INT, 'Course id.'),
42-
'categoryidnumber' => new external_value(PARAM_RAW, 'Idnumber of the question category.'),
37+
public static function get_sharable_question_choices_parameters(): \external_function_parameters {
38+
return new \external_function_parameters([
39+
'courseid' => new \external_value(PARAM_INT, 'Course id.'),
40+
'categoryidnumber' => new \external_value(PARAM_RAW, 'Idnumber of the question category.'),
4341
]);
4442
}
4543

4644
/**
4745
* Returns result type for get_status function.
4846
*
49-
* @return external_description Result type
47+
* @return \external_description Result type
5048
*/
51-
public static function get_sharable_question_choices_returns(): external_description {
52-
return new external_multiple_structure(
53-
new external_single_structure([
54-
'value' => new external_value(PARAM_RAW, 'Choice value to return from the form.'),
55-
'label' => new external_value(PARAM_RAW, 'Choice name, to display to users.'),
49+
public static function get_sharable_question_choices_returns(): \external_description {
50+
return new \external_multiple_structure(
51+
new \external_single_structure([
52+
'value' => new \external_value(PARAM_RAW, 'Choice value to return from the form.'),
53+
'label' => new \external_value(PARAM_RAW, 'Choice name, to display to users.'),
5654
]));
5755
}
5856

@@ -107,52 +105,52 @@ public static function get_sharable_question_choices(int $courseid, string $cate
107105
/**
108106
* Returns parameter types for get_embed_code function.
109107
*
110-
* @return external_function_parameters Parameters
108+
* @return \external_function_parameters Parameters
111109
*/
112-
public static function get_embed_code_parameters(): external_function_parameters {
110+
public static function get_embed_code_parameters(): \external_function_parameters {
113111
// We can't use things like PARAM_INT for things like variant, because it is
114112
// and int of '' for not set.
115-
return new external_function_parameters([
116-
'courseid' => new external_value(PARAM_INT,
113+
return new \external_function_parameters([
114+
'courseid' => new \external_value(PARAM_INT,
117115
'Course id.'),
118-
'categoryidnumber' => new external_value(PARAM_RAW,
116+
'categoryidnumber' => new \external_value(PARAM_RAW,
119117
'Id number of the question category.'),
120-
'questionidnumber' => new external_value(PARAM_RAW,
118+
'questionidnumber' => new \external_value(PARAM_RAW,
121119
'Id number of the question.'),
122-
'iframedescription' => new external_value(PARAM_TEXT,
120+
'iframedescription' => new \external_value(PARAM_TEXT,
123121
'Iframe description.'),
124-
'behaviour' => new external_value(PARAM_RAW,
122+
'behaviour' => new \external_value(PARAM_RAW,
125123
'Question behaviour.'),
126-
'maxmark' => new external_value(PARAM_RAW_TRIMMED,
124+
'maxmark' => new \external_value(PARAM_RAW_TRIMMED,
127125
'Question maximum mark (float or "").'),
128-
'variant' => new external_value(PARAM_RAW_TRIMMED,
126+
'variant' => new \external_value(PARAM_RAW_TRIMMED,
129127
'Question variant (int or "").'),
130-
'correctness' => new external_value(PARAM_RAW_TRIMMED,
128+
'correctness' => new \external_value(PARAM_RAW_TRIMMED,
131129
'Whether to show question correctness (1/0/"") for show, hide or default.'),
132-
'marks' => new external_value(PARAM_RAW_TRIMMED,
130+
'marks' => new \external_value(PARAM_RAW_TRIMMED,
133131
'Wheter to show mark information (0/1/2/"") for hide, show max only, show mark and max or default.'),
134-
'markdp' => new external_value(PARAM_RAW_TRIMMED,
132+
'markdp' => new \external_value(PARAM_RAW_TRIMMED,
135133
'Decimal places to use when outputting grades.'),
136-
'feedback' => new external_value(PARAM_RAW_TRIMMED,
134+
'feedback' => new \external_value(PARAM_RAW_TRIMMED,
137135
'Whether to show specific feedback (1/0/"") for show, hide or default.'),
138-
'generalfeedback' => new external_value(PARAM_RAW_TRIMMED,
136+
'generalfeedback' => new \external_value(PARAM_RAW_TRIMMED,
139137
'Whether to show general feedback (1/0/"") for show, hide or default.'),
140-
'rightanswer' => new external_value(PARAM_RAW_TRIMMED,
138+
'rightanswer' => new \external_value(PARAM_RAW_TRIMMED,
141139
'Whether to show the automatically generated right answer display (1/0/"") for show, hide or default.'),
142-
'history' => new external_value(PARAM_RAW_TRIMMED,
140+
'history' => new \external_value(PARAM_RAW_TRIMMED,
143141
'Whether to show the response history (1/0/"") for show, hide or default.'),
144-
'forcedlanguage' => new external_value(PARAM_LANG,
142+
'forcedlanguage' => new \external_value(PARAM_LANG,
145143
'Whether to force the UI language of the question. Lang code or empty string.'),
146144
]);
147145
}
148146

149147
/**
150148
* Returns result type for for get_embed_code function.
151149
*
152-
* @return external_description Result type
150+
* @return \external_description Result type
153151
*/
154-
public static function get_embed_code_returns(): external_description {
155-
return new external_value(PARAM_RAW, 'Embed code to show this question with those options.');
152+
public static function get_embed_code_returns(): \external_description {
153+
return new \external_value(PARAM_RAW, 'Embed code to show this question with those options.');
156154
}
157155

158156
/**

tests/external_test.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
* @copyright 2018 The Open University
2424
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2525
* @covers \filter_embedquestion\external
26+
* @runTestsInSeparateProcesses
2627
*/
2728
class external_test extends \advanced_testcase {
2829

0 commit comments

Comments
 (0)