forked from trampgeek/moodle-qtype_coderunner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquestion.php
700 lines (608 loc) · 27.8 KB
/
question.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
<?php
// This file is part of CodeRunner - http://coderunner.org.nz/
//
// CodeRunner is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// CodeRunner is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with CodeRunner. If not, see <http://www.gnu.org/licenses/>.
/**
* coderunner question definition classes.
*
* @package qtype
* @subpackage coderunner
* @copyright Richard Lobb, 2011, The University of Canterbury
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/question/behaviour/adaptive/behaviour.php');
require_once($CFG->dirroot . '/question/engine/questionattemptstep.php');
require_once($CFG->dirroot . '/question/behaviour/adaptive_adapted_for_coderunner/behaviour.php');
require_once($CFG->dirroot . '/question/type/coderunner/questiontype.php');
use qtype_coderunner\constants;
/**
* Represents a 'CodeRunner' question.
*/
class qtype_coderunner_question extends question_graded_automatically {
public $testcases = null; // Array of testcases.
/**
* Start a new attempt at this question, storing any information that will
* be needed later in the step. It is retrieved and applied by
* apply_attempt_state.
*
* For CodeRunner questions we pre-process the template parameters for any
* randomisation required, storing the processed template parameters in
* the question_attempt_step.
*
* @param question_attempt_step The first step of the {@link question_attempt}
* being started. Can be used to store state. Is set to null during
* question validation, and must then be ignored.
* @param int $varant which variant of this question to start. Will be between
* 1 and {@link get_num_variants()} inclusive.
*/
public function start_attempt(question_attempt_step $step=null, $variant=null) {
global $DB, $USER;
if ($step !== null) {
parent::start_attempt($step, $variant);
$userid = $step->get_user_id();
$this->student = $DB->get_record('user', array('id' => $userid));
$step->set_qt_var('_STUDENT', serialize($this->student));
} else { // Validation, so just use the global $USER as student.
$this->student = $USER;
}
$seed = mt_rand();
if ($step !== null) {
$step->set_qt_var('_mtrandseed', $seed);
}
$this->setup_template_params($seed);
if ($this->twigall) {
$this->twig_all();
}
}
// Retrieve the saved random number seed and reconstruct the template
// parameters to the state they were left after start_attempt was called.
// Also twig expand the rest of the question fields if $this->twigall is true.
public function apply_attempt_state(question_attempt_step $step) {
parent::apply_attempt_state($step);
$this->student = unserialize($step->get_qt_var('_STUDENT'));
$seed = $step->get_qt_var('_mtrandseed');
if ($seed === null) {
// Rendering a question that was begun before randomisation
// was introduced into the code.
$seed = mt_rand();
}
$this->setup_template_params($seed);
if ($this->twigall) {
$this->twig_all();
}
}
/**
* Override default behaviour so that we can use a specialised behaviour
* that caches test results returned by the call to grade_response().
*
* @param question_attempt $qa the attempt we are creating an behaviour for.
* @param string $preferredbehaviour the requested type of behaviour.
* @return question_behaviour the new behaviour object.
*/
public function make_behaviour(question_attempt $qa, $preferredbehaviour) {
// Regardless of the preferred behaviour, always use an adaptive
// behaviour.
return new qbehaviour_adaptive_adapted_for_coderunner($qa, $preferredbehaviour);
}
public function get_expected_data() {
$expecteddata = array('answer' => PARAM_RAW,
'language' => PARAM_NOTAGS);
if ($this->attachments != 0) {
$expecteddata['attachments'] = question_attempt::PARAM_FILES;
}
return $expecteddata;
}
public function summarise_response(array $response) {
if (isset($response['answer'])) {
return $response['answer'];
} else {
return null;
}
}
public function validate_response(array $response) {
// Check the response and return a validation error message if it's
// faulty or an empty string otherwise.
// First check the attachments.
$hasattachments = array_key_exists('attachments', $response)
&& $response['attachments'] instanceof question_response_files;
if ($hasattachments) {
$attachmentfiles = $response['attachments']->get_files();
$attachcount = count($attachmentfiles);
// Check the filetypes.
$invalidfiles = array();
$regex = $this->filenamesregex;
$supportfiles = $this->get_files();
foreach ($attachmentfiles as $file) {
$filename = $file->get_filename();
if (!$this->is_valid_filename($filename, $regex, $supportfiles)) {
$invalidfiles[] = $filename;
}
}
if (count($invalidfiles) > 0) {
$badfilelist = implode(', ', $invalidfiles);
return get_string('badfiles', 'qtype_coderunner', $badfilelist);
}
} else {
$attachcount = 0;
}
if ($attachcount < $this->attachmentsrequired) {
return get_string('insufficientattachments', 'qtype_coderunner', $this->attachmentsrequired);
}
if ($attachcount == 0) { // If no attachments, require an answer.
$hasanswer = array_key_exists('answer', $response);
if (!$hasanswer || strlen($response['answer']) == 0) {
return get_string('answerrequired', 'qtype_coderunner');
} else if (strlen($response['answer']) < constants::FUNC_MIN_LENGTH) {
return get_string('answertooshort', 'qtype_coderunner', constants::FUNC_MIN_LENGTH);
}
}
return ''; // All good.
}
// Return true iff the given filename is valid, meaning it matches the
// regex (if given), contains only alphanumerics plus '-', '_' and '.',
// doesn't clash with any of the support files and doesn't
// start with double underscore..
private function is_valid_filename($filename, $regex, $supportfiles) {
if (strpos($filename, '__') === 0) {
return false; // Dunder names are reserved for runtime task.
}
if (!ctype_alnum(str_replace(array('-', '_', '.'), '', $filename))) {
return false; // Filenames must be alphanumeric plus '.', '-', or '_'.
}
if (!empty($regex) && preg_match('=^' . $this->filenamesregex . '$=', $filename) !== 1) {
return false; // Filename doesn't match given regex.
}
foreach (array_keys($supportfiles) as $supportfilename) {
if ($supportfilename == $filename) {
return false; // Filename collides with a support file name.
}
}
return true;
}
public function is_gradable_response(array $response) {
// Determine if the given response has a non-empty answer and/or
// a suitable number of attachments of accepted types.
return $this->validate_response($response) == '';
}
public function is_complete_response(array $response) {
return $this->is_gradable_response($response);
}
/**
* In situations where is_gradable_response() returns false, this method
* should generate a description of what the problem is.
* @return string the message.
*/
public function get_validation_error(array $response) {
$error = $this->validate_response($response);
if ($error) {
return $error;
} else {
return get_string('unknownerror', 'qtype_coderunner');
}
}
/** This function is used by the question engine to prevent regrading of
* unchanged submissions.
*
* @param array $prevresponse
* @param array $newresponse
* @return boolean
*/
public function is_same_response(array $prevresponse, array $newresponse) {
$sameanswer = question_utils::arrays_same_at_key_missing_is_blank(
$prevresponse, $newresponse, 'answer') &&
question_utils::arrays_same_at_key_missing_is_blank(
$prevresponse, $newresponse, 'language');
$attachments1 = $this->get_attached_files($prevresponse);
$attachments2 = $this->get_attached_files($newresponse);
$sameattachments = $attachments1 === $attachments2;
return $sameanswer && $sameattachments;
}
public function get_correct_response() {
return $this->get_correct_answer();
}
public function get_correct_answer() {
// Return the sample answer, if supplied.
if (!isset($this->answer)) {
return null;
} else {
$answer = array('answer' => $this->answer);
// For multilanguage questions we also need to specify the language.
// Use the answer_language template parameter value if given, otherwise
// run with the default.
$params = json_decode($this->templateparams);
if (!empty($params->answer_language)) {
$answer['language'] = $params->answer_language;
} else if (!empty($this->acelang) && strpos($this->acelang, ',') !== false) {
list($langs, $defaultlang) = qtype_coderunner_util::extract_languages($this->acelang);
$default = empty($defaultlang) ? $langs[0] : $defaultlang;
$answer['language'] = $default;
}
return $answer;
}
}
public function check_file_access($qa, $options, $component, $filearea, $args, $forcedownload) {
if ($component == 'question' && $filearea == 'response_attachments') {
// Response attachments visible if the question has them.
return $this->attachments != 0;
} else {
return parent::check_file_access($qa, $options, $component,
$filearea, $args, $forcedownload);
}
}
/** Return a setting that determines whether or not the specific
* feedback display is controlled by the quiz settings or this particular
* question.
* @return bool FEEDBACK_USE_QUIZ, FEEDBACK_SHOW or FEEDBACK_HIDE from constants class.
*/
public function display_feedback() {
return isset($this->displayfeedback) ? intval($this->displayfeedback) : constants::FEEDBACK_USE_QUIZ;
}
/**
* Grade the given student's response.
* This implementation assumes a modified behaviour that will accept a
* third array element in its response, containing data to be cached and
* served up again in the response on subsequent calls.
* @param array $response the qt_data for the current pending step. The
* two relevant keys are '_testoutcome', which is a cached copy of the
* grading outcome if this response has already been graded and 'answer'
* (the student's answer) otherwise.
* @param bool $isprecheck true iff this grading is occurring because the
* student clicked the precheck button
* @return 3-element array of the mark (0 - 1), the question_state (
* gradedright, gradedwrong, gradedpartial, invalid) and the full
* qtype_coderunner_testing_outcome object to be cached. The invalid
* state is used when a sandbox error occurs.
* @throws coding_exception
*/
public function grade_response(array $response, $isprecheck=false) {
if ($isprecheck && empty($this->precheck)) {
throw new coding_exception("Unexpected precheck");
}
$language = empty($response['language']) ? '' : $response['language'];
$gradingreqd = true;
if (!empty($response['_testoutcome'])) {
$testoutcomeserial = $response['_testoutcome'];
$testoutcome = unserialize($testoutcomeserial);
if ($testoutcome instanceof qtype_coderunner_testing_outcome // Ignore legacy-format outcomes.
&& $testoutcome->isprecheck == $isprecheck) {
$gradingreqd = false; // Already graded and with same precheck state.
}
}
if ($gradingreqd) {
// We haven't already graded this submission or we graded it with
// a different precheck setting. Get the code and the attachments
// from the response. The attachments is an array with keys being
// filenames and values being file contents.
$code = $response['answer'];
$attachments = $this->get_attached_files($response);
$testcases = $this->filter_testcases($isprecheck, $this->precheck);
$runner = new qtype_coderunner_jobrunner();
$testoutcome = $runner->run_tests($this, $code, $attachments, $testcases, $isprecheck, $language);
$testoutcomeserial = serialize($testoutcome);
}
$datatocache = array('_testoutcome' => $testoutcomeserial);
if ($testoutcome->run_failed()) {
return array(0, question_state::$invalid, $datatocache);
} else if ($testoutcome->all_correct()) {
return array(1, question_state::$gradedright, $datatocache);
} else if ($this->allornothing &&
!($this->grader === 'TemplateGrader' && $this->iscombinatortemplate)) {
return array(0, question_state::$gradedwrong, $datatocache);
} else {
// Allow partial marks if not allornothing or if it's a combinator template grader.
return array($testoutcome->mark_as_fraction(),
question_state::$gradedpartial, $datatocache);
}
}
// Return a map from filename to file contents for all the attached files
// in the given response.
private function get_attached_files($response) {
$attachments = array();
if (array_key_exists('attachments', $response) && $response['attachments']) {
$files = $response['attachments']->get_files();
foreach ($files as $file) {
$attachments[$file->get_filename()] = $file->get_content();
}
}
return $attachments;
}
/**
* @return an array of result column specifiers, each being a 2-element
* array of a column header and the testcase field to be displayed
*/
public function result_columns() {
if (isset($this->resultcolumns) && $this->resultcolumns) {
$resultcolumns = json_decode($this->resultcolumns);
} else {
// Use default column headers, equivalent to json_decode of (in English):
// '[["Test", "testcode"], ["Input", "stdin"], ["Expected", "expected"], ["Got", "got"]]'.
$resultcolumns = array(
array(get_string('testcolhdr', 'qtype_coderunner'), 'testcode'),
array(get_string('inputcolhdr', 'qtype_coderunner'), 'stdin'),
array(get_string('expectedcolhdr', 'qtype_coderunner'), 'expected'),
array(get_string('gotcolhdr', 'qtype_coderunner'), 'got'),
);
}
return $resultcolumns;
}
// Return an array of all the use_as_example testcases.
public function example_testcases() {
return array_filter($this->testcases, function($tc) {
return $tc->useasexample;
});
}
// Twig expand all text fields of the question except the templateparam field
// (which should have been expanded when the question was started) and
// the template itself.
// Done only if randomisation is specified within the template params.
private function twig_all() {
// Before twig expanding all fields, copy the template parameters
// into $this->parameters.
if (!empty($this->templateparams)) {
$this->parameters = json_decode($this->templateparams);
} else {
$this->parameters = new stdClass();
}
// Twig expand everything in a context that includes the template
// parameters and the STUDENT and QUESTION objects.
$this->questiontext = $this->twig_expand($this->questiontext);
$this->generalfeedback = $this->twig_expand($this->generalfeedback);
$this->answer = $this->twig_expand($this->answer);
$this->answerpreload = $this->twig_expand($this->answerpreload);
$this->globalextra = $this->twig_expand($this->globalextra);
foreach ($this->testcases as $key => $test) {
foreach (['testcode', 'stdin', 'expected', 'extra'] as $field) {
$text = $this->testcases[$key]->$field;
$this->testcases[$key]->$field = $this->twig_expand($text);
}
}
}
/**
* Return Twig-expanded version of the given text. The
* Twig environment includes the question itself (this) and the template
* parameters. Additional twig environment parameters are passed in via
* $twigparams. Template parameters are hoisted if required.
* @param string $text Text to be twig expanded.
* @param associative array $twigparams Extra twig environment parameters
*/
public function twig_expand($text, $twigparams=array()) {
if (empty(trim($text))) {
return $text;
} else {
$twigparams['QUESTION'] = $this;
if ($this->hoisttemplateparams) {
foreach ($this->parameters as $key => $value) {
$twigparams[$key] = $value;
}
}
return $this->twig_render($text, $twigparams);
}
}
/**
* Define the template parameters for this question by Twig-expanding
* both our own template params and our prototype template params and
* merging the two.
* @param type $seed The random number seed to set for Twig randomisation
*/
private function setup_template_params($seed) {
mt_srand($seed);
if (!isset($this->templateparams)) {
$this->templateparams = '';
}
$ournewtemplateparams = $this->twig_render($this->templateparams);
if (isset($this->prototypetemplateparams)) {
$prototypenewtemplateparams = $this->twig_render($this->prototypetemplateparams);
$this->templateparams = qtype_coderunner_util::merge_json($prototypenewtemplateparams, $ournewtemplateparams);
} else {
// Missing prototype?
$this->templateparams = $ournewtemplateparams;
}
}
// Render the given twig text using the given parameters and the
// current $this->student as user variable (for mapping to STUDENT twig param).
private function twig_render($text, $params=array()) {
return qtype_coderunner_twig::render($text, $this->student, $params);
}
// Extract and return the appropriate subset of the set of question testcases
// given $isprecheckrun (true iff this was a run initiated by clicking
// precheck) and the question's prechecksetting (0, 1, 2, 3, 4 for Disable,
// Empty, Examples, Selected and All respectively).
protected function filter_testcases($isprecheckrun, $prechecksetting) {
if (!$isprecheckrun) {
if ($prechecksetting != constants::PRECHECK_SELECTED) {
return $this->testcases;
} else {
return $this->selected_testcases(false);
}
} else { // This is a precheck run.
if ($prechecksetting == constants::PRECHECK_EMPTY) {
return array($this->empty_testcase());
} else if ($prechecksetting == constants::PRECHECK_EXAMPLES) {
return $this->example_testcases();
} else if ($prechecksetting == constants::PRECHECK_SELECTED) {
return $this->selected_testcases(true);
} else if ($prechecksetting == constants::PRECHECK_ALL) {
return $this->testcases;
} else {
throw new coding_exception('Precheck clicked but no precheck button?!');
}
}
}
// Return the appropriate subset of questions in the case that the question
// precheck setting is "selected", given whether or not this is a precheckrun.
protected function selected_testcases($isprecheckrun) {
$testcases = array();
foreach ($this->testcases as $testcase) {
if (($isprecheckrun && $testcase->testtype != constants::TESTTYPE_NORMAL) ||
(!$isprecheckrun && $testcase->testtype != constants::TESTTYPE_PRECHECK)) {
$testcases[] = $testcase;
}
}
return $testcases;
}
// Return an empty testcase - an artifical testcase with all fields
// empty or zero except for a mark of 1.
private function empty_testcase() {
return (object) array(
'testtype' => 0,
'testcode' => '',
'stdin' => '',
'expected' => '',
'extra' => '',
'display' => 'HIDE',
'useasexample' => 0,
'hiderestiffail' => 0,
'mark' => 1
);
}
/* ================================================================
* Interface methods for use by jobrunner.
================================================================*/
// Return the template.
public function get_template() {
return $this->template;
}
// Return the programming language used to run the code.
public function get_language() {
return $this->language;
}
// Get the showsource boolean.
public function get_show_source() {
return $this->showsource;
}
// Return the regular expression used to split the combinator template
// output into individual tests.
public function get_test_splitter_re() {
return $this->testsplitterre;
}
// Return whether or not the template is a combinator.
public function get_is_combinator() {
return $this->iscombinatortemplate;
}
// Return whether or not multiple stdins are allowed when using combinator.
public function allow_multiple_stdins() {
return $this->allowmultiplestdins;
}
// Return an instance of the sandbox to be used to run code for this question.
public function get_sandbox() {
global $CFG;
$sandbox = $this->sandbox; // Get the specified sandbox (if question has one).
if ($sandbox === null) { // No sandbox specified. Use best we can find.
$sandboxinstance = qtype_coderunner_sandbox::get_best_sandbox($this->language);
if ($sandboxinstance === null) {
throw new qtype_coderunner_exception("Language {$this->language} is not available on this system");
}
} else {
$sandboxinstance = qtype_coderunner_sandbox::get_instance($sandbox);
if ($sandboxinstance === null) {
throw new qtype_coderunner_exception("Question is configured to use a non-existent or disabled sandbox ($sandbox)");
}
}
return $sandboxinstance;
}
// Get an instance of the grader to be used to grade this question.
public function get_grader() {
global $CFG;
$grader = $this->grader == null ? constants::DEFAULT_GRADER : $this->grader;
if ($grader === 'CombinatorTemplateGrader') { // Legacy grader type.
$grader = 'TemplateGrader';
assert($this->iscombinatortemplate);
}
$graders = qtype_coderunner_grader::available_graders();
$graderclass = $graders[$grader];
$graderinstance = new $graderclass();
return $graderinstance;
}
// Return the support files for this question, namely all the files
// uploaded with this question itself plus all the files uploaded with the
// prototype. This does not include files attached to the answer.
// Returns an associative array mapping filenames to filecontents.
public function get_files() {
if ($this->prototypetype != 0) { // Is this a prototype question?
$files = array(); // Don't load the files twice.
} else {
// Load any files from the prototype.
$this->get_prototype();
$files = self::get_support_files($this->prototype, $this->prototype->questionid);
}
$files = array_merge($files, self::get_support_files($this, $this->id)); // Add in files for this question.
return $files;
}
// Get the sandbox parameters for a run.
public function get_sandbox_params() {
if (isset($this->sandboxparams)) {
$sandboxparams = json_decode($this->sandboxparams, true);
} else {
$sandboxparams = array();
}
if (isset($this->cputimelimitsecs)) {
$sandboxparams['cputime'] = intval($this->cputimelimitsecs);
}
if (isset($this->memlimitmb)) {
$sandboxparams['memorylimit'] = intval($this->memlimitmb);
}
if (isset($this->templateparams) && $this->templateparams != '') {
$this->parameters = json_decode($this->templateparams);
} else {
$this->parameters = new stdClass();
}
return $sandboxparams;
}
/**
* Load the prototype for this question and store in $this->prototype
*/
public function get_prototype() {
if (!isset($this->prototype)) {
$context = qtype_coderunner::question_context($this);
$this->prototype = qtype_coderunner::get_prototype($this->coderunnertype, $context);
}
}
/**
* Return an associative array mapping filename to file contents
* for all the support files the given question (which may be a real
* question or, in the case of a prototype, the question_options row).
* $questionid is the id of the question.
* The sample answer files are not included in the return value.
*/
private static function get_support_files($question, $questionid) {
global $DB, $USER;
// If not given in the question object get the contextid from the database.
if (isset($question->contextid)) {
$contextid = $question->contextid;
} else {
$context = qtype_coderunner::question_context($question);
$contextid = $context->id;
}
$fs = get_file_storage();
$filemap = array();
if (isset($question->supportfilemanagerdraftid)) {
// If we're just validating a question, get files from user draft area.
$draftid = $question->supportfilemanagerdraftid;
$context = context_user::instance($USER->id);
$files = $fs->get_area_files($context->id, 'user', 'draft', $draftid, '', false);
} else {
// Otherwise, get the stored support files for this question (not
// the sample answer files).
$files = $fs->get_area_files($contextid, 'qtype_coderunner', 'datafile', $questionid);
}
foreach ($files as $f) {
$name = $f->get_filename();
if ($name !== '.') {
$filemap[$f->get_filename()] = $f->get_content();
}
}
return $filemap;
}
}