Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'MDL-37600' of git://github.com/timhunt/moodle
  • Loading branch information
danpoltawski committed Jan 29, 2013
2 parents 37c6830 + 9887aae commit cbb26eb
Show file tree
Hide file tree
Showing 16 changed files with 413 additions and 310 deletions.
22 changes: 10 additions & 12 deletions question/type/match/backup/moodle1/lib.php
@@ -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
Expand All @@ -16,16 +15,15 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* @package qtype
* @subpackage match
* @package qtype_match
* @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
* Matching question type conversion handler.
*/
class moodle1_qtype_match_handler extends moodle1_qtype_handler {

Expand All @@ -35,27 +33,27 @@ 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) {
$matchids[] = $match['id'];
}
}

// convert match options
// Convert match options.
if (isset($data['matchoptions'])) {
$matchoptions = $data['matchoptions'][0];
} else {
Expand All @@ -65,11 +63,11 @@ public function process_question(array $data, array $raw) {
$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);
Expand Down
Expand Up @@ -26,66 +26,66 @@


/**
* 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
*/
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');
}
}

0 comments on commit cbb26eb

Please sign in to comment.