Skip to content

Commit 9e71efb

Browse files
authored
feat: send the context id to application server
1 parent e15933a commit 9e71efb

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

classes/local/api/package_api.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ public function __construct(
6464
* @throws moodle_exception
6565
*/
6666
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);
6870
$response = $this->post_and_maybe_retry('/options', $options);
6971
return api_utils::convert_response_to_class($response, question_edit_form_response::class);
7072
}
@@ -80,11 +82,12 @@ public function get_question_edit_form(?string $questionstate): question_edit_fo
8082
* @throws moodle_exception
8183
*/
8284
public function create_question(?string $currentstate, object $formdata): question_response {
85+
global $PAGE;
86+
8387
$options['multipart'] = $this->transform_to_multipart(
8488
[
8589
'form_data' => $formdata,
86-
// TODO: Send an actual context.
87-
'context' => 1,
90+
'context' => $PAGE->context->id,
8891
],
8992
$currentstate,
9093
);
@@ -104,7 +107,15 @@ public function create_question(?string $currentstate, object $formdata): questi
104107
* @throws moodle_exception
105108
*/
106109
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+
);
108119
$response = $this->post_and_maybe_retry('/attempt/start', $options);
109120
return api_utils::convert_response_to_class($response, attempt_started::class);
110121
}
@@ -123,11 +134,14 @@ public function start_attempt(string $questionstate, int $variant): attempt_star
123134
*/
124135
public function view_attempt(string $questionstate, string $attemptstate, ?string $scoringstate = null,
125136
?object $response = null): attempt {
137+
global $PAGE;
138+
126139
$options['multipart'] = $this->transform_to_multipart(
127140
[
128141
'attempt_state' => $attemptstate,
129142
'scoring_state' => $scoringstate,
130143
'response' => $response,
144+
'context' => $PAGE->context->id,
131145
],
132146
$questionstate,
133147
);
@@ -149,12 +163,15 @@ public function view_attempt(string $questionstate, string $attemptstate, ?strin
149163
*/
150164
public function score_attempt(string $questionstate, string $attemptstate, ?string $scoringstate,
151165
object $response): attempt_scored {
166+
global $PAGE;
167+
152168
$options['multipart'] = $this->transform_to_multipart(
153169
[
154170
'attempt_state' => $attemptstate,
155171
'scoring_state' => $scoringstate,
156172
'response' => $response,
157173
'generate_hint' => false,
174+
'context' => $PAGE->context->id,
158175
],
159176
$questionstate
160177
);

0 commit comments

Comments
 (0)