protected function definition_inner($mform) { $qtype = question_bank::get_qtype('poodllrecording'); $mform->addElement('select', 'responseformat', get_string('responseformat', 'qtype_poodllrecording'), $qtype->response_formats()); $mform->setDefault('responseformat', 'editor'); $mform->addElement('editor', 'graderinfo', get_string('graderinfo', 'qtype_poodllrecording'), array('rows' => 10), $this->editoroptions); }
public function validation($data, $files) { global $DB; $errors = parent::validation($data, $files); if (isset($data->categorymoveto)) { list($category) = explode(',', $data['categorymoveto']); } else { list($category) = explode(',', $data['category']); } $saquestions = question_bank::get_qtype('randomsamatch')->get_sa_candidates($category); $numberavailable = count($saquestions); if ($saquestions === false) { $a = new stdClass(); $a->catname = $DB->get_field('question_categories', 'name', array('id' => $category)); $errors['choose'] = get_string('nosaincategory', 'qtype_randomsamatch', $a); } else { if ($numberavailable < $data['choose']) { $a = new stdClass(); $a->catname = $DB->get_field('question_categories', 'name', array('id' => $category)); $a->nosaquestions = $numberavailable; $errors['choose'] = get_string('notenoughsaincategory', 'qtype_randomsamatch', $a); } } return $errors; }
protected function definition_inner($mform) { global $DB, $question; $loaded_initialy = optional_param('reloaded_initialy', 1, PARAM_INT); $qtype = question_bank::get_qtype('javaunittest'); $definitionoptions = $this->_customdata['definitionoptions']; $attachmentoptions = $this->_customdata['attachmentoptions']; // -------------------------- feedback options $mform->addElement('select', 'feedbacklevel', get_string('feedbacklevel', 'qtype_javaunittest'), $qtype->feedback_levels()); $mform->setDefault('feedbacklevel', FEEDBACK_ONLY_TIMES); // -------------------------- size of the response field $mform->addElement('select', 'responsefieldlines', get_string('responsefieldlines', 'qtype_javaunittest'), $qtype->response_sizes()); $mform->setDefault('responsefieldlines', 15); // -------------------------- "Given Code" Text-Area $mform->addElement('textarea', 'givencode', get_string('givencode', 'qtype_javaunittest'), array('cols' => 80, 'rows' => 20)); $mform->setType('givencode', PARAM_RAW); $mform->addHelpButton('givencode', 'givencode', 'qtype_javaunittest'); // -------------------------- "Test class" Text-Area $mform->addElement('textarea', 'testclassname', get_string('testclassname', 'qtype_javaunittest'), array('cols' => 80, 'rows' => 1)); $mform->setType('testclassname', PARAM_ALPHANUMEXT); $mform->addRule('testclassname', null, 'required'); $mform->addHelpButton('testclassname', 'testclassname', 'qtype_javaunittest'); $mform->addElement('textarea', 'junitcode', get_string('uploadtestclass', 'qtype_javaunittest'), array('cols' => 80, 'rows' => 20)); $mform->setType('junitcode', PARAM_RAW); $mform->addRule('junitcode', null, 'required'); $mform->addHelpButton('junitcode', 'uploadtestclass', 'qtype_javaunittest'); }
protected function definition_inner($mform) { $qtype = question_bank::get_qtype('essay'); $mform->addElement('editor', 'graderinfo', get_string('graderinfo', 'qtype_essay'), array('rows' => 10), $this->editoroptions); $mform->addElement('header', 'responseheader', get_string('responseheader', 'qtype_essay')); $mform->addElement('select', 'responseformat', get_string('responseformat', 'qtype_essay'), $qtype->response_formats()); $mform->setDefault('responseformat', 'editor'); $mform->addElement('select', 'responsefieldlines', get_string('responsefieldlines', 'qtype_essay'), $qtype->response_sizes()); $mform->setDefault('responsefieldlines', 15); $mform->addElement('select', 'attachments', get_string('allowattachments', 'qtype_essay'), $qtype->attachment_options()); $mform->setDefault('attachments', 0); $mform->addElement('select', 'responselimitpolicy', get_string('responselimitpolicy', 'qtype_essay'), $qtype->response_limit_policies()); $mform->addHelpButton('responselimitpolicy', 'responselimitpolicy', 'qtype_essay'); $mform->addElement('text', 'wordlimit', get_string('wordlimit', 'qtype_essay'), array('size' => 3)); $mform->disabledIf('wordlimit', 'responselimitpolicy', 'eq', 0); $mform->setType('wordlimit', PARAM_INT); $mform->addElement('text', 'charlimit', get_string('charlimit', 'qtype_essay'), array('size' => 3)); $mform->disabledIf('charlimit', 'responselimitpolicy', 'eq', 0); $mform->setType('charlimit', PARAM_INT); }
/** * Returns the qtype information to attach to question element. */ protected function define_question_plugin_structure() { $qtypeobj = question_bank::get_qtype($this->pluginname); // Define the virtual plugin element with the condition to fulfill. $plugin = $this->get_plugin_element(null, '../../qtype', $qtypeobj->name()); // Create one standard named plugin element (the visible container). $pluginwrapper = new backup_nested_element($this->get_recommended_name()); // Connect the visible container ASAP. $plugin->add_child($pluginwrapper); // This qtype uses standard question_answers, add them here // to the tree before any other information that will use them. $this->add_question_question_answers($pluginwrapper); $answers = $pluginwrapper->get_child('answers'); $answer = $answers->get_child('answer'); // Extra question fields. $extraquestionfields = $qtypeobj->extra_question_fields(); if (!empty($extraquestionfields)) { $tablename = array_shift($extraquestionfields); $child = new backup_nested_element($qtypeobj->name(), array('id'), $extraquestionfields); $pluginwrapper->add_child($child); $child->set_source_table($tablename, array($qtypeobj->questionid_column_name() => backup::VAR_PARENTID)); } // Extra answer fields. $extraanswerfields = $qtypeobj->extra_answer_fields(); if (!empty($extraanswerfields)) { $tablename = array_shift($extraanswerfields); $child = new backup_nested_element('extraanswerdata', array('id'), $extraanswerfields); $answer->add_child($child); $child->set_source_table($tablename, array('answerid' => backup::VAR_PARENTID)); } // Don't need to annotate ids nor files. return $plugin; }
/** * Function to read all questions for category into big array * * @param int $category category number * @param bool $noparent if true only questions with NO parent will be selected * @param bool $recurse include subdirectories * @param bool $export set true if this is called by questionbank export * @author added by Howard Miller June 2004 */ function get_questions_category( $category, $noparent=false, $recurse=true, $export=true ) { global $DB; // questions will be added to an array $qresults = array(); // build sql bit for $noparent $npsql = ''; if ($noparent) { $npsql = " and parent='0' "; } // Get list of categories if ($recurse) { $categorylist = question_categorylist($category->id); } else { $categorylist = array($category->id); } // get the list of questions for the category list($usql, $params) = $DB->get_in_or_equal($categorylist); if ($questions = $DB->get_records_select('question', "category $usql $npsql", $params, 'qtype, name')) { // iterate through questions, getting stuff we need foreach($questions as $question) { $question->export_process = $export; question_bank::get_qtype($question->qtype)->get_question_options($question); $qresults[] = $question; } } return $qresults; }
/** * Function to read all questions for category into big array * * @param int $category category number * @param bool $noparent if true only questions with NO parent will be selected * @param bool $recurse include subdirectories * @param bool $export set true if this is called by questionbank export */ function get_questions_category($category, $noparent = false, $recurse = true, $export = true) { global $DB; // Build sql bit for $noparent $npsql = ''; if ($noparent) { $npsql = " and parent='0' "; } // Get list of categories if ($recurse) { $categorylist = question_categorylist($category->id); } else { $categorylist = array($category->id); } // Get the list of questions for the category list($usql, $params) = $DB->get_in_or_equal($categorylist); $questions = $DB->get_records_select('question', "category {$usql} {$npsql}", $params, 'qtype, name'); // Iterate through questions, getting stuff we need $qresults = array(); foreach ($questions as $key => $question) { $question->export_process = $export; $qtype = question_bank::get_qtype($question->qtype, false); if ($export && $qtype->name() == 'missingtype') { // Unrecognised question type. Skip this question when exporting. continue; } $qtype->get_question_options($question); $qresults[] = $question; } return $qresults; }
/** * Add question-type specific form fields. * * @param MoodleQuickForm $mform the form being built. */ public function __construct($submiturl, $question, $regenerate) { global $SESSION, $CFG, $DB; $this->regenerate = $regenerate; $this->question = $question; $this->qtypeobj = question_bank::get_qtype($this->question->qtype); // Validate the question category. if (!($category = $DB->get_record('question_categories', array('id' => $question->category)))) { print_error('categorydoesnotexist', 'question', $returnurl); } $this->category = $category; $this->categorycontext = context::instance_by_id($category->contextid); // Get the dataset defintions for this question. if (empty($question->id)) { $this->datasetdefs = $this->qtypeobj->get_dataset_definitions($question->id, $SESSION->calculated->definitionform->dataset); } else { if (empty($question->options)) { $this->get_question_options($question); } $this->datasetdefs = $this->qtypeobj->get_dataset_definitions($question->id, array()); } foreach ($this->datasetdefs as $datasetdef) { // Get maxnumber. if ($this->maxnumber == -1 || $datasetdef->itemcount < $this->maxnumber) { $this->maxnumber = $datasetdef->itemcount; } } foreach ($this->datasetdefs as $defid => $datasetdef) { if (isset($datasetdef->id)) { $this->datasetdefs[$defid]->items = $this->qtypeobj->get_database_dataset_items($datasetdef->id); } } parent::__construct($submiturl); }
public static function make_question($type, $answers = array("cat", "mat")) { question_bank::load_question_definition_classes($type); $question = new qtype_gapfill_question(); test_question_maker::initialise_a_question($question); $question->qtype = question_bank::get_qtype('gapfill'); $question->name = 'Gapfill Test Question'; $question->questiontext = "The [cat] sat on the [mat]"; $question->textfragments = array('The ', ' sat on the '); $question->displayanswers = '1'; $question->casesensitive = '1'; $question->generalfeedback = 'congratulations on your knowledge of pets and floor covering'; $question->places[1] = $answers[0]; $question->places[2] = $answers[1]; $answer1 = new question_answer(43, $answers[0], 4, 1, 1); $answer2 = new question_answer(44, $answers[1], 4, 1, 1); $question->answers = array($answer1, $answer2); $question->options = new stdClass(); $question->options->showanswers = false; $question->options->delimitchars = "[]"; $question->options->casesensitive = false; $question->options->correctfeedback = ""; $question->options->correctfeedbackformat = ""; $question->options->partiallycorrectfeedback = ""; $question->options->partiallycorrectfeedbackformat = ""; $question->options->incorrectfeedback = ""; $question->options->incorrectfeedbackformat = ""; $question->options->shuffledanswers = "mat,cat"; $question->options->wronganswers = "bat,dog"; $question->shuffledanswers = "mat,cat,bat,dog"; $answers = new stdClass(); $question->options->answers = array($answer1, $answer2); $question->hints = array(new question_hint(1, 'This is the first hint.', FORMAT_HTML), new question_hint(2, 'This is the second hint.', FORMAT_HTML)); return $question; }
public function readquestions($lines) { question_bank::get_qtype('multianswer'); // Ensure the multianswer code is loaded. // For this class the method has been simplified as // there can never be more than one question for a // multianswer import. $questions = array(); $questiontext = array(); $questiontext['text'] = implode('', $lines); $questiontext['format'] = FORMAT_MOODLE; $questiontext['itemid'] = ''; $question = qtype_multianswer_extract_question($questiontext); $question->questiontext = $question->questiontext['text']; $question->questiontextformat = 0; $question->qtype = 'multianswer'; $question->generalfeedback = ''; $question->generalfeedbackformat = FORMAT_MOODLE; $question->length = 1; $question->penalty = 0.3333333; if (!empty($question)) { $question->name = $this->create_default_question_name($question->questiontext, get_string('questionname', 'question')); $questions[] = $question; } return $questions; }
public function test_grading_rounding_three_right() { question_bank::load_question_definition_classes('multichoice'); $mc = new qtype_multichoice_multi_question(); test_question_maker::initialise_a_question($mc); $mc->name = 'Odd numbers'; $mc->questiontext = 'Which are the odd numbers?'; $mc->generalfeedback = '1, 3 and 5 are the odd numbers.'; $mc->qtype = question_bank::get_qtype('multichoice'); $mc->shuffleanswers = 0; $mc->answernumbering = 'abc'; test_question_maker::set_standard_combined_feedback_fields($mc); $mc->answers = array( 11 => new question_answer(11, '1', 0.3333333, '', FORMAT_HTML), 12 => new question_answer(12, '2', -1, '', FORMAT_HTML), 13 => new question_answer(13, '3', 0.3333333, '', FORMAT_HTML), 14 => new question_answer(14, '4', -1, '', FORMAT_HTML), 15 => new question_answer(15, '5', 0.3333333, '', FORMAT_HTML), 16 => new question_answer(16, '6', -1, '', FORMAT_HTML), ); $mc->start_attempt(new question_attempt_step(), 1); list($grade, $state) = $mc->grade_response( array('choice0' => 1, 'choice2' => 1, 'choice4' => 1)); $this->assertEquals(1, $grade, '', 0.000001); $this->assertEquals(question_state::$gradedright, $state); }
protected function definition_inner($mform) { $qtype = question_bank::get_qtype('essay'); $mform->addElement('header', 'responseoptions', get_string('responseoptions', 'qtype_essay')); $mform->setExpanded('responseoptions'); $mform->addElement('select', 'responseformat', get_string('responseformat', 'qtype_essay'), $qtype->response_formats()); $mform->setDefault('responseformat', 'editor'); $mform->addElement('select', 'responserequired', get_string('responserequired', 'qtype_essay'), $qtype->response_required_options()); $mform->setDefault('responserequired', 1); $mform->disabledIf('responserequired', 'responseformat', 'eq', 'noinline'); $mform->addElement('select', 'responsefieldlines', get_string('responsefieldlines', 'qtype_essay'), $qtype->response_sizes()); $mform->setDefault('responsefieldlines', 15); $mform->disabledIf('responsefieldlines', 'responseformat', 'eq', 'noinline'); $mform->addElement('select', 'attachments', get_string('allowattachments', 'qtype_essay'), $qtype->attachment_options()); $mform->setDefault('attachments', 0); $mform->addElement('select', 'attachmentsrequired', get_string('attachmentsrequired', 'qtype_essay'), $qtype->attachments_required_options()); $mform->setDefault('attachmentsrequired', 0); $mform->addHelpButton('attachmentsrequired', 'attachmentsrequired', 'qtype_essay'); $mform->disabledIf('attachmentsrequired', 'attachments', 'eq', 0); $mform->addElement('header', 'responsetemplateheader', get_string('responsetemplateheader', 'qtype_essay')); $mform->addElement('editor', 'responsetemplate', get_string('responsetemplate', 'qtype_essay'), array('rows' => 10), array_merge($this->editoroptions, array('maxfiles' => 0))); $mform->addHelpButton('responsetemplate', 'responsetemplate', 'qtype_essay'); $mform->addElement('header', 'graderinfoheader', get_string('graderinfoheader', 'qtype_essay')); $mform->setExpanded('graderinfoheader'); $mform->addElement('editor', 'graderinfo', get_string('graderinfo', 'qtype_essay'), array('rows' => 10), $this->editoroptions); }
/** * Makes a calculated question about summing two numbers. * @return qtype_calculated_question */ public function make_calculated_question_sum() { question_bank::load_question_definition_classes('calculated'); $q = new qtype_calculated_question(); test_question_maker::initialise_a_question($q); $q->name = 'Simple sum'; $q->questiontext = 'What is {a} + {b}?'; $q->generalfeedback = 'Generalfeedback: {={a} + {b}} is the right answer.'; $q->answers = array( 13 => new qtype_numerical_answer(13, '{a} + {b}', 1.0, 'Very good.', FORMAT_HTML, 0), 14 => new qtype_numerical_answer(14, '{a} - {b}', 0.0, 'Add. not subtract!.', FORMAT_HTML, 0), 17 => new qtype_numerical_answer(17, '*', 0.0, 'Completely wrong.', FORMAT_HTML, 0), ); foreach ($q->answers as $answer) { $answer->correctanswerlength = 2; $answer->correctanswerformat = 1; } $q->qtype = question_bank::get_qtype('calculated'); $q->unitdisplay = qtype_numerical::UNITNONE; $q->unitgradingtype = 0; $q->unitpenalty = 0; $q->ap = new qtype_numerical_answer_processor(array()); $q->synchronised = false; $q->datasetloader = new qtype_calculated_test_dataset_loader(0, array( array('a' => 1, 'b' => 5), array('a' => 3, 'b' => 4), )); return $q; }
/** * Run all the question tests for all variants of all questions belonging to * a given context. * * Does output as we go along. * * @param context $context the context to run the tests for. * @return array with two elements: * bool true if all the tests passed, else false. * array of messages relating to the questions with failures. */ public function run_all_tests_for_context(context $context) { global $DB, $OUTPUT; // Load the necessary data. $categories = question_category_options(array($context)); $categories = reset($categories); $questiontestsurl = new moodle_url('/question/type/stack/questiontestrun.php'); if ($context->contextlevel == CONTEXT_COURSE) { $questiontestsurl->param('courseid', $context->instanceid); } else { if ($context->contextlevel == CONTEXT_MODULE) { $questiontestsurl->param('cmid', $context->instanceid); } } $allpassed = true; $failingtests = array(); foreach ($categories as $key => $category) { list($categoryid) = explode(',', $key); echo $OUTPUT->heading($category, 3); $questionids = $DB->get_records_menu('question', array('category' => $categoryid, 'qtype' => 'stack'), 'name', 'id,name'); if (!$questionids) { continue; } echo html_writer::tag('p', stack_string('replacedollarscount', count($questionids))); foreach ($questionids as $questionid => $name) { $tests = question_bank::get_qtype('stack')->load_question_tests($questionid); if (!$tests) { echo $OUTPUT->heading(html_writer::link(new moodle_url($questiontestsurl, array('questionid' => $questionid)), format_string($name)), 4); echo html_writer::tag('p', stack_string('bulktestnotests')); continue; } $question = question_bank::load_question($questionid); $questionname = format_string($name); $previewurl = new moodle_url($questiontestsurl, array('questionid' => $questionid)); if (empty($question->deployedseeds)) { $questionnamelink = html_writer::link($previewurl, $questionname); echo $OUTPUT->heading($questionnamelink, 4); list($ok, $message) = $this->qtype_stack_test_question($question, $tests); if (!$ok) { $allpassed = false; $failingtests[] = $questionnamelink . ': ' . $message; } } else { echo $OUTPUT->heading(format_string($name), 4); foreach ($question->deployedseeds as $seed) { $previewurl->param('seed', $seed); $questionnamelink = html_writer::link($previewurl, stack_string('seedx', $seed)); echo $OUTPUT->heading($questionnamelink, 4); list($ok, $message) = $this->qtype_stack_test_question($question, $tests, $seed); if (!$ok) { $allpassed = false; $failingtests[] = $questionname . ' ' . $questionnamelink . ': ' . $message; } } } } } return array($allpassed, $failingtests); }
/** * Create a quiz add questions to it, walk through quiz attempts and then check results. * * @param PHPUnit_Extensions_Database_DataSet_ITable[] of data read from csv file "questionsXX.csv", * "stepsXX.csv" and "resultsXX.csv". * @dataProvider get_data_for_walkthrough */ public function test_walkthrough_from_csv($quizsettings, $csvdata) { // CSV data files for these tests were generated using : // https://github.com/jamiepratt/moodle-quiz-tools/tree/master/responsegenerator $this->resetAfterTest(true); question_bank::get_qtype('random')->clear_caches_before_testing(); $this->create_quiz($quizsettings, $csvdata['questions']); $attemptids = $this->walkthrough_attempts($csvdata['steps']); $this->check_attempts_results($csvdata['results'], $attemptids); $this->report = new quiz_statistics_report(); $whichattempts = QUIZ_GRADEAVERAGE; $groupstudents = array(); $questions = $this->report->load_and_initialise_questions_for_calculations($this->quiz); list($quizstats, $questionstats, $subquestionstats) = $this->report->get_quiz_and_questions_stats($this->quiz, $whichattempts, $groupstudents, $questions); $qubaids = quiz_statistics_qubaids_condition($this->quiz->id, $groupstudents, $whichattempts); // We will create some quiz and question stat calculator instances and some response analyser instances, just in order // to check the time of the $quizcalc = new quiz_statistics_calculator(); // Should not be a delay of more than one second between the calculation of stats above and here. $this->assertTimeCurrent($quizcalc->get_last_calculated_time($qubaids)); $qcalc = new \core_question\statistics\questions\calculator($questions); $this->assertTimeCurrent($qcalc->get_last_calculated_time($qubaids)); foreach ($questions as $question) { if (!question_bank::get_qtype($question->qtype, false)->can_analyse_responses()) { continue; } $responesstats = new \core_question\statistics\responses\analyser($question); $this->assertTimeCurrent($responesstats->get_last_analysed_time($qubaids)); } // These quiz stats and the question stats found in qstats00.csv were calculated independently in spreadsheet which is // available in open document or excel format here : // https://github.com/jamiepratt/moodle-quiz-tools/tree/master/statsspreadsheet $quizstatsexpected = array('median' => 4.5, 'firstattemptsavg' => 4.617333332, 'allattemptsavg' => 4.617333332, 'firstattemptscount' => 25, 'allattemptscount' => 25, 'standarddeviation' => 0.8117265554, 'skewness' => -0.092502502, 'kurtosis' => -0.7073968557, 'cic' => -87.22309355420001, 'errorratio' => 136.8294900795, 'standarderror' => 1.1106813066); foreach ($quizstatsexpected as $statname => $statvalue) { $this->assertEquals($statvalue, $quizstats->{$statname}, $quizstats->{$statname}, abs($statvalue) * 1.5E-5); } for ($rowno = 0; $rowno < $csvdata['qstats']->getRowCount(); $rowno++) { $slotqstats = $csvdata['qstats']->getRow($rowno); foreach ($slotqstats as $statname => $slotqstat) { if ($statname !== 'slot') { switch ($statname) { case 'covariance': case 'discriminationindex': case 'discriminativeefficiency': case 'effectiveweight': $precision = 1.0E-5; break; default: $precision = 1.0E-6; } $slot = $slotqstats['slot']; $delta = abs($slotqstat) * $precision; $actual = $questionstats[$slot]->{$statname}; $this->assertEquals(floatval($slotqstat), $actual, "{$statname} for slot {$slot}", $delta); } } } }
public function __construct($plugintype, $pluginname, $step) { parent::__construct($plugintype, $pluginname, $step); $this->qtypeobj = question_bank::get_qtype($this->pluginname); $this->oldquestionid = -1; $this->newquestionid = -1; $this->questioncreated = false; $this->currentanswer = null; }
/** * Create a new instance of this class for holding/computing the statistics * for a particular question. * @param object $questiondata the data from the database defining this question. */ public function __construct($questiondata) { $this->questiondata = $questiondata; $this->responseclasses = question_bank::get_qtype($questiondata->qtype)->get_possible_responses($questiondata); foreach ($this->responseclasses as $subpartid => $responseclasses) { foreach ($responseclasses as $responseclassid => $notused) { $this->responses[$subpartid][$responseclassid] = array(); } } }
/** * Create a new instance of this class for holding/computing the statistics * for a particular question. * * @param object $questiondata the full question data from the database defining this question. * @param string $whichtries which tries to analyse. */ public function __construct($questiondata, $whichtries = \question_attempt::LAST_TRY) { $this->questiondata = $questiondata; $qtypeobj = \question_bank::get_qtype($this->questiondata->qtype); if ($whichtries != \question_attempt::ALL_TRIES) { $this->analysis = new analysis_for_question($qtypeobj->get_possible_responses($this->questiondata)); } else { $this->analysis = new analysis_for_question_all_tries($qtypeobj->get_possible_responses($this->questiondata)); } $this->breakdownbyvariant = $qtypeobj->break_down_stats_and_response_analysis_by_variant($this->questiondata); }
protected function definition_inner($mform) { $qtype = question_bank::get_qtype('poodllrecording'); $mform->addElement('select', 'responseformat', get_string('responseformat', 'qtype_poodllrecording'), $qtype->response_formats()); $mform->setDefault('responseformat', 'editor'); $mform->addElement('editor', 'graderinfo', get_string('graderinfo', 'qtype_poodllrecording'), array('rows' => 10), $this->editoroptions); // added Justin 20120814 bgimage, part of whiteboard response $mform->addElement('filemanager', 'backimage', get_string('backimage', 'qtype_poodllrecording'), null, array('subdirs' => 0, 'maxbytes' => 0, 'maxfiles' => 1)); $mform->addElement('select', 'boardsize', get_string('boardsize', 'qtype_poodllrecording'), $qtype->board_sizes()); $mform->setDefault('boardsize', 'editor'); }
protected function definition_inner($mform) { global $DB, $question, $PAGE; $loaded_initialy = optional_param('reloaded_initialy', 1, PARAM_INT); $qtype = question_bank::get_qtype('javaunittest'); $definitionoptions = $this->_customdata['definitionoptions']; $attachmentoptions = $this->_customdata['attachmentoptions']; // -------------------------- feedback options $mform->addElement('select', 'feedbacklevel', get_string('feedbacklevel', 'qtype_javaunittest'), $qtype->feedback_levels()); $mform->setDefault('feedbacklevel', FEEDBACK_ONLY_TIMES); // -------------------------- auditlevel options $mform->addElement('select', 'auditlevel', get_string('auditlevel', 'qtype_javaunittest'), $qtype->audit_values()); $mform->setDefault('auditlevel', AUDIT_VALUE_30); // -------------------------- size of the response field $mform->addElement('select', 'responsefieldlines', get_string('responsefieldlines', 'qtype_javaunittest'), $qtype->response_sizes()); $mform->setDefault('responsefieldlines', 15); // -------------------------- "Given Code" Text-Area Modded /*$attributes['rows'] = 20; $attributes['cols'] = 80; $init_page = '<script language="javascript" type="text/javascript" '; $init_page .= 'src="/mod/editarea_0_8_2/edit_area/edit_area_full.js"></script> '; #$init_page .= 'src="http://www.cdolivet.com/editarea/editarea/edit_area/edit_area_full.js"></script> '; #$init_page .= 'src=" http://lms-test2.eigsi.fr/inc/edit_area/edit_area_full.js"></script> '; $init_page .= '<script language="javascript" type="text/javascript"> '; $init_page .= 'editAreaLoader.init({id : "' . $attributes['id'] . '",syntax: "java",start_highlight: true,is_editable: ' . 'true' .' }); '; $init_page .= ' </script> '; $mform->addElement ( 'textarea', 'givencode', get_string ( 'givencode', 'qtype_javaunittest' ), array ( 'cols' => 80, 'rows' => 20, ) ); $mform->setType ( 'givencode', PARAM_RAW ); $mform->addHelpButton ( 'givencode', 'givencode', 'qtype_javaunittest' ); */ // -------------------------- "Given Code" Text-Area $mform->addElement('textarea', 'givencode', get_string('givencode', 'qtype_javaunittest'), array('cols' => 80, 'rows' => 20)); $mform->setType('givencode', PARAM_RAW); $mform->addHelpButton('givencode', 'givencode', 'qtype_javaunittest'); // -------------------------- "Test class" Text-Area $mform->addElement('textarea', 'testclassname', get_string('testclassname', 'qtype_javaunittest'), array('cols' => 80, 'rows' => 1)); $mform->setType('testclassname', PARAM_ALPHANUMEXT); $mform->addRule('testclassname', null, 'required'); $mform->addHelpButton('testclassname', 'testclassname', 'qtype_javaunittest'); $mform->addElement('textarea', 'junitcode', get_string('uploadtestclass', 'qtype_javaunittest'), array('cols' => 80, 'rows' => 20)); $mform->setType('junitcode', PARAM_RAW); $mform->addRule('junitcode', null, 'required'); $mform->addHelpButton('junitcode', 'uploadtestclass', 'qtype_javaunittest'); }
/** * Create a new question. The question is initialised using one of the * examples from the appropriate {@link question_test_helper} subclass. * Then, any files you want to change from the value in the base example you * can override using $overrides. * @param string $qtype the question type to create an example of. * @param string $which as for the corresponding argument of * {@link question_test_helper::get_question_form_data}. null for the default one. * @param array|stdClass $overrides any fields that should be different from the base example. */ public function create_question($qtype, $which = null, $overrides = null) { global $CFG; require_once $CFG->dirroot . '/question/engine/tests/helpers.php'; $fromform = test_question_maker::get_question_form_data($qtype, $which); $fromform = (object) $this->datagenerator->combine_defaults_and_record((array) $fromform, $overrides); $question = new stdClass(); $question->category = $fromform->category; $question->qtype = $qtype; $question->createdby = 0; return question_bank::get_qtype($qtype)->save_question($question, $fromform); }
/** * Add question-type specific form fields. * * @param MoodleQuickForm $mform the form being built. */ public function __construct($submiturl, $question) { global $DB; $this->question = $question; $this->qtypeobj = question_bank::get_qtype($this->question->qtype); // Validate the question category. if (!$category = $DB->get_record('question_categories', array('id' => $question->category))) { print_error('categorydoesnotexist', 'question', $returnurl); } $this->category = $category; $this->categorycontext = context::instance_by_id($category->contextid); parent::__construct($submiturl); }
/** * Makes a REGEXP question with (first) correct answer "it's blue, white and red" * partially correct answer must match "(it('s| is) |they are )?blue, white, red" * @return qtype_regexp_question */ public static function make_a_regexp_question() { question_bank::load_question_definition_classes('regexp'); $pm = new qtype_regexp_question(); self::initialise_a_question($pm); $pm->name = 'Regular expression short answer question'; $pm->questiontext = 'French flag colors : __________'; // generalfeedback is not needed in the REGEXP question type //$pm->generalfeedback = 'Generalfeedback: '; //$pm->regexpoptions = new regexp_options(); $pm->answers = array(13 => new question_answer(13, "it's blue, white and red", 1.0, 'ok', FORMAT_HTML), 14 => new question_answer(14, "(it('s| is) |they are )?blue, white, red", 0.8, 'yes', FORMAT_HTML), 15 => new question_answer(15, '--.*blue.*', 0.0, 'Missing blue!', FORMAT_HTML), 15 => new question_answer(15, '.*', 0.0, 'No, no, no! Try again', FORMAT_HTML)); $pm->qtype = question_bank::get_qtype('regexp'); return $pm; }
/** * @return qtype_linkerdesc_question */ public static function make_linkerdesc_question_info() { question_bank::load_question_definition_classes('linkerdesc'); $q = new qtype_linkerdesc_question(); test_question_maker::initialise_a_question($q); $q->defaultmark = 0; $q->penalty = 0; $q->length = 0; $q->name = 'Description'; $q->questiontext = 'Here is some information about the questions you are about to attempt.'; $q->generalfeedback = 'And here is some more text shown only on the review page.'; $q->qtype = question_bank::get_qtype('linkerdesc'); return $q; }
/** * Create a quiz add questions to it, walk through quiz attempts and then check results. * * @param array $quizsettings settings to override default settings for quiz created by generator. Taken from quizzes.csv. * @param PHPUnit_Extensions_Database_DataSet_ITable[] $csvdata of data read from csv file "questionsXX.csv", * "stepsXX.csv" and "responsesXX.csv". * @dataProvider get_data_for_walkthrough */ public function test_walkthrough_from_csv($quizsettings, $csvdata) { $this->resetAfterTest(true); question_bank::get_qtype('random')->clear_caches_before_testing(); $this->create_quiz($quizsettings, $csvdata['questions']); $quizattemptids = $this->walkthrough_attempts($csvdata['steps']); for ($rowno = 0; $rowno < $csvdata['responses']->getRowCount(); $rowno++) { $responsesfromcsv = $csvdata['responses']->getRow($rowno); $responses = $this->explode_dot_separated_keys_to_make_subindexs($responsesfromcsv); if (!isset($quizattemptids[$responses['quizattempt']])) { throw new coding_exception("There is no quizattempt {$responses['quizattempt']}!"); } $this->assert_response_test($quizattemptids[$responses['quizattempt']], $responses); } }
/** * Makes a multichoice all or nothing question with choices 'A', 'B', 'C' and 'D' shuffled. * 'A' and 'C' is correct, defaultmark 1. * @return qtype_multichoiceset_question */ public static function make_a_multichoiceset_question() { question_bank::load_question_definition_classes('multichoiceset'); $mc = new qtype_multichoiceset_question(); test_question_maker::initialise_a_question($mc); $mc->name = 'Multi-choice all or nothing question'; $mc->questiontext = 'The answer is A and C.'; $mc->generalfeedback = 'You should have selected A and C.'; $mc->qtype = question_bank::get_qtype('multichoiceset'); $mc->shuffleanswers = 1; $mc->answernumbering = 'abc'; test_question_maker::set_standard_combined_feedback_fields($mc); $mc->answers = array(13 => new question_answer(13, 'A', 0.5, 'A is part of the right answer', FORMAT_HTML), 14 => new question_answer(14, 'B', 0, 'B is wrong', FORMAT_HTML), 15 => new question_answer(15, 'C', 0.5, 'C is part of the right answer', FORMAT_HTML), 16 => new question_answer(16, 'D', 0, 'D is wrong', FORMAT_HTML)); return $mc; }
/** * Makes a turmultiplechoice question with choices 'A', 'B', 'C' and 'D' shuffled. * 'A' and 'C' is correct, defaultmark 1. * @return qtype_turmultiplechoice_multi_question */ public static function make_a_turmultiplechoice_multi_question() { question_bank::load_question_definition_classes('turmultiplechoice'); $mc = new qtype_turmultiplechoice_multi_question(); self::initialise_a_question($mc); $mc->name = 'Multi-choice question, multiple response'; $mc->questiontext = 'The answer is A and C.'; $mc->generalfeedback = 'You should have selected A and C.'; $mc->qtype = question_bank::get_qtype('turmultiplechoice'); $mc->shuffleanswers = 1; $mc->qdifficulty = '0'; self::set_standard_combined_feedback_fields($mc); $mc->answers = array(13 => new question_answer(13, 'A', 0.5, 'A is part of the right answer', FORMAT_HTML), 14 => new question_answer(14, 'B', -1, 'B is wrong', FORMAT_HTML), 15 => new question_answer(15, 'C', 0.5, 'C is part of the right answer', FORMAT_HTML), 16 => new question_answer(16, 'D', -1, 'D is wrong', FORMAT_HTML)); return $mc; }
/** * Helper method to reduce duplication. * @return qtype_essay_question */ protected function initialise_essay_question() { question_bank::load_question_definition_classes('essay'); $q = new qtype_essay_question(); test_question_maker::initialise_a_question($q); $q->name = 'Essay question (HTML editor)'; $q->questiontext = 'Please write a story about a frog.'; $q->generalfeedback = 'I hope your story had a beginning, a middle and an end.'; $q->responseformat = 'editor'; $q->responsefieldlines = 10; $q->attachments = 0; $q->graderinfo = ''; $q->graderinfoformat = FORMAT_HTML; $q->qtype = question_bank::get_qtype('essay'); return $q; }
/** * @return qtype_ddimageortext_question */ public function make_ddimageortext_question_maths() { question_bank::load_question_definition_classes('ddimageortext'); $dd = new qtype_ddimageortext_question(); test_question_maker::initialise_a_question($dd); $dd->name = 'Drag-and-drop onto image question'; $dd->questiontext = 'Fill in the operators to make this equation work: ' . '7 [[1]] 11 [[2]] 13 [[1]] 17 [[2]] 19 = 3'; $dd->generalfeedback = 'This sentence uses each letter of the alphabet.'; $dd->qtype = question_bank::get_qtype('ddimageortext'); $dd->shufflechoices = true; test_question_maker::set_standard_combined_feedback_fields($dd); $dd->choices = $this->make_choice_structure(array(new qtype_ddimageortext_drag_item('+', 1, 1), new qtype_ddimageortext_drag_item('-', 2, 1))); $dd->places = $this->make_place_structure(array(new qtype_ddimageortext_drop_zone('', 1, 1), new qtype_ddimageortext_drop_zone('', 2, 1), new qtype_ddimageortext_drop_zone('', 3, 1), new qtype_ddimageortext_drop_zone('', 4, 1))); $dd->rightchoices = array(1 => 1, 2 => 2, 3 => 1, 4 => 2); return $dd; }
/** * @return qtype_gapselect_question */ public static function make_a_maths_gapselect_question() { question_bank::load_question_definition_classes('gapselect'); $gapselect = new qtype_gapselect_question(); test_question_maker::initialise_a_question($gapselect); $gapselect->name = 'Selection from drop down list question'; $gapselect->questiontext = 'Fill in the operators to make this equation work: ' . '7 [[1]] 11 [[2]] 13 [[1]] 17 [[2]] 19 = 3'; $gapselect->generalfeedback = 'This sentence uses each letter of the alphabet.'; $gapselect->qtype = question_bank::get_qtype('gapselect'); $gapselect->shufflechoices = true; test_question_maker::set_standard_combined_feedback_fields($gapselect); $gapselect->choices = array(1 => array(1 => new qtype_gapselect_choice('+', 1, true), 2 => new qtype_gapselect_choice('-', 1, true), 3 => new qtype_gapselect_choice('*', 1, true), 4 => new qtype_gapselect_choice('/', 1, true))); $gapselect->places = array(1 => 1, 2 => 1, 3 => 1, 4 => 1); $gapselect->rightchoices = array(1 => 1, 2 => 2, 3 => 1, 4 => 2); $gapselect->textfragments = array('7 ', ' 11 ', ' 13 ', ' 17 ', ' 19 = 3'); return $gapselect; }