Skip to content

Commit bcf86e6

Browse files
committed
Remove files attribute from combinator outcome, plus some code tidying.
1 parent 6682d85 commit bcf86e6

File tree

2 files changed

+19
-25
lines changed

2 files changed

+19
-25
lines changed

classes/combinator_grader_outcome.php

+13-16
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ class qtype_coderunner_combinator_grader_outcome extends qtype_coderunner_testin
5757

5858
// A list of the allowed attributes in the combinator template grader return value.
5959
public $allowedfields = ['fraction', 'prologuehtml', 'testresults', 'files', 'epiloguehtml',
60-
'feedbackhtml', 'columnformats', 'showdifferences',
61-
'showoutputonly', 'graderstate', 'instructorhtml',
60+
'columnformats', 'showdifferences', 'showoutputonly', 'graderstate', 'instructorhtml',
6261
];
6362

6463
public function __construct($isprecheck) {
@@ -174,22 +173,20 @@ private function insert_file_urls($html, $urls) {
174173
*/
175174
public function set_mark_and_feedback($markfraction, $feedback) {
176175
$this->actualmark = $markfraction; // Combinators work in the range 0 - 1.
177-
$columnformats = $feedback['columnformats'] ?? null;
178176
$testresults = $feedback['testresults'] ?? null;
179177
$files = $feedback['files'] ?? null;
180-
$urls = null;
181-
if ($this->valid_table_formats($testresults, $columnformats)) {
182-
if ($files) {
183-
$urls = $this->save_files($files);
184-
}
185-
foreach ($feedback as $field => $value) {
186-
if ($urls && in_array($field, ['prologuehtml', 'epiloguehtml', 'instructorhtml', 'feedbackhtml'])) {
187-
$this->$field = $this->insert_file_urls($value, $urls);
188-
} else {
189-
$this->$field = $value;
190-
}
178+
$urls = $files ? $this->save_files($files) : null;
179+
180+
foreach ($feedback as $field => $value) {
181+
if ($urls && in_array($field, ['prologuehtml', 'epiloguehtml', 'instructorhtml'])) {
182+
$this->$field = $this->insert_file_urls($value, $urls);
183+
} else if (! in_array($field, ['files', 'testresults'])) {
184+
$this->$field = $value;
191185
}
192-
$this->format_results_table($testresults, $columnformats, $urls);
186+
}
187+
188+
if ($this->valid_table_formats($testresults, $this->columnformats)) {
189+
$this->format_results_table($testresults, $this->columnformats, $urls);
193190
}
194191
}
195192

@@ -212,7 +209,7 @@ public function iscombinatorgrader() {
212209
// but just output to be displayed as supplied. There is no message
213210
// regarding success or failure with such questions.
214211
public function is_output_only() {
215-
return isset($this->outputonly) && $this->outputonly;
212+
return $this->outputonly ?? false;
216213
}
217214

218215

classes/jobrunner.php

+6-9
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,11 @@ private function do_combinator_grading($run, $isprecheck) {
374374
// A successful combinator run (so far).
375375
$fract = $outcome->is_output_only() ? 1.0 : $result->fraction;
376376
$feedback = [];
377-
if (isset($result->feedback_html)) { // Legacy combinator grader?
378-
$result->feedbackhtml = $result->feedback_html; // Change to modern version.
379-
unset($result->feedback_html);
377+
foreach (['feedback_html', 'feedbackhtml'] as $legacykey) {
378+
if (isset($result->$legacykey)) { // Legacy combinator grader?
379+
$result->epiloguehtml = $result->$legacykey; // Use it as epiloguehtml.
380+
unset($result->$legacykey);
381+
}
380382
}
381383
foreach ($result as $key => $value) {
382384
if (!in_array($key, $outcome->allowedfields)) {
@@ -387,12 +389,7 @@ private function do_combinator_grading($run, $isprecheck) {
387389
);
388390
throw new Exception($error);
389391
}
390-
if ($key === 'feedbackhtml' || $key === 'feedback_html') {
391-
// For compatibility with older combinator graders.
392-
$feedback['epiloguehtml'] = $result->$key;
393-
} else {
394-
$feedback[$key] = $value;
395-
}
392+
$feedback[$key] = $value;
396393
}
397394
$outcome->set_mark_and_feedback($fract, $feedback); // Further valididty checks done in here.
398395
} catch (Exception $except) {

0 commit comments

Comments
 (0)