Skip to content

Commit c9e40c5

Browse files
authored
Merge pull request #1471 from maths/api-solutions
API - Use better 'can be typed as' solution. Update Debian.
2 parents 534bcdb + cf71959 commit c9e40c5

7 files changed

Lines changed: 6 additions & 43 deletions

File tree

api/controller/RenderController.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,10 @@ public function __invoke(Request $request, Response $response, array $args): Res
100100
$inputs = [];
101101
foreach ($question->inputs as $name => $input) {
102102
$apiinput = new StackRenderInput();
103-
104-
$apiinput->samplesolution = $input->get_api_solution($question->get_ta_for_input($name));
103+
$correctresponse = (isset($question->get_correct_response()[$name])) ? $question->get_correct_response()[$name] : null;
104+
// Deal with matrix questions.
105+
$correctresponse = (isset($correctresponse)) ? $correctresponse : $question->get_ta_for_input($name);
106+
$apiinput->samplesolution = $input->get_api_solution($correctresponse);
105107
$apiinput->samplesolutionrender = $input->get_api_solution_render(
106108
$question->get_ta_render_for_input($name), $question->get_ta_for_input($name));
107109

api/docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ RUN composer install
99
RUN composer dump-autoload --optimize
1010

1111
#Base Image
12-
FROM php:8.2-apache-bullseye AS base
12+
FROM php:8.4.5-apache-bookworm AS base
1313

1414
#Install required php extensions
1515
RUN apt-get update && \

api/public/stackshared.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ function send() {
111111
correctAnswers += `, <?php echo stack_string('api_which_typed') ?>: `;
112112
for (const [name, solution] of Object.entries(input.samplesolution)) {
113113
if (name.indexOf('_val') === -1) {
114-
correctAnswers += `<span class='correct-answer'>${solution}</span>`;
114+
correctAnswers += `<span class='correct-answer'>${solution.replace(/\n/g, '<br>')}</span>`;
115115
}
116116
}
117117
}

stack/input/equiv/equiv.class.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -588,9 +588,4 @@ protected function ajax_to_response_array($in) {
588588
$in = implode("\n", $in);
589589
return [$this->name => $in];
590590
}
591-
592-
// phpcs:ignore moodle.Commenting.MissingDocblock.Function
593-
public function get_api_solution($tavalue) {
594-
return ['' => $this->maxima_to_raw_input($tavalue)];
595-
}
596591
}

stack/input/notes/notes.class.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,6 @@ public function summarise_response($name, $state, $response) {
229229
return $name . ': ' . $val . ' [' . $state->status . ']';
230230
}
231231

232-
// phpcs:ignore moodle.Commenting.MissingDocblock.Function
233-
public function get_api_solution($tavalue) {
234-
return new stdClass();
235-
}
236-
237232
// phpcs:ignore moodle.Commenting.MissingDocblock.Function
238233
public function get_api_solution_render($tadisplay, $ta) {
239234
return '';

stack/input/textarea/textarea.class.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -342,21 +342,4 @@ public function get_teacher_answer_display($value, $display) {
342342

343343
return stack_string('teacheranswershow', ['value' => $value, 'display' => $display]);
344344
}
345-
346-
// phpcs:ignore moodle.Commenting.MissingDocblock.Function
347-
public function get_api_solution($tavalue) {
348-
$values = stack_utils::list_to_array($tavalue, false);
349-
foreach ($values as $key => $val) {
350-
if (trim($val) !== '' ) {
351-
$cs = stack_ast_container::make_from_teacher_source($val);
352-
$cs->get_valid();
353-
$val = $cs->get_inputform(true, 0, true);
354-
}
355-
$values[$key] = $val;
356-
}
357-
358-
return ['' => implode("\n", $values)];
359-
}
360-
361-
362345
}

stack/input/varmatrix/varmatrix.class.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -457,16 +457,4 @@ public function internal_validate_parameter($parameter, $value) {
457457
}
458458
return $valid;
459459
}
460-
461-
// phpcs:ignore moodle.Commenting.MissingDocblock.Function
462-
public function get_api_solution($tavalue) {
463-
// We clear the name, and then restore its original value,
464-
// to not include the prefix in the api solution.
465-
$name = $this->name;
466-
$this->name = '';
467-
$sol = $this->maxima_to_response_array($tavalue);
468-
$this->name = $name;
469-
return $sol;
470-
}
471-
472460
}

0 commit comments

Comments
 (0)