Skip to content

Commit

Permalink
First version of dragdrop matching question created by Adriane Boyd u…
Browse files Browse the repository at this point in the history
…pgraded to Moodle 2.3
  • Loading branch information
Jean-Michel Vedrine committed Sep 9, 2012
0 parents commit 4380fa0
Show file tree
Hide file tree
Showing 31 changed files with 3,839 additions and 0 deletions.
23 changes: 23 additions & 0 deletions README.txt
@@ -0,0 +1,23 @@
Drag-and-Drop Matching Question
-------------------------------

Author: Adriane Boyd (adrianeboyd@gmail.com)

Description:

The drag-and-drop question is adapted from the existing matching question.
The teacher editing interface and the grading have not been modified. The
fallback looks identical to the original matching question.

The drag-and-drop version of the student interface provides all the
answers in a list to the right of the question table. Answers can be
dragged from the list to each of the question targets. The current target
is highlighted to show where the answer will be dropped. To allow answers
to be used multiple times, dragging an answer from the list on the right
to a target puts a copy of the answer in the target. The current answer
for a question can be changed by dragging the answer off the target or by
dropping another answer on the target.

Grading:

The grading is identical to the original matching question.
85 changes: 85 additions & 0 deletions backup/moodle1/lib.php
@@ -0,0 +1,85 @@
<?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* @package qtype
* @subpackage ddmatch
* @copyright 2011 David Mudrak <david@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

/**
* Matching question type conversion handler
*/
class moodle1_qtype_ddmatch_handler extends moodle1_qtype_handler {

/**
* @return array
*/
public function get_question_subpaths() {
return array(
'DDMATCHS/MATCH'
);
}

/**
* Appends the ddmatch 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
$matchids = array();
if (isset($data['ddmatchs']['match'])) {
foreach ($data['ddmatchs']['match'] as $match) {
$matchids[] = $match['id'];
}
}

// convert match options
$matchoptions = array();
$matchoptions['id'] = $this->converter->get_nextid();
$matchoptions['subquestions'] = implode(',', $matchids);
$matchoptions['shuffleanswers'] = $data['shuffleanswers'];
$this->write_xml('matchoptions', $matchoptions, array('/matchoptions/id'));

// convert ddmatches
$this->xmlwriter->begin_tag('matches');
if (isset($data['ddmatchs']['match'])) {
foreach ($data['ddmatchs']['match'] as $match) {
// 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);
$match['questiontextformat'] = FORMAT_HTML;
$match['answertext'] = text_to_html($match['answertext'], false, false, true);
$match['answertextformat'] = FORMAT_HTML;
} else {
$match['questiontextformat'] = $data['oldquestiontextformat'];
$match['answertextformat'] = $data['oldquestiontextformat'];
}

$this->write_xml('match', $match, array('/match/id'));
}
}
$this->xmlwriter->end_tag('matches');
}
}
80 changes: 80 additions & 0 deletions backup/moodle2/backup_qtype_ddmatch_plugin.class.php
@@ -0,0 +1,80 @@
<?php
/**
* @package moodlecore
* @subpackage backup-moodle2
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/


defined('MOODLE_INTERNAL') || die();


/**
* Provides the information to backup ddmatch questions
*
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class backup_qtype_ddmatch_plugin extends backup_qtype_plugin {

/**
* 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
$plugin = $this->get_plugin_element(null, '../../qtype', 'ddmatch');

// 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);

// Now create the qtype own structures
$matchoptions = new backup_nested_element('matchoptions', array('id'), array(
'subquestions', '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', 'answertextformat'));

// 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_ddmatch',
array('question' => backup::VAR_PARENTID));
$match->set_source_sql('
SELECT *
FROM {question_ddmatch_sub}
WHERE question = :question
ORDER BY id',
array('question' => backup::VAR_PARENTID));

// don't need to annotate ids nor files

return $plugin;
}

/**
* 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(
'correctfeedback' => 'question_ddmatch',
'partiallycorrectfeedback' => 'question_ddmatch',
'incorrectfeedback' => 'question_ddmatch',
'subquestion' => 'question_ddmatch_sub',
'subanswer' => 'question_ddmatch_sub');
}
}

0 comments on commit 4380fa0

Please sign in to comment.