forked from trampgeek/moodle-qtype_coderunner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ajax.php
58 lines (51 loc) · 2.05 KB
/
ajax.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
<?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/>.
/**
* AJAX script to return a JSON-encoded row of the options for the specified
* question type by looking up the prototype in the question_coderunner_options
* table. Fields 'success' and 'error' are added for validation checking by
* the caller.
*
* @group qtype_coderunner
* Assumed to be run after python questions have been tested, so focuses
* only on C-specific aspects.
*
* @package qtype
* @subpackage coderunner
* @copyright 2015 Richard Lobb, University of Canterbury
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define('AJAX_SCRIPT', true);
require_once('../../../config.php');
require_once($CFG->dirroot . '/question/engine/lib.php');
require_once($CFG->dirroot . '/question/type/coderunner/questiontype.php');
require_login();
require_sesskey();
$qtype = required_param('qtype', PARAM_RAW_TRIMMED);
$courseid = required_param('courseid', PARAM_INT);
header('Content-type: application/json; charset=utf-8');
$coursecontext = context_course::instance($courseid);
$questiontype = qtype_coderunner::get_prototype($qtype, $coursecontext);
if ($questiontype === null) {
$questiontype = new stdClass();
$questiontype->success = false;
$questiontype->error = "Error fetching prototype '$qtype'.";
} else {
$questiontype->success = true;
$questiontype->error = '';
}
echo json_encode($questiontype);
die();