Permalink
Browse files

MDL-37600 qtype match: fix codechecker issues.

  • Loading branch information...
timhunt committed Jan 21, 2013
1 parent 87d7673 commit 9887aaeb75f81476405ab178cc31dc000f95d292
@@ -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,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 {
@@ -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 {
@@ -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);
@@ -26,28 +26,28 @@
/**
- * 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(
'shuffleanswers', 'correctfeedback', 'correctfeedbackformat',
'partiallycorrectfeedback', 'partiallycorrectfeedbackformat',
@@ -58,12 +58,12 @@ protected function define_question_plugin_structure() {
$match = new backup_nested_element('match', array('id'), array(
'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
+ // Set source to populate the data.
$matchoptions->set_source_table('qtype_match_options',
array('questionid' => backup::VAR_PARENTID));
$match->set_source_sql('
@@ -73,13 +73,13 @@ protected function define_question_plugin_structure() {
ORDER BY id',
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.
@@ -26,22 +26,22 @@
/**
- * 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
*/
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 @@ protected function define_question_plugin_structure() {
$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 @@ public function process_matchoptions($data) {
$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 qtype_match_options 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,7 +89,7 @@ public function process_matchoptions($data) {
$data->shownumcorrect = 0;
}
- // Adjust some columns
+ // Adjust some columns.
$data->questionid = $newquestionid;
$newitemid = $DB->insert_record('qtype_match_options', $data);
$this->set_mapping('qtype_match_options', $oldid, $newitemid);
@@ -105,7 +105,7 @@ public function process_match($data) {
$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;
@@ -114,21 +114,21 @@ public function process_match($data) {
// If the question has been created by restore, we need to create its
// qtype_match_subquestions too.
- // Adjust some columns
+ // Adjust some columns.
$data->questionid = $newquestionid;
- // Insert record
+ // Insert record.
$newitemid = $DB->insert_record('qtype_match_subquestions', $data);
- // Create mapping (there are files and states based on this)
+ // 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 qtype_match_subquestions, 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 questionid, questiontext and answertext)
+ // 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 = ?',
@@ -138,13 +138,16 @@ public function process_match($data) {
// Not able to find the answer, let's try cleaning the answertext
// of all the match subquestions in DB as slower fallback. MDL-36683 / MDL-30018.
if (!$sub) {
- $potentialsubs = $DB->get_records('qtype_match_subquestions', array('questionid' => $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) {
@@ -153,7 +156,7 @@ public function process_match($data) {
}
}
- // Found, let's create the mapping
+ // Found one. Let's create the mapping.
if ($sub) {
$this->set_mapping('qtype_match_subquestions', $oldid, $sub->id);
} else {
@@ -174,7 +177,7 @@ public function recode_response($questionid, $sequencenumber, array $response) {
/**
* 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, which
@@ -214,7 +217,7 @@ protected function recode_match_sub_order($order) {
}
/**
- * 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() {
@@ -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
*/
@@ -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 @@
*
* 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;
@@ -17,10 +17,9 @@
/**
* Defines the editing form for the match question type.
*
- * @package qtype
- * @subpackage match
- * @copyright 2007 Jamie Pratt me@jamiep.org
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @package qtype_match
+ * @copyright 2007 Jamie Pratt me@jamiep.org
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -30,8 +29,8 @@
/**
* Match question type editing form definition.
*
- * @copyright 2007 Jamie Pratt me@jamiep.org
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @copyright 2007 Jamie Pratt me@jamiep.org
+ * @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 @@ protected function data_preprocessing($question) {
$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++;
@@ -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';
Oops, something went wrong.

0 comments on commit 9887aae

Please sign in to comment.