@@ -64,7 +64,9 @@ public function __construct(
64
64
* @throws moodle_exception
65
65
*/
66
66
public function get_question_edit_form (?string $ questionstate ): question_edit_form_response {
67
- $ options ['multipart ' ] = $ this ->transform_to_multipart ([], $ questionstate );
67
+ global $ PAGE ;
68
+
69
+ $ options ['multipart ' ] = $ this ->transform_to_multipart (['context ' => $ PAGE ->context ->id ], $ questionstate );
68
70
$ response = $ this ->post_and_maybe_retry ('/options ' , $ options );
69
71
return api_utils::convert_response_to_class ($ response , question_edit_form_response::class);
70
72
}
@@ -80,11 +82,12 @@ public function get_question_edit_form(?string $questionstate): question_edit_fo
80
82
* @throws moodle_exception
81
83
*/
82
84
public function create_question (?string $ currentstate , object $ formdata ): question_response {
85
+ global $ PAGE ;
86
+
83
87
$ options ['multipart ' ] = $ this ->transform_to_multipart (
84
88
[
85
89
'form_data ' => $ formdata ,
86
- // TODO: Send an actual context.
87
- 'context ' => 1 ,
90
+ 'context ' => $ PAGE ->context ->id ,
88
91
],
89
92
$ currentstate ,
90
93
);
@@ -104,7 +107,15 @@ public function create_question(?string $currentstate, object $formdata): questi
104
107
* @throws moodle_exception
105
108
*/
106
109
public function start_attempt (string $ questionstate , int $ variant ): attempt_started {
107
- $ options ['multipart ' ] = $ this ->transform_to_multipart (['variant ' => $ variant ], $ questionstate );
110
+ global $ PAGE ;
111
+
112
+ $ options ['multipart ' ] = $ this ->transform_to_multipart (
113
+ [
114
+ 'variant ' => $ variant ,
115
+ 'context ' => $ PAGE ->context ->id ,
116
+ ],
117
+ $ questionstate ,
118
+ );
108
119
$ response = $ this ->post_and_maybe_retry ('/attempt/start ' , $ options );
109
120
return api_utils::convert_response_to_class ($ response , attempt_started::class);
110
121
}
@@ -123,11 +134,14 @@ public function start_attempt(string $questionstate, int $variant): attempt_star
123
134
*/
124
135
public function view_attempt (string $ questionstate , string $ attemptstate , ?string $ scoringstate = null ,
125
136
?object $ response = null ): attempt {
137
+ global $ PAGE ;
138
+
126
139
$ options ['multipart ' ] = $ this ->transform_to_multipart (
127
140
[
128
141
'attempt_state ' => $ attemptstate ,
129
142
'scoring_state ' => $ scoringstate ,
130
143
'response ' => $ response ,
144
+ 'context ' => $ PAGE ->context ->id ,
131
145
],
132
146
$ questionstate ,
133
147
);
@@ -149,12 +163,15 @@ public function view_attempt(string $questionstate, string $attemptstate, ?strin
149
163
*/
150
164
public function score_attempt (string $ questionstate , string $ attemptstate , ?string $ scoringstate ,
151
165
object $ response ): attempt_scored {
166
+ global $ PAGE ;
167
+
152
168
$ options ['multipart ' ] = $ this ->transform_to_multipart (
153
169
[
154
170
'attempt_state ' => $ attemptstate ,
155
171
'scoring_state ' => $ scoringstate ,
156
172
'response ' => $ response ,
157
173
'generate_hint ' => false ,
174
+ 'context ' => $ PAGE ->context ->id ,
158
175
],
159
176
$ questionstate
160
177
);
0 commit comments