Merge branch 'MDL-37600' of git://github.com/timhunt/moodle

This commit is contained in:
Dan Poltawski
2013-01-29 16:49:58 +08:00
16 changed files with 412 additions and 309 deletions
+10 -12
View File
@@ -1,5 +1,4 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -16,8 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* @package qtype
* @subpackage match
* @package qtype_match
* @copyright 2011 David Mudrak <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -25,7 +23,7 @@
defined('MOODLE_INTERNAL') || die();
/**
* Matching question type conversion handler
* Matching question type conversion handler.
*/
class moodle1_qtype_match_handler extends moodle1_qtype_handler {
@@ -35,19 +33,19 @@ class moodle1_qtype_match_handler extends moodle1_qtype_handler {
public function get_question_subpaths() {
return array(
'MATCHOPTIONS',
'MATCHS/MATCH'
'MATCHS/MATCH',
);
}
/**
* Appends the match specific information to the question
* Appends the match specific information to the question.
*/
public function process_question(array $data, array $raw) {
global $CFG;
// populate the list of matches first to get their ids
// note that the field is re-populated on restore anyway but let us
// do our best to produce valid backup files
// Populate the list of matches first to get their ids.
// Note that the field is re-populated on restore anyway but let us
// do our best to produce valid backup files.
$matchids = array();
if (isset($data['matchs']['match'])) {
foreach ($data['matchs']['match'] as $match) {
@@ -55,7 +53,7 @@ class moodle1_qtype_match_handler extends moodle1_qtype_handler {
}
}
// convert match options
// Convert match options.
if (isset($data['matchoptions'])) {
$matchoptions = $data['matchoptions'][0];
} else {
@@ -65,11 +63,11 @@ class moodle1_qtype_match_handler extends moodle1_qtype_handler {
$matchoptions['subquestions'] = implode(',', $matchids);
$this->write_xml('matchoptions', $matchoptions, array('/matchoptions/id'));
// convert matches
// Convert matches.
$this->xmlwriter->begin_tag('matches');
if (isset($data['matchs']['match'])) {
foreach ($data['matchs']['match'] as $match) {
// replay the upgrade step 2009072100
// Replay the upgrade step 2009072100.
$match['questiontextformat'] = 0;
if ($CFG->texteditors !== 'textarea' and $data['oldquestiontextformat'] == FORMAT_MOODLE) {
$match['questiontext'] = text_to_html($match['questiontext'], false, false, true);
@@ -26,7 +26,7 @@ defined('MOODLE_INTERNAL') || die();
/**
* Provides the information to backup match questions
* Provides the information to backup match questions.
*
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
@@ -34,58 +34,58 @@ defined('MOODLE_INTERNAL') || die();
class backup_qtype_match_plugin extends backup_qtype_plugin {
/**
* Returns the qtype information to attach to question element
* Returns the qtype information to attach to question element.
*/
protected function define_question_plugin_structure() {
// Define the virtual plugin element with the condition to fulfill
// Define the virtual plugin element with the condition to fulfill.
$plugin = $this->get_plugin_element(null, '../../qtype', 'match');
// Create one standard named plugin element (the visible container)
// Create one standard named plugin element (the visible container).
$pluginwrapper = new backup_nested_element($this->get_recommended_name());
// connect the visible container ASAP
// Connect the visible container ASAP.
$plugin->add_child($pluginwrapper);
// Now create the qtype own structures
// Now create the qtype own structures.
$matchoptions = new backup_nested_element('matchoptions', array('id'), array(
'subquestions', 'shuffleanswers', 'correctfeedback', 'correctfeedbackformat',
'shuffleanswers', 'correctfeedback', 'correctfeedbackformat',
'partiallycorrectfeedback', 'partiallycorrectfeedbackformat',
'incorrectfeedback', 'incorrectfeedbackformat', 'shownumcorrect'));
$matches = new backup_nested_element('matches');
$match = new backup_nested_element('match', array('id'), array(
'code', 'questiontext', 'questiontextformat', 'answertext'));
'questiontext', 'questiontextformat', 'answertext'));
// Now the own qtype tree
// Now the own qtype tree.
$pluginwrapper->add_child($matchoptions);
$pluginwrapper->add_child($matches);
$matches->add_child($match);
// set source to populate the data
$matchoptions->set_source_table('question_match',
array('question' => backup::VAR_PARENTID));
// Set source to populate the data.
$matchoptions->set_source_table('qtype_match_options',
array('questionid' => backup::VAR_PARENTID));
$match->set_source_sql('
SELECT *
FROM {question_match_sub}
WHERE question = :question
FROM {qtype_match_subquestions}
WHERE questionid = :questionid
ORDER BY id',
array('question' => backup::VAR_PARENTID));
array('questionid' => backup::VAR_PARENTID));
// don't need to annotate ids nor files
// Don't need to annotate ids nor files.
return $plugin;
}
/**
* Returns one array with filearea => mappingname elements for the qtype
* Returns one array with filearea => mappingname elements for the qtype.
*
* Used by {@link get_components_and_fileareas} to know about all the qtype
* files to be processed both in backup and restore.
*/
public static function get_qtype_fileareas() {
return array(
'subquestion' => 'question_match_sub');
'subquestion' => 'qtype_match_subquestions');
}
}
@@ -26,8 +26,8 @@ defined('MOODLE_INTERNAL') || die();
/**
* restore plugin class that provides the necessary information
* needed to restore one match qtype plugin
* Restore plugin class that provides the necessary information
* needed to restore one match qtype plugin.
*
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
@@ -35,13 +35,13 @@ defined('MOODLE_INTERNAL') || die();
class restore_qtype_match_plugin extends restore_qtype_plugin {
/**
* Returns the paths to be handled by the plugin at question level
* Returns the paths to be handled by the plugin at question level.
*/
protected function define_question_plugin_structure() {
$paths = array();
// Add own qtype stuff
// Add own qtype stuff.
$elename = 'matchoptions';
// We used get_recommended_name() so this works.
$elepath = $this->get_pathfor('/matchoptions');
@@ -52,7 +52,7 @@ class restore_qtype_match_plugin extends restore_qtype_plugin {
$elepath = $this->get_pathfor('/matches/match');
$paths[] = new restore_path_element($elename, $elepath);
return $paths; // And we return the interesting paths
return $paths;
}
/**
@@ -64,12 +64,12 @@ class restore_qtype_match_plugin extends restore_qtype_plugin {
$data = (object)$data;
$oldid = $data->id;
// Detect if the question is created or mapped
// Detect if the question is created or mapped.
$oldquestionid = $this->get_old_parentid('question');
$newquestionid = $this->get_new_parentid('question');
$questioncreated = $this->get_mappingid('question_created', $oldquestionid) ? true : false;
// If the question has been created by restore, we need to create its question_match too
// If the question has been created by restore, we need to create its qtype_match_options too.
if ($questioncreated) {
// Fill in some field that were added in 2.1, and so which may be missing
// from backups made in older versions of Moodle.
@@ -89,15 +89,10 @@ class restore_qtype_match_plugin extends restore_qtype_plugin {
$data->shownumcorrect = 0;
}
// Adjust some columns
$data->question = $newquestionid;
// Keep question_match->subquestions unmodified
// after_execute_question() will perform the remapping once all subquestions
// have been created
// Insert record
$newitemid = $DB->insert_record('question_match', $data);
// Create mapping
$this->set_mapping('question_match', $oldid, $newitemid);
// Adjust some columns.
$data->questionid = $newquestionid;
$newitemid = $DB->insert_record('qtype_match_options', $data);
$this->set_mapping('qtype_match_options', $oldid, $newitemid);
}
}
@@ -110,44 +105,49 @@ class restore_qtype_match_plugin extends restore_qtype_plugin {
$data = (object)$data;
$oldid = $data->id;
// Detect if the question is created or mapped
// Detect if the question is created or mapped.
$oldquestionid = $this->get_old_parentid('question');
$newquestionid = $this->get_new_parentid('question');
$questioncreated = $this->get_mappingid('question_created', $oldquestionid) ? true : false;
if ($questioncreated) {
// If the question has been created by restore, we need to create its
// question_match_sub too
// qtype_match_subquestions too.
// Adjust some columns
$data->question = $newquestionid;
// Insert record
$newitemid = $DB->insert_record('question_match_sub', $data);
// Create mapping (there are files and states based on this)
$this->set_mapping('question_match_sub', $oldid, $newitemid);
// Adjust some columns.
$data->questionid = $newquestionid;
// Insert record.
$newitemid = $DB->insert_record('qtype_match_subquestions', $data);
// Create mapping (there are files and states based on this).
$this->set_mapping('qtype_match_subquestions', $oldid, $newitemid);
if (isset($data->code)) {
$this->set_mapping('qtype_match_subquestion_codes', $data->code, $newitemid);
}
} else {
// match questions require mapping of question_match_sub, because
// they are used by question_states->answer
// Match questions require mapping of qtype_match_subquestions, because
// they are used by question_states->answer.
// Look for matching subquestion (by question, questiontext and answertext)
$sub = $DB->get_record_select('question_match_sub', 'question = ? AND ' .
// Look for matching subquestion (by questionid, questiontext and answertext).
$sub = $DB->get_record_select('qtype_match_subquestions', 'questionid = ? AND ' .
$DB->sql_compare_text('questiontext') . ' = ' .
$DB->sql_compare_text('?').' AND answertext = ?',
array($newquestionid, $data->questiontext, $data->answertext),
'id', IGNORE_MULTIPLE);
array($newquestionid, $data->questiontext, $data->answertext),
'id', IGNORE_MULTIPLE);
// Not able to find the answer, let's try cleaning the answertext
// of all the question answers in DB as slower fallback. MDL-36683 / MDL-30018.
// of all the match subquestions in DB as slower fallback. MDL-36683 / MDL-30018.
if (!$sub) {
$params = array('question' => $newquestionid);
$potentialsubs = $DB->get_records('question_match_sub', array('question' => $newquestionid), '', 'id, questiontext, answertext');
$potentialsubs = $DB->get_records('qtype_match_subquestions',
array('questionid' => $newquestionid), '', 'id, questiontext, answertext');
foreach ($potentialsubs as $potentialsub) {
// Clean in the same way than {@link xml_writer::xml_safe_utf8()}.
$cleanquestion = preg_replace('/[\x-\x8\xb-\xc\xe-\x1f\x7f]/is', '', $potentialsub->questiontext); // Clean CTRL chars.
$cleanquestion = preg_replace('/[\x-\x8\xb-\xc\xe-\x1f\x7f]/is',
'', $potentialsub->questiontext); // Clean CTRL chars.
$cleanquestion = preg_replace("/\r\n|\r/", "\n", $cleanquestion); // Normalize line ending.
$cleananswer = preg_replace('/[\x-\x8\xb-\xc\xe-\x1f\x7f]/is', '', $potentialsub->answertext); // Clean CTRL chars.
$cleananswer = preg_replace('/[\x-\x8\xb-\xc\xe-\x1f\x7f]/is',
'', $potentialsub->answertext); // Clean CTRL chars.
$cleananswer = preg_replace("/\r\n|\r/", "\n", $cleananswer); // Normalize line ending.
if ($cleanquestion === $data->questiontext && $cleananswer == $data->answertext) {
@@ -156,47 +156,15 @@ class restore_qtype_match_plugin extends restore_qtype_plugin {
}
}
// Found, let's create the mapping
// Found one. Let's create the mapping.
if ($sub) {
$this->set_mapping('question_match_sub', $oldid, $sub->id);
$this->set_mapping('qtype_match_subquestions', $oldid, $sub->id);
} else {
throw new restore_step_exception('error_question_match_sub_missing_in_db', $data);
throw new restore_step_exception('error_qtype_match_subquestion_missing_in_db', $data);
}
}
}
/**
* This method is executed once the whole restore_structure_step,
* more exactly ({@link restore_create_categories_and_questions})
* has ended processing the whole xml structure. Its name is:
* "after_execute_" + connectionpoint ("question")
*
* For match qtype we use it to restore the subquestions column,
* containing one list of question_match_sub ids
*/
public function after_execute_question() {
global $DB;
// Now that all the question_match_subs have been restored, let's process
// the created question_match subquestions (list of question_match_sub ids)
$rs = $DB->get_recordset_sql(
"SELECT qm.id, qm.subquestions
FROM {question_match} qm
JOIN {backup_ids_temp} bi ON bi.newitemid = qm.question
WHERE bi.backupid = ?
AND bi.itemname = 'question_created'", array($this->get_restoreid()));
foreach ($rs as $rec) {
$subquestionsarr = explode(',', $rec->subquestions);
foreach ($subquestionsarr as $key => $subquestion) {
$subquestionsarr[$key] = $this->get_mappingid(
'question_match_sub', $subquestion);
}
$subquestions = implode(',', $subquestionsarr);
$DB->set_field('question_match', 'subquestions', $subquestions,
array('id' => $rec->id));
}
$rs->close();
}
public function recode_response($questionid, $sequencenumber, array $response) {
if (array_key_exists('_stemorder', $response)) {
$response['_stemorder'] = $this->recode_match_sub_order($response['_stemorder']);
@@ -209,10 +177,11 @@ class restore_qtype_match_plugin extends restore_qtype_plugin {
/**
* Given one question_states record, return the answer
* recoded pointing to all the restored stuff for match questions
* recoded pointing to all the restored stuff for match questions.
*
* answer is one comma separated list of hypen separated pairs
* containing question_match_sub->id and question_match_sub->code
* containing question_match_sub->id and question_match_sub->code, which
* has been remapped to be qtype_match_subquestions->id, since code no longer exists.
*/
public function recode_legacy_state_answer($state) {
$answer = $state->answer;
@@ -221,8 +190,13 @@ class restore_qtype_match_plugin extends restore_qtype_plugin {
$pairarr = explode('-', $pair);
$id = $pairarr[0];
$code = $pairarr[1];
$newid = $this->get_mappingid('question_match_sub', $id);
$resultarr[] = implode('-', array($newid, $code));
$newid = $this->get_mappingid('qtype_match_subquestions', $id);
if ($code) {
$newcode = $this->get_mappingid('qtype_match_subquestion_codes', $code);
} else {
$newcode = $code;
}
$resultarr[] = $newid . '-' . $newcode;
}
return implode(',', $resultarr);
}
@@ -235,7 +209,7 @@ class restore_qtype_match_plugin extends restore_qtype_plugin {
protected function recode_match_sub_order($order) {
$neworder = array();
foreach (explode(',', $order) as $id) {
if ($newid = $this->get_mappingid('question_match_sub', $id)) {
if ($newid = $this->get_mappingid('qtype_match_subquestions', $id)) {
$neworder[] = $newid;
}
}
@@ -243,17 +217,17 @@ class restore_qtype_match_plugin extends restore_qtype_plugin {
}
/**
* Return the contents of this qtype to be processed by the links decoder
* Return the contents of this qtype to be processed by the links decoder.
*/
public static function define_decode_contents() {
$contents = array();
$contents[] = new restore_decode_content('question_match_sub',
array('questiontext'), 'question_match_sub');
$contents[] = new restore_decode_content('qtype_match_subquestions',
array('questiontext'), 'qtype_match_subquestions');
$fields = array('correctfeedback', 'partiallycorrectfeedback', 'incorrectfeedback');
$contents[] = new restore_decode_content('question_match', $fields, 'question_match');
$contents[] = new restore_decode_content('qtype_match_options', $fields, 'qtype_match_options');
return $contents;
}
+15 -17
View File
@@ -1,41 +1,39 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="question/type/match/db" VERSION="20120122" COMMENT="XMLDB file for Moodle question/type/match"
<XMLDB PATH="question/type/match/db" VERSION="20130121" COMMENT="XMLDB file for Moodle question/type/match"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../../lib/xmldb/xmldb.xsd"
>
<TABLES>
<TABLE NAME="question_match" COMMENT="Defines fixed matching questions" NEXT="question_match_sub">
<TABLE NAME="qtype_match_options" COMMENT="Defines the question-type specific options for matching questions" NEXT="qtype_match_subquestions">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" NEXT="question"/>
<FIELD NAME="question" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="subquestions"/>
<FIELD NAME="subquestions" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="question" NEXT="shuffleanswers"/>
<FIELD NAME="shuffleanswers" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="1" SEQUENCE="false" PREVIOUS="subquestions" NEXT="correctfeedback"/>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" NEXT="questionid"/>
<FIELD NAME="questionid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Foreign key link to question.id." PREVIOUS="id" NEXT="shuffleanswers"/>
<FIELD NAME="shuffleanswers" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="1" SEQUENCE="false" PREVIOUS="questionid" NEXT="correctfeedback"/>
<FIELD NAME="correctfeedback" TYPE="text" NOTNULL="true" SEQUENCE="false" COMMENT="Feedback shown for any correct response." PREVIOUS="shuffleanswers" NEXT="correctfeedbackformat"/>
<FIELD NAME="correctfeedbackformat" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="correctfeedback" NEXT="partiallycorrectfeedback"/>
<FIELD NAME="partiallycorrectfeedback" TYPE="text" NOTNULL="true" SEQUENCE="false" COMMENT="Feedback shown for any partially correct response." PREVIOUS="correctfeedbackformat" NEXT="partiallycorrectfeedbackformat"/>
<FIELD NAME="partiallycorrectfeedbackformat" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="partiallycorrectfeedback" NEXT="incorrectfeedback"/>
<FIELD NAME="incorrectfeedback" TYPE="text" NOTNULL="true" SEQUENCE="false" COMMENT="Feedback shown for any incorrect response." PREVIOUS="partiallycorrectfeedbackformat" NEXT="incorrectfeedbackformat"/>
<FIELD NAME="incorrectfeedbackformat" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="incorrectfeedback" NEXT="shownumcorrect"/>
<FIELD NAME="shownumcorrect" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="If true, then when the user gets a multiple-response question partially correct, tell them how many choices they got correct alongside the feedback." PREVIOUS="incorrectfeedbackformat"/>
<FIELD NAME="shownumcorrect" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="If true, then when the user gets the question partially correct, tell them how many choices they got correct alongside the feedback." PREVIOUS="incorrectfeedbackformat"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="question"/>
<KEY NAME="question" TYPE="foreign" FIELDS="question" REFTABLE="question" REFFIELDS="id" PREVIOUS="primary"/>
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="questionid"/>
<KEY NAME="questionid" TYPE="foreign-unique" FIELDS="questionid" REFTABLE="question" REFFIELDS="id" PREVIOUS="primary"/>
</KEYS>
</TABLE>
<TABLE NAME="question_match_sub" COMMENT="Defines the subquestions that make up a matching question" PREVIOUS="question_match">
<TABLE NAME="qtype_match_subquestions" COMMENT="The subquestions that make up a matching question" PREVIOUS="qtype_match_options">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" NEXT="code"/>
<FIELD NAME="code" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Should this point to parent question_match-&amp;gt;id ?" PREVIOUS="id" NEXT="question"/>
<FIELD NAME="question" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="code" NEXT="questiontext"/>
<FIELD NAME="questiontext" TYPE="text" NOTNULL="true" SEQUENCE="false" PREVIOUS="question" NEXT="questiontextformat"/>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" NEXT="questionid"/>
<FIELD NAME="questionid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Foreign key link to question.id." PREVIOUS="id" NEXT="questiontext"/>
<FIELD NAME="questiontext" TYPE="text" NOTNULL="true" SEQUENCE="false" PREVIOUS="questionid" NEXT="questiontextformat"/>
<FIELD NAME="questiontextformat" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="questiontext" NEXT="answertext"/>
<FIELD NAME="answertext" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="questiontextformat"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="question"/>
<KEY NAME="question" TYPE="foreign" FIELDS="question" REFTABLE="question" REFFIELDS="id" PREVIOUS="primary"/>
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="questionid"/>
<KEY NAME="questionid" TYPE="foreign" FIELDS="questionid" REFTABLE="question" REFFIELDS="id" PREVIOUS="primary"/>
</KEYS>
</TABLE>
</TABLES>
</XMLDB>
</XMLDB>
+140 -10
View File
@@ -17,10 +17,9 @@
/**
* Matching question type upgrade code.
*
* @package qtype
* @subpackage match
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package qtype_match
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -36,17 +35,148 @@ function xmldb_qtype_match_upgrade($oldversion) {
$dbman = $DB->get_manager();
// Moodle v2.2.0 release upgrade line.
// Put any upgrade step following this.
// Moodle v2.2.0 release upgrade line
// Put any upgrade step following this
// Moodle v2.3.0 release upgrade line.
// Put any upgrade step following this.
// Moodle v2.3.0 release upgrade line
// Put any upgrade step following this
// Moodle v2.4.0 release upgrade line.
// Put any upgrade step following this.
if ($oldversion < 2013012100) {
// Moodle v2.4.0 release upgrade line
// Put any upgrade step following this
// Define table question_match to be renamed to qtype_match_options.
$table = new xmldb_table('question_match');
// Launch rename table for qtype_match_options.
$dbman->rename_table($table, 'qtype_match_options');
// Record that qtype_match savepoint was reached.
upgrade_plugin_savepoint(true, 2013012100, 'qtype', 'match');
}
if ($oldversion < 2013012101) {
// Define key question (foreign) to be dropped form qtype_match_options.
$table = new xmldb_table('qtype_match_options');
$key = new xmldb_key('question', XMLDB_KEY_FOREIGN, array('question'), 'question', array('id'));
// Launch drop key question.
$dbman->drop_key($table, $key);
// Record that qtype_match savepoint was reached.
upgrade_plugin_savepoint(true, 2013012101, 'qtype', 'match');
}
if ($oldversion < 2013012102) {
// Rename field question on table qtype_match_options to questionid.
$table = new xmldb_table('qtype_match_options');
$field = new xmldb_field('question', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'id');
// Launch rename field question.
$dbman->rename_field($table, $field, 'questionid');
// Record that qtype_match savepoint was reached.
upgrade_plugin_savepoint(true, 2013012102, 'qtype', 'match');
}
if ($oldversion < 2013012103) {
// Define key questionid (foreign-unique) to be added to qtype_match_options.
$table = new xmldb_table('qtype_match_options');
$key = new xmldb_key('questionid', XMLDB_KEY_FOREIGN_UNIQUE, array('questionid'), 'question', array('id'));
// Launch add key questionid.
$dbman->add_key($table, $key);
// Record that qtype_match savepoint was reached.
upgrade_plugin_savepoint(true, 2013012103, 'qtype', 'match');
}
if ($oldversion < 2013012104) {
// Define field subquestions to be dropped from qtype_match_options.
$table = new xmldb_table('qtype_match_options');
$field = new xmldb_field('subquestions');
// Conditionally launch drop field subquestions.
if ($dbman->field_exists($table, $field)) {
$dbman->drop_field($table, $field);
}
// Record that qtype_match savepoint was reached.
upgrade_plugin_savepoint(true, 2013012104, 'qtype', 'match');
}
if ($oldversion < 2013012105) {
// Define table question_match_sub to be renamed to qtype_match_subquestions.
$table = new xmldb_table('question_match_sub');
// Launch rename table for qtype_match_subquestions.
$dbman->rename_table($table, 'qtype_match_subquestions');
// Record that qtype_match savepoint was reached.
upgrade_plugin_savepoint(true, 2013012105, 'qtype', 'match');
}
if ($oldversion < 2013012106) {
// Define key question (foreign) to be dropped form qtype_match_subquestions.
$table = new xmldb_table('qtype_match_subquestions');
$key = new xmldb_key('question', XMLDB_KEY_FOREIGN, array('question'), 'question', array('id'));
// Launch drop key question.
$dbman->drop_key($table, $key);
// Record that qtype_match savepoint was reached.
upgrade_plugin_savepoint(true, 2013012106, 'qtype', 'match');
}
if ($oldversion < 2013012107) {
// Rename field question on table qtype_match_subquestions to questionid.
$table = new xmldb_table('qtype_match_subquestions');
$field = new xmldb_field('question', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'id');
// Launch rename field question.
$dbman->rename_field($table, $field, 'questionid');
// Record that qtype_match savepoint was reached.
upgrade_plugin_savepoint(true, 2013012107, 'qtype', 'match');
}
if ($oldversion < 2013012108) {
// Define key questionid (foreign) to be added to qtype_match_subquestions.
$table = new xmldb_table('qtype_match_subquestions');
$key = new xmldb_key('questionid', XMLDB_KEY_FOREIGN, array('questionid'), 'question', array('id'));
// Launch add key questionid.
$dbman->add_key($table, $key);
// Record that qtype_match savepoint was reached.
upgrade_plugin_savepoint(true, 2013012108, 'qtype', 'match');
}
if ($oldversion < 2013012109) {
// Define field code to be dropped from qtype_match_subquestions.
// The field code has not been needed since the new question engine in
// Moodle 2.1. It should be safe to drop it now.
$table = new xmldb_table('qtype_match_subquestions');
$field = new xmldb_field('code');
// Conditionally launch drop field code.
if ($dbman->field_exists($table, $field)) {
$dbman->drop_field($table, $field);
}
// Record that qtype_match savepoint was reached.
upgrade_plugin_savepoint(true, 2013012109, 'qtype', 'match');
}
return true;
}
+6 -7
View File
@@ -17,10 +17,9 @@
/**
* Upgrade library code for the match question type.
*
* @package qtype
* @subpackage match
* @copyright 2010 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package qtype_match
* @copyright 2010 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -33,8 +32,8 @@ defined('MOODLE_INTERNAL') || die();
*
* This class is used by the code in question/engine/upgrade/upgradelib.php.
*
* @copyright 2010 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright 2010 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_match_qe2_attempt_updater extends question_qtype_attempt_updater {
protected $stems;
@@ -98,7 +97,7 @@ class qtype_match_qe2_attempt_updater extends question_qtype_attempt_updater {
protected function lookup_choice($choice) {
foreach ($this->question->options->subquestions as $matchsub) {
if ($matchsub->code == $choice) {
if ($matchsub->id == $choice) {
if (array_key_exists($matchsub->id, $this->choices)) {
return $matchsub->id;
} else {
+9 -15
View File
@@ -17,10 +17,9 @@
/**
* Defines the editing form for the match question type.
*
* @package qtype
* @subpackage match
* @copyright 2007 Jamie Pratt [email protected]
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package qtype_match
* @copyright 2007 Jamie Pratt [email protected]
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -30,8 +29,8 @@ defined('MOODLE_INTERNAL') || die();
/**
* Match question type editing form definition.
*
* @copyright 2007 Jamie Pratt [email protected]
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright 2007 Jamie Pratt [email protected]
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_match_edit_form extends question_edit_form {
@@ -88,15 +87,10 @@ class qtype_match_edit_form extends question_edit_form {
$draftid = file_get_submitted_draft_itemid('subquestions[' . $key . ']');
$question->subquestions[$key] = array();
$question->subquestions[$key]['text'] = file_prepare_draft_area(
$draftid, // draftid
$this->context->id, // context
'qtype_match', // component
'subquestion', // filarea
!empty($subquestion->id) ? (int) $subquestion->id : null, // itemid
$this->fileoptions, // options
$subquestion->questiontext // text
);
$question->subquestions[$key]['text'] = file_prepare_draft_area($draftid,
$this->context->id, 'qtype_match', 'subquestion',
!empty($subquestion->id) ? (int) $subquestion->id : null,
$this->fileoptions, $subquestion->questiontext);
$question->subquestions[$key]['format'] = $subquestion->questiontextformat;
$question->subquestions[$key]['itemid'] = $draftid;
$key++;
+3 -4
View File
@@ -17,10 +17,9 @@
/**
* Strings for component 'qtype_match', language 'en', branch 'MOODLE_20_STABLE'
*
* @package qtype
* @subpackage match
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package qtype_match
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['addmoreqblanks'] = '{no} More Sets of Blanks';
+6 -7
View File
@@ -17,10 +17,9 @@
/**
* Matching question definition class.
*
* @package qtype
* @subpackage match
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package qtype_match
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -30,8 +29,8 @@ defined('MOODLE_INTERNAL') || die();
/**
* Represents a matching question.
*
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_match_question extends question_graded_automatically_with_countback {
/** @var boolean Whether the question stems should be shuffled. */
@@ -273,7 +272,7 @@ class qtype_match_question extends question_graded_automatically_with_countback
public function check_file_access($qa, $options, $component, $filearea, $args, $forcedownload) {
if ($component == 'qtype_match' && $filearea == 'subquestion') {
$subqid = reset($args); // itemid is sub question id
$subqid = reset($args); // Itemid is sub question id.
return array_key_exists($subqid, $this->stems);
} else if ($component == 'question' && in_array($filearea,
+27 -44
View File
@@ -17,10 +17,9 @@
/**
* Question type class for the matching question type.
*
* @package qtype
* @subpackage match
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package qtype_match
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -33,17 +32,18 @@ require_once($CFG->dirroot . '/question/engine/lib.php');
/**
* The matching question type class.
*
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_match extends question_type {
public function get_question_options($question) {
global $DB;
parent::get_question_options($question);
$question->options = $DB->get_record('question_match', array('question' => $question->id));
$question->options->subquestions = $DB->get_records('question_match_sub',
array('question' => $question->id), 'id ASC');
$question->options = $DB->get_record('qtype_match_options',
array('questionid' => $question->id));
$question->options->subquestions = $DB->get_records('qtype_match_subquestions',
array('questionid' => $question->id), 'id ASC');
return true;
}
@@ -52,13 +52,10 @@ class qtype_match extends question_type {
$context = $question->context;
$result = new stdClass();
$oldsubquestions = $DB->get_records('question_match_sub',
array('question' => $question->id), 'id ASC');
$oldsubquestions = $DB->get_records('qtype_match_subquestions',
array('questionid' => $question->id), 'id ASC');
// $subquestions will be an array with subquestion ids
$subquestions = array();
// Insert all the new question+answer pairs
// Insert all the new question & answer pairs.
foreach ($question->subquestions as $key => $questiontext) {
if ($questiontext['text'] == '' && trim($question->subanswers[$key]) == '') {
continue;
@@ -71,16 +68,10 @@ class qtype_match extends question_type {
$subquestion = array_shift($oldsubquestions);
if (!$subquestion) {
$subquestion = new stdClass();
// Determine a unique random code
$subquestion->code = rand(1, 999999999);
while ($DB->record_exists('question_match_sub',
array('code' => $subquestion->code, 'question' => $question->id))) {
$subquestion->code = rand(1, 999999999);
}
$subquestion->question = $question->id;
$subquestion->questionid = $question->id;
$subquestion->questiontext = '';
$subquestion->answertext = '';
$subquestion->id = $DB->insert_record('question_match_sub', $subquestion);
$subquestion->id = $DB->insert_record('qtype_match_subquestions', $subquestion);
}
$subquestion->questiontext = $this->import_or_save_files($questiontext,
@@ -88,33 +79,30 @@ class qtype_match extends question_type {
$subquestion->questiontextformat = $questiontext['format'];
$subquestion->answertext = trim($question->subanswers[$key]);
$DB->update_record('question_match_sub', $subquestion);
$subquestions[] = $subquestion->id;
$DB->update_record('qtype_match_subquestions', $subquestion);
}
// Delete old subquestions records
// Delete old subquestions records.
$fs = get_file_storage();
foreach ($oldsubquestions as $oldsub) {
$fs->delete_area_files($context->id, 'qtype_match', 'subquestion', $oldsub->id);
$DB->delete_records('question_match_sub', array('id' => $oldsub->id));
$DB->delete_records('qtype_match_subquestions', array('id' => $oldsub->id));
}
// Save the question options.
$options = $DB->get_record('question_match', array('question' => $question->id));
$options = $DB->get_record('qtype_match_options', array('questionid' => $question->id));
if (!$options) {
$options = new stdClass();
$options->question = $question->id;
$options->questionid = $question->id;
$options->correctfeedback = '';
$options->partiallycorrectfeedback = '';
$options->incorrectfeedback = '';
$options->id = $DB->insert_record('question_match', $options);
$options->id = $DB->insert_record('qtype_match_options', $options);
}
$options->subquestions = implode(',', $subquestions);
$options->shuffleanswers = $question->shuffleanswers;
$options = $this->save_combined_feedback_helper($options, $question, $context, true);
$DB->update_record('question_match', $options);
$DB->update_record('qtype_match_options', $options);
$this->save_hints($question, true);
@@ -122,11 +110,6 @@ class qtype_match extends question_type {
return $result;
}
if (count($subquestions) < 3) {
$result->notice = get_string('notenoughanswers', 'question', 3);
return $result;
}
return true;
}
@@ -162,8 +145,8 @@ class qtype_match extends question_type {
public function delete_question($questionid, $contextid) {
global $DB;
$DB->delete_records('question_match', array('question' => $questionid));
$DB->delete_records('question_match_sub', array('question' => $questionid));
$DB->delete_records('qtype_match_options', array('questionid' => $questionid));
$DB->delete_records('qtype_match_subquestions', array('questionid' => $questionid));
parent::delete_question($questionid, $contextid);
}
@@ -200,8 +183,8 @@ class qtype_match extends question_type {
parent::move_files($questionid, $oldcontextid, $newcontextid);
$subquestionids = $DB->get_records_menu('question_match_sub',
array('question' => $questionid), 'id', 'id,1');
$subquestionids = $DB->get_records_menu('qtype_match_subquestions',
array('questionid' => $questionid), 'id', 'id,1');
foreach ($subquestionids as $subquestionid => $notused) {
$fs->move_area_files_to_new_context($oldcontextid,
$newcontextid, 'qtype_match', 'subquestion', $subquestionid);
@@ -217,8 +200,8 @@ class qtype_match extends question_type {
parent::delete_files($questionid, $contextid);
$subquestionids = $DB->get_records_menu('question_match_sub',
array('question' => $questionid), 'id', 'id,1');
$subquestionids = $DB->get_records_menu('qtype_match_subquestions',
array('questionid' => $questionid), 'id', 'id,1');
foreach ($subquestionids as $subquestionid => $notused) {
$fs->delete_area_files($contextid, 'qtype_match', 'subquestion', $subquestionid);
}
+9 -8
View File
@@ -17,10 +17,9 @@
/**
* Matching question renderer class.
*
* @package qtype
* @subpackage match
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package qtypematch
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -30,8 +29,8 @@ defined('MOODLE_INTERNAL') || die();
/**
* Generates the output for matching questions.
*
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_match_renderer extends qtype_with_combined_feedback_renderer {
@@ -81,7 +80,9 @@ class qtype_match_renderer extends qtype_with_combined_feedback_renderer {
}
$result .= html_writer::tag('td',
html_writer::label(get_string('answer', 'qtype_match', $i), 'menu' . $qa->get_qt_field_name('sub' . $key), false, array('class' => 'accesshide')) .
html_writer::label(get_string('answer', 'qtype_match', $i),
'menu' . $qa->get_qt_field_name('sub' . $key), false,
array('class' => 'accesshide')) .
html_writer::select($choices, $qa->get_qt_field_name('sub' . $key), $selected,
array('0' => 'choose'), array('disabled' => $options->readonly)) .
' ' . $feedbackimage, array('class' => $classes));
@@ -93,7 +94,7 @@ class qtype_match_renderer extends qtype_with_combined_feedback_renderer {
$result .= html_writer::end_tag('tbody');
$result .= html_writer::end_tag('table');
$result .= html_writer::end_tag('div'); // ablock
$result .= html_writer::end_tag('div'); // Closes <div class="ablock">.
if ($qa->get_state() == question_state::$invalid) {
$result .= html_writer::nonempty_tag('div',
+5 -6
View File
@@ -17,10 +17,9 @@
/**
* Unit tests for the matching question definition classes.
*
* @package qtype
* @subpackage match
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package qtype_match
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -33,8 +32,8 @@ require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
/**
* Unit tests for the matching question definition class.
*
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_match_question_test extends advanced_testcase {
@@ -17,10 +17,9 @@
/**
* Unit tests for the matching question definition class.
*
* @package qtype
* @subpackage match
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package qtype_match
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -34,8 +33,8 @@ require_once($CFG->dirroot . '/question/type/match/questiontype.php');
/**
* Unit tests for the matching question definition class.
*
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_match_test extends advanced_testcase {
/** @var qtype_match instance of the question type class to test. */
@@ -18,10 +18,9 @@
* Tests of the upgrade to the new Moodle question engine for attempts at
* match questions.
*
* @package qtype
* @subpackage match
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package qtype_match
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -34,8 +33,8 @@ require_once($CFG->dirroot . '/question/engine/upgrade/tests/helper.php');
/**
* Testing the upgrade of match question attempts.
*
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_match_attempt_upgrader_test extends question_attempt_upgrader_test_base {
@@ -110,39 +109,34 @@ class qtype_match_attempt_upgrader_test extends question_attempt_upgrader_test_b
'maxmark' => '3',
'options' => (object) array(
'id' => '27',
'question' => '695',
'questionid' => '695',
'subquestions' => array(
148 => (object) array(
'code' => '511093512',
'question' => '695',
'questionid' => '695',
'questiontext' => 'Active adjacent system',
'answertext' => 'A system that interacts with or participates in the work.',
'id' => 148,
),
149 => (object) array(
'code' => '10881658',
'question' => '695',
'questionid' => '695',
'questiontext' => 'Autonomous adjacent system',
'answertext' => 'An external entity that acts independently of the work under study.',
'id' => 149,
),
150 => (object) array(
'code' => '661953276',
'question' => '695',
'questionid' => '695',
'questiontext' => 'Cooperative adjacent system',
'answertext' => 'A system that is involved in the response to a business event.',
'id' => 150,
),
151 => (object) array(
'code' => '786218388',
'question' => '695',
'questionid' => '695',
'questiontext' => '',
'answertext' => 'A system which does not supply or receive data from the work.',
'id' => 151,
),
152 => (object) array(
'code' => '166673328',
'question' => '695',
'questionid' => '695',
'questiontext' => '',
'answertext' => 'An external entity that performs part of the work under study.',
'id' => 152,
@@ -186,7 +180,7 @@ class qtype_match_attempt_upgrader_test extends question_attempt_upgrader_test_b
'question' => '695',
'originalquestion' => '0',
'seq_number' => '1',
'answer' => '148-511093512,149-786218388,150-166673328,151-0,152-0',
'answer' => '148-148,149-151,150-152,151-0,152-0',
'timestamp' => '1177419855',
'event' => '2',
'grade' => '0',
@@ -199,7 +193,7 @@ class qtype_match_attempt_upgrader_test extends question_attempt_upgrader_test_b
'question' => '695',
'originalquestion' => '0',
'seq_number' => '2',
'answer' => '148-511093512,149-10881658,150-661953276,151-0,152-0',
'answer' => '148-148,149-149,150-150,151-0,152-0',
'timestamp' => '1177419956',
'event' => '2',
'grade' => '0',
@@ -212,7 +206,7 @@ class qtype_match_attempt_upgrader_test extends question_attempt_upgrader_test_b
'question' => '695',
'originalquestion' => '0',
'seq_number' => '3',
'answer' => '148-511093512,149-10881658,150-661953276,151-0,152-0',
'answer' => '148-148,149-149,150-150,151-0,152-0',
'timestamp' => '1177419956',
'event' => '6',
'grade' => '3',
@@ -231,9 +225,24 @@ class qtype_match_attempt_upgrader_test extends question_attempt_upgrader_test_b
'maxmark' => 3,
'minfraction' => 0,
'flagged' => 0,
'questionsummary' => 'Associate the appropriate definition with each term. {Active adjacent system; Autonomous adjacent system; Cooperative adjacent system} -> {A system that interacts with or participates in the work.; An external entity that acts independently of the work under study.; A system that is involved in the response to a business event.; A system which does not supply or receive data from the work.; An external entity that performs part of the work under study.}',
'rightanswer' => 'Active adjacent system -> A system that interacts with or participates in the work.; Autonomous adjacent system -> An external entity that acts independently of the work under study.; Cooperative adjacent system -> A system that is involved in the response to a business event.',
'responsesummary' => 'Active adjacent system -> A system that interacts with or participates in the work.; Autonomous adjacent system -> An external entity that acts independently of the work under study.; Cooperative adjacent system -> A system that is involved in the response to a business event.',
'questionsummary' => 'Associate the appropriate definition with each term. ' .
'{Active adjacent system; Autonomous adjacent system; ' .
'Cooperative adjacent system} -> {A system that interacts with ' .
'or participates in the work.; An external entity that acts ' .
'independently of the work under study.; A system that is involved ' .
'in the response to a business event.; A system which does not supply ' .
'or receive data from the work.; An external entity that performs part ' .
'of the work under study.}',
'rightanswer' => 'Active adjacent system -> A system that interacts with ' .
'or participates in the work.; Autonomous adjacent system -> ' .
'An external entity that acts independently of the work under study.; ' .
'Cooperative adjacent system -> A system that is involved in the response ' .
'to a business event.',
'responsesummary' => 'Active adjacent system -> A system that interacts with ' .
'or participates in the work.; Autonomous adjacent system -> ' .
'An external entity that acts independently of the work under study.; ' .
'Cooperative adjacent system -> A system that is involved in the response ' .
'to a business event.',
'timemodified' => 1177419956,
'steps' => array(
0 => (object) array(
@@ -242,7 +251,8 @@ class qtype_match_attempt_upgrader_test extends question_attempt_upgrader_test_b
'fraction' => null,
'timecreated' => 1177419915,
'userid' => 91483,
'data' => array('_stemorder' => '148,149,150', '_choiceorder' => 'todo - see below'),
'data' => array('_stemorder' => '148,149,150',
'_choiceorder' => 'todo - see below'),
),
1 => (object) array(
'sequencenumber' => 1,
@@ -271,7 +281,7 @@ class qtype_match_attempt_upgrader_test extends question_attempt_upgrader_test_b
),
);
// This is a random thing, so just set expected to actual:
// This is a random thing, so just set expected to actual.
$expectedqa->steps[0]->data['_choiceorder'] = $qa->steps[0]->data['_choiceorder'];
$order = explode(',', $qa->steps[0]->data['_choiceorder']);
$order = array_combine(array_values($order), array_keys($order));
@@ -290,7 +300,8 @@ class qtype_match_attempt_upgrader_test extends question_attempt_upgrader_test_b
'id' => '60',
'course' => '2304',
'name' => 'Types of resources available quiz',
'intro' => 'This quiz covers the different types of information resources available and how to select which is most appropriate. ',
'intro' => 'This quiz covers the different types of information resources available ' .
'and how to select which is most appropriate. ',
'introformat' => FORMAT_HTML,
'questiondecimalpoints' => '-1',
'showuserpicture' => '1',
@@ -360,33 +371,30 @@ class qtype_match_attempt_upgrader_test extends question_attempt_upgrader_test_b
'maxmark' => '1',
'options' => (object) array(
'id' => '35',
'question' => '738',
'questionid' => '738',
'subquestions' => array(
213 => (object) array(
'code' => '860968335',
'question' => '738',
'questionid' => '738',
'questiontext' => 'Subject gateways provide links to sites that have been quality checked ',
'answertext' => 'True',
'id' => 213,
),
214 => (object) array(
'code' => '253006016',
'question' => '738',
'questionid' => '738',
'questiontext' => 'Subject gateways offer more variety than search engines ',
'answertext' => 'False',
'id' => 214,
),
215 => (object) array(
'code' => '964910717',
'question' => '738',
'questionid' => '738',
'questiontext' => 'Subject gateways index websites automatically',
'answertext' => 'False',
'id' => 215,
),
216 => (object) array(
'code' => '3109713',
'question' => '738',
'questiontext' => 'Subject gateways can provide a more direct route to websites containing academic content ',
'questionid' => '738',
'questiontext' => 'Subject gateways can provide a more direct route ' .
'to websites containing academic content ',
'answertext' => 'True',
'id' => 216,
),
@@ -429,7 +437,7 @@ class qtype_match_attempt_upgrader_test extends question_attempt_upgrader_test_b
'question' => '738',
'originalquestion' => '0',
'seq_number' => '1',
'answer' => '213-860968335,214-253006016,215-964910717,216-3109713',
'answer' => '213-213,214-214,215-215,216-216',
'timestamp' => '1168267508',
'event' => '6',
'grade' => '1',
@@ -448,9 +456,21 @@ class qtype_match_attempt_upgrader_test extends question_attempt_upgrader_test_b
'maxmark' => 1,
'minfraction' => 0,
'flagged' => 0,
'questionsummary' => 'Which of the following statements about subject gateways are true, and which are false? {Subject gateways provide links to sites that have been quality checked; Subject gateways offer more variety than search engines; Subject gateways index websites automatically; Subject gateways can provide a more direct route to websites containing academic content} -> {True; False}',
'rightanswer' => 'Subject gateways provide links to sites that have been quality checked -> True; Subject gateways offer more variety than search engines -> False; Subject gateways index websites automatically -> False; Subject gateways can provide a more direct route to websites containing academic content -> True',
'responsesummary' => 'Subject gateways provide links to sites that have been quality checked -> True; Subject gateways offer more variety than search engines -> False; Subject gateways index websites automatically -> False; Subject gateways can provide a more direct route to websites containing academic content -> True',
'questionsummary' => 'Which of the following statements about subject ' .
'gateways are true, and which are false? {Subject gateways ' .
'provide links to sites that have been quality checked; ' .
'Subject gateways offer more variety than search engines; ' .
'Subject gateways index websites automatically; ' .
'Subject gateways can provide a more direct route to websites containing academic content} -> ' .
'{True; False}',
'rightanswer' => 'Subject gateways provide links to sites that have been quality checked -> True; ' .
'Subject gateways offer more variety than search engines -> False; ' .
'Subject gateways index websites automatically -> False; ' .
'Subject gateways can provide a more direct route to websites containing academic content -> True',
'responsesummary' => 'Subject gateways provide links to sites that have been quality checked -> True; ' .
'Subject gateways offer more variety than search engines -> False; ' .
'Subject gateways index websites automatically -> False; ' .
'Subject gateways can provide a more direct route to websites containing academic content -> True',
'timemodified' => 1168267508,
'steps' => array(
0 => (object) array(
@@ -467,12 +487,12 @@ class qtype_match_attempt_upgrader_test extends question_attempt_upgrader_test_b
'fraction' => 1,
'timecreated' => 1168267508,
'userid' => 182682,
'data' => array('sub0' => 213, 'sub1' => 214,'sub2' => 214,'sub3' => 213, '-finish' => 1),
'data' => array('sub0' => 213, 'sub1' => 214, 'sub2' => 214, 'sub3' => 213, '-finish' => 1),
),
),
);
// This is a random thing, so just set expected to actual:
// This is a random thing, so just set expected to actual.
$expectedqa->steps[0]->data['_choiceorder'] = $qa->steps[0]->data['_choiceorder'];
$order = explode(',', $qa->steps[0]->data['_choiceorder']);
$order = array_combine(array_values($order), array_keys($order));
@@ -550,11 +570,13 @@ class qtype_match_attempt_upgrader_test extends question_attempt_upgrader_test_b
'generalfeedback' => '<ul>
<li>Subject gateways provide links to sites that have been quality checked = True </li>
</ul>
<p>All links in a subject gateway have been added by a knowledgeable subject specialist and so have to be of a certain quality to be added to the collection.</p>
<p>All links in a subject gateway have been added by a knowledgeable subject specialist and ' .
'so have to be of a certain quality to be added to the collection.</p>
<ul>
<li>Subject gateways offer more variety than search engines = False </li>
</ul>
<p>Subject gateways will most likely provide fewer links than a search engine, but this is because they are selected with a particular subject area in mind </p>
<p>Subject gateways will most likely provide fewer links than a search engine, but this is because ' .
'they are selected with a particular subject area in mind </p>
<ul>
<li>Subject gateways index websites automatically = False </li>
</ul>
@@ -562,7 +584,8 @@ class qtype_match_attempt_upgrader_test extends question_attempt_upgrader_test_b
<ul>
<li>Subject gateways can provide a more direct route to websites containing academic content = True </li>
</ul>
<p>All links in a subject gateway have been added by a knowledgeable subject specialist and so you can find academic content easier than using a web search engine.</p>',
<p>All links in a subject gateway have been added by a knowledgeable subject specialist ' .
'and so you can find academic content easier than using a web search engine.</p>',
'generalfeedbackformat' => '1',
'timecreated' => '0',
'timemodified' => '0',
@@ -572,33 +595,30 @@ class qtype_match_attempt_upgrader_test extends question_attempt_upgrader_test_b
'maxmark' => '1',
'options' => (object) array(
'id' => '279',
'question' => '11135',
'questionid' => '11135',
'subquestions' => array(
1632 => (object) array(
'code' => '315604704',
'question' => '11135',
'questionid' => '11135',
'questiontext' => 'Subject gateways provide links to sites that have been quality checked',
'answertext' => 'True',
'id' => 1632,
),
1633 => (object) array(
'code' => '750106618',
'question' => '11135',
'questionid' => '11135',
'questiontext' => 'Subject gateways offer more variety than search engines',
'answertext' => 'False',
'id' => 1633,
),
1634 => (object) array(
'code' => '446418834',
'question' => '11135',
'questionid' => '11135',
'questiontext' => 'Subject gateways index websites automatically',
'answertext' => 'False',
'id' => 1634,
),
1635 => (object) array(
'code' => '3262827',
'question' => '11135',
'questiontext' => 'Subject gateways can provide a more direct route to websites containing academic content',
'questionid' => '11135',
'questiontext' => 'Subject gateways can provide a more direct route to websites ' .
'containing academic content',
'answertext' => 'True',
'id' => 1635,
),
@@ -641,7 +661,7 @@ class qtype_match_attempt_upgrader_test extends question_attempt_upgrader_test_b
'question' => '11135',
'originalquestion' => '0',
'seq_number' => '1',
'answer' => '1633-750106618,1635-3262827,1634-0,1632-315604704',
'answer' => '1633-1633,1635-1635,1634-0,1632-1632',
'timestamp' => '1200507025',
'event' => '2',
'grade' => '0',
@@ -654,7 +674,7 @@ class qtype_match_attempt_upgrader_test extends question_attempt_upgrader_test_b
'question' => '11135',
'originalquestion' => '0',
'seq_number' => '2',
'answer' => '1633-750106618,1635-3262827,1634-0,1632-315604704',
'answer' => '1633-1633,1635-1635,1634-0,1632-1632',
'timestamp' => '1200507125',
'event' => '2',
'grade' => '0',
@@ -667,7 +687,7 @@ class qtype_match_attempt_upgrader_test extends question_attempt_upgrader_test_b
'question' => '11135',
'originalquestion' => '0',
'seq_number' => '3',
'answer' => '1633-750106618,1635-3262827,1634-0,1632-315604704',
'answer' => '1633-1633,1635-1635,1634-0,1632-1632',
'timestamp' => '1200507172',
'event' => '2',
'grade' => '0',
@@ -680,7 +700,7 @@ class qtype_match_attempt_upgrader_test extends question_attempt_upgrader_test_b
'question' => '11135',
'originalquestion' => '0',
'seq_number' => '4',
'answer' => '1633-750106618,1635-3262827,1634-3262827,1632-315604704',
'answer' => '1633-1633,1635-1635,1634-1635,1632-1632',
'timestamp' => '1200507467',
'event' => '2',
'grade' => '0',
@@ -693,7 +713,7 @@ class qtype_match_attempt_upgrader_test extends question_attempt_upgrader_test_b
'question' => '11135',
'originalquestion' => '0',
'seq_number' => '5',
'answer' => '1633-750106618,1635-3262827,1634-3262827,1632-315604704',
'answer' => '1633-1633,1635-1635,1634-1635,1632-1632',
'timestamp' => '1200507467',
'event' => '6',
'grade' => '0.75',
@@ -712,9 +732,20 @@ class qtype_match_attempt_upgrader_test extends question_attempt_upgrader_test_b
'maxmark' => 1,
'minfraction' => 0,
'flagged' => 0,
'questionsummary' => 'Which of the following statements about subject gateways are true, and which are false? {Subject gateways provide links to sites that have been quality checked; Subject gateways offer more variety than search engines; Subject gateways index websites automatically; Subject gateways can provide a more direct route to websites containing academic content} -> {True; False}',
'rightanswer' => 'Subject gateways provide links to sites that have been quality checked -> True; Subject gateways offer more variety than search engines -> False; Subject gateways index websites automatically -> False; Subject gateways can provide a more direct route to websites containing academic content -> True',
'responsesummary' => 'Subject gateways offer more variety than search engines -> False; Subject gateways can provide a more direct route to websites containing academic content -> True; Subject gateways index websites automatically -> True; Subject gateways provide links to sites that have been quality checked -> True',
'questionsummary' => 'Which of the following statements about subject gateways are true, and which are false? ' .
'{Subject gateways provide links to sites that have been quality checked; ' .
'Subject gateways offer more variety than search engines; ' .
'Subject gateways index websites automatically; ' .
'Subject gateways can provide a more direct route to websites containing academic content} ' .
'-> {True; False}',
'rightanswer' => 'Subject gateways provide links to sites that have been quality checked -> True; ' .
'Subject gateways offer more variety than search engines -> False; ' .
'Subject gateways index websites automatically -> False; ' .
'Subject gateways can provide a more direct route to websites containing academic content -> True',
'responsesummary' => 'Subject gateways offer more variety than search engines -> False; ' .
'Subject gateways can provide a more direct route to websites containing academic content -> True; ' .
'Subject gateways index websites automatically -> True; ' .
'Subject gateways provide links to sites that have been quality checked -> True',
'timemodified' => 1200507467,
'steps' => array(
0 => (object) array(
@@ -723,7 +754,8 @@ class qtype_match_attempt_upgrader_test extends question_attempt_upgrader_test_b
'fraction' => null,
'timecreated' => 1200506648,
'userid' => 6584,
'data' => array('_stemorder' => '1633,1635,1634,1632', '_choiceorder' => 'todo - see below'),
'data' => array('_stemorder' => '1633,1635,1634,1632',
'_choiceorder' => 'todo - see below'),
),
1 => (object) array(
'sequencenumber' => 1,
@@ -768,7 +800,7 @@ class qtype_match_attempt_upgrader_test extends question_attempt_upgrader_test_b
),
);
// This is a random thing, so just set expected to actual:
// This is a random thing, so just set expected to actual.
$expectedqa->steps[0]->data['_choiceorder'] = $qa->steps[0]->data['_choiceorder'];
$order = explode(',', $qa->steps[0]->data['_choiceorder']);
$order = array_combine(array_values($order), array_keys($order));
@@ -18,10 +18,9 @@
* This file contains tests that walks a question through the interactive
* behaviour.
*
* @package qtype
* @subpackage match
* @copyright 2010 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package qtype_match
* @copyright 2010 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -34,8 +33,8 @@ require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
/**
* Unit tests for the matching question type.
*
* @copyright 2010 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright 2010 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_match_walkthrough_test extends qbehaviour_walkthrough_test_base {
+4 -5
View File
@@ -17,16 +17,15 @@
/**
* Version information for the matching question type.
*
* @package qtype
* @subpackage match
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package qtype_match
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->component = 'qtype_match';
$plugin->version = 2012112900;
$plugin->version = 2013012109;
$plugin->requires = 2012112900;