public function __construct($plugintype, $pluginname, $step)
 {
     parent::__construct($plugintype, $pluginname, $step);
     $this->legacynamemap = array('custom_template' => 'pertesttemplate');
     $revmap = qtype_coderunner::legacy_field_name_map();
     foreach ($revmap as $new => $old) {
         $this->legacynamemap[$old] = $new;
         // Invert the mapping
     }
 }
 function add_quest_coderunner_options($element)
 {
     $dummy_coderunner_q = new qtype_coderunner();
     // Check $element is one nested_backup_element
     if (!$element instanceof backup_nested_element) {
         throw new backup_step_exception("quest_coderunner_options_bad_parent_element", $element);
     }
     // Define the elements
     $options = new backup_nested_element('coderunner_options');
     $optionFields = $dummy_coderunner_q->extra_question_fields();
     // It's not static :-(
     array_shift($optionFields);
     $option = new backup_nested_element('coderunner_option', array('id'), $optionFields);
     // Build the tree
     $element->add_child($options);
     $options->add_child($option);
     // Set the source
     $option->set_source_table('question_coderunner_options', array('questionid' => backup::VAR_PARENTID));
 }
示例#3
0
文件: helper.php 项目: pac/CodeRunner
 private function get_options(&$question)
 {
     global $CFG, $DB;
     $type = $question->coderunnertype;
     if (!($row = $DB->get_record_select('question_coderunner_options', "coderunnertype = '{$type}' and prototypetype != 0"))) {
         throw new qtype_coderunner_missing_question_type("TestHelper: failed to load type info for question with type {$type}");
     }
     $noninherited = qtype_coderunner::noninherited_fields();
     foreach ($row as $field => $value) {
         if (!in_array($field, $noninherited)) {
             $question->{$field} = $value;
         }
     }
     foreach ($question->options as $key => $value) {
         $question->{$key} = $value;
     }
     // What follows is a rather horrible hack to support question export
     // testing. Having built the flattened question, we now "unflatten"
     // it back out to the set of options we get from the database.
     $question->options = new StdClass();
     foreach ($question->qtype->extra_question_fields() as $field) {
         if (isset($question->{$field})) {
             $question->options->{$field} = $question->{$field};
         } else {
             $question->options->{$field} = NULL;
         }
     }
     $question->options->answers = array();
     // For compatability with questiontype base
     $question->options->testcases = $question->testcases;
     if (!isset($question->sandbox)) {
         $question->sandbox = $question->get_best_sandbox($question->language);
         if ($question->sandbox === null) {
             throw new exception("TestHelper: no sandbox available for language {$question->language}");
         }
     }
     if (!isset($question->grader)) {
         $question->grader = 'EqualityGrader';
     }
 }
示例#4
0
 private function get_languages_and_types()
 {
     // Return two arrays (language => language_upper_case) and (type => subtype) of
     // all the coderunner question types available in the current course
     // context.
     // The subtype is the suffix of the type in the database,
     // e.g. for java_method it is 'method'. The language is the bit before
     // the underscore, and language_upper_case is a capitalised version,
     // e.g. Java for java. For question types without a
     // subtype the word 'Default' is used.
     $records = qtype_coderunner::get_all_prototypes();
     $types = array();
     foreach ($records as $row) {
         if (($pos = strpos($row->coderunnertype, '_')) !== false) {
             $subtype = substr($row->coderunnertype, $pos + 1);
             $language = substr($row->coderunnertype, 0, $pos);
         } else {
             $subtype = 'Default';
             $language = $row->coderunnertype;
         }
         $types[$row->coderunnertype] = $row->coderunnertype;
         $languages[$language] = ucwords($language);
     }
     asort($types);
     asort($languages);
     return array($languages, $types);
 }
示例#5
0
 private function make_sqr_user_type_prototype($fileAttachmentReqd = false)
 {
     global $DB;
     $q = $this->make_question('sqr');
     $q->test_cases = array();
     // No testcases in a prototype
     $q->customise = 1;
     $q->prototypetype = 2;
     $q->typename = "sqr_user_prototype";
     $q->cputimelimitsecs = 179;
     // Silly test value
     $q->combinatortemplate = 'combinatortemplatevalue';
     // Save the prototype to the DB so it has an accessible context for
     // retrieving associated files. All we need is its id and
     // its category, but the DB has other required fields so we dummy
     // up a minimal question containing the right category, at least.
     question_bank::load_question_definition_classes('coderunner');
     $row = new qtype_coderunner_question();
     test_question_maker::initialise_a_question($row);
     $catRow = $DB->get_record_select('question_categories', "contextid=1 limit 1");
     $row->category = $catRow->id;
     $row->qtype = 'qtype_coderunner';
     $row->contextid = 1;
     foreach (array('id', 'name', 'questiontext', 'generalfeedback') as $key) {
         $row->{$key} = $q->{$key};
     }
     $q->id = $DB->insert_record('question', $row);
     $qtype = new qtype_coderunner();
     $qtype->save_question_options($q);
     if ($fileAttachmentReqd) {
         // Attach a file.
         $fs = get_file_storage();
         $fileinfo = array('contextid' => 1, 'component' => 'qtype_coderunner', 'filearea' => 'datafile', 'itemid' => $q->id, 'filepath' => '/', 'filename' => 'data.txt');
         // Create file
         $fs->create_file_from_string($fileinfo, "This is data\nLine 2");
     }
     return $q->id;
 }
示例#6
0
 /**
  *  Return an associative array mapping filename to datafile contents
  *  for all the datafiles associated with a given question (which may
  *  be a real question or, in the case of a prototype, the question_options
  *  row) and the questionid from the mdl_questions table.
  */
 private static function get_data_files($question, $questionid)
 {
     global $DB;
     // 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();
     $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;
 }
示例#7
0
文件: ajax.php 项目: pac/CodeRunner
 * @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);
if (strpos(__DIR__, 'local/CodeRunner/type/coderunner') !== false) {
    require_once '../../../../config.php';
    // Symbolically linked rather than copied
} else {
    require_once '../../../config.php';
    // "Normal" case of a copy of the code
}
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_ALPHANUMEXT);
$courseid = required_param('courseid', PARAM_INT);
header('Content-type: application/json; charset=utf-8');
try {
    $coursecontext = context_course::instance($courseid);
    $questiontype = qtype_coderunner::get_prototype($qtype, $coursecontext);
    $questiontype->success = true;
    $questiontype->error = '';
} catch (moodle_exception $e) {
    $questiontype = new stdClass();
    $questiontype->success = false;
    $questiontype->error = "Error fetching prototype. " . $e->getMessage();
}
echo json_encode($questiontype);
die;