Commit 678826ef authored by cescobedo's avatar cescobedo
Browse files

MDL-72517 qformat: Remove ExamView question format

parent 70073fdc
......@@ -1720,7 +1720,7 @@ class core_plugin_manager {
// branch, listed should be no plugins that were removed at 1.9.x - 2.1.x versions as
// Moodle 2.3 supports upgrades from 2.2.x only.
$plugins = array(
'qformat' => array('blackboard', 'learnwise'),
'qformat' => array('blackboard', 'learnwise', 'examview'),
'auth' => array('radius', 'fc', 'nntp', 'pam', 'pop3', 'imap'),
'block' => array('course_overview', 'messages', 'community', 'participants'),
'cachestore' => array('memcache'),
......@@ -1966,7 +1966,7 @@ class core_plugin_manager {
),
'qformat' => array(
'aiken', 'blackboard_six', 'examview', 'gift',
'aiken', 'blackboard_six', 'gift',
'missingword', 'multianswer',
'xhtml', 'xml'
),
......
......@@ -2882,5 +2882,15 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2021100300.02);
}
if ($oldversion < 2021100600.01) {
// Remove qformat_examview (unless it has manually been added back).
if (!file_exists($CFG->dirroot . '/question/format/examview/format.php')) {
unset_all_config_for_plugin('qformat_examview');
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2021100600.01);
}
return true;
}
<?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/>.
/**
* Privacy Subsystem implementation for qformat_examview.
*
* @package qformat_examview
* @copyright 2018 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace qformat_examview\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for qformat_examview implementing null_provider.
*
* @copyright 2018 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason() : string {
return 'privacy:metadata';
}
}
<?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/>.
/**
* Examview question importer.
*
* @package qformat_examview
* @copyright 2005 Howard Miller
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/xmlize.php');
/**
* Examview question importer.
*
* @copyright 2005 Howard Miller
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qformat_examview extends qformat_based_on_xml {
public $qtypes = array(
'tf' => 'truefalse',
'mc' => 'multichoice',
'yn' => 'truefalse',
'co' => 'shortanswer',
'ma' => 'match',
'mtf' => 99,
'nr' => 'numerical',
'pr' => 99,
'es' => 'essay',
'ca' => 99,
'ot' => 99,
'sa' => 'shortanswer',
);
public $matchingquestions = array();
public function provide_import() {
return true;
}
public function mime_type() {
return 'application/xml';
}
/**
* unxmlise reconstructs part of the xml data structure in order
* to identify the actual data therein
* @param array $xml section of the xml data structure
* @return string data with evrything else removed
*/
protected function unxmlise( $xml ) {
// If it's not an array then it's probably just data.
if (!is_array($xml)) {
$text = s($xml);
} else {
// Otherwise parse the array.
$text = '';
foreach ($xml as $tag => $data) {
// If tag is '@' then it's attributes and we don't care.
if ($tag!=='@') {
$text = $text . $this->unxmlise( $data );
}
}
}
// Currently we throw the tags we found.
$text = strip_tags($text);
return $text;
}
public function parse_matching_groups($matchinggroups) {
if (empty($matchinggroups)) {
return;
}
foreach ($matchinggroups as $matchgroup) {
$newgroup = new stdClass();
$groupname = trim($matchgroup['@']['name']);
$questiontext = $this->unxmlise($matchgroup['#']['text'][0]['#']);
$newgroup->questiontext = trim($questiontext);
$newgroup->subchoices = array();
$newgroup->subquestions = array();
$newgroup->subanswers = array();
$choices = $matchgroup['#']['choices']['0']['#'];
foreach ($choices as $key => $value) {
if (strpos(trim($key), 'choice-') !== false) {
$key = strtoupper(trim(str_replace('choice-', '', $key)));
$newgroup->subchoices[$key] = trim($value['0']['#']);
}
}
$this->matching_questions[$groupname] = $newgroup;
}
}
protected function parse_ma($qrec, $groupname) {
$matchgroup = $this->matching_questions[$groupname];
$phrase = trim($this->unxmlise($qrec['text']['0']['#']));
$answer = trim($this->unxmlise($qrec['answer']['0']['#']));
$answer = strip_tags( $answer );
$matchgroup->mappings[$phrase] = $matchgroup->subchoices[$answer];
$this->matching_questions[$groupname] = $matchgroup;
return null;
}
protected function process_matches(&$questions) {
if (empty($this->matching_questions)) {
return;
}
foreach ($this->matching_questions as $matchgroup) {
$question = $this->defaultquestion();
$htmltext = s($matchgroup->questiontext);
$question->questiontext = $htmltext;
$question->questiontextformat = FORMAT_HTML;
$question->questiontextfiles = array();
$question->name = $this->create_default_question_name($question->questiontext, get_string('questionname', 'question'));
$question->qtype = 'match';
$question = $this->add_blank_combined_feedback($question);
$question->subquestions = array();
$question->subanswers = array();
foreach ($matchgroup->subchoices as $subchoice) {
$fiber = array_keys ($matchgroup->mappings, $subchoice);
$subquestion = '';
foreach ($fiber as $subquestion) {
$question->subquestions[] = $this->text_field($subquestion);
$question->subanswers[] = $subchoice;
}
if ($subquestion == '') { // Then in this case, $subchoice is a distractor.
$question->subquestions[] = $this->text_field('');
$question->subanswers[] = $subchoice;
}
}
$questions[] = $question;
}
}
protected function cleanunicode($text) {
return str_replace('&#x2019;', "'", $text);
}
public function readquestions($lines) {
// Parses an array of lines into an array of questions,
// where each item is a question object as defined by
// readquestion().
$questions = array();
$currentquestion = array();
$text = implode(' ', $lines);
$text = $this->cleanunicode($text);
$xml = xmlize($text, 0);
if (!empty($xml['examview']['#']['matching-group'])) {
$this->parse_matching_groups($xml['examview']['#']['matching-group']);
}
$questionnode = $xml['examview']['#']['question'];
foreach ($questionnode as $currentquestion) {
if ($question = $this->readquestion($currentquestion)) {
$questions[] = $question;
}
}
$this->process_matches($questions);
return $questions;
}
public function readquestion($qrec) {
global $OUTPUT;
$type = trim($qrec['@']['type']);
$question = $this->defaultquestion();
if (array_key_exists($type, $this->qtypes)) {
$question->qtype = $this->qtypes[$type];
} else {
$question->qtype = null;
}
$question->single = 1;
// Only one answer is allowed.
$htmltext = $this->unxmlise($qrec['#']['text'][0]['#']);
$question->questiontext = $this->cleaninput($htmltext);
$question->questiontextformat = FORMAT_HTML;
$question->questiontextfiles = array();
$question->name = $this->create_default_question_name($question->questiontext, get_string('questionname', 'question'));
switch ($question->qtype) {
case 'multichoice':
$question = $this->parse_mc($qrec['#'], $question);
break;
case 'match':
$groupname = trim($qrec['@']['group']);
$question = $this->parse_ma($qrec['#'], $groupname);
break;
case 'truefalse':
$question = $this->parse_tf_yn($qrec['#'], $question);
break;
case 'shortanswer':
$question = $this->parse_co($qrec['#'], $question);
break;
case 'essay':
$question = $this->parse_es($qrec['#'], $question);
break;
case 'numerical':
$question = $this->parse_nr($qrec['#'], $question);
break;
break;
default:
echo $OUTPUT->notification(get_string('unknownorunhandledtype', 'question', $type));
$question = null;
}
return $question;
}
protected function parse_tf_yn($qrec, $question) {
$choices = array('T' => 1, 'Y' => 1, 'F' => 0, 'N' => 0 );
$answer = trim($qrec['answer'][0]['#']);
$question->answer = $choices[$answer];
$question->correctanswer = $question->answer;
if ($question->answer == 1) {
$question->feedbacktrue = $this->text_field(get_string('correct', 'question'));
$question->feedbackfalse = $this->text_field(get_string('incorrect', 'question'));
} else {
$question->feedbacktrue = $this->text_field(get_string('incorrect', 'question'));
$question->feedbackfalse = $this->text_field(get_string('correct', 'question'));
}
return $question;
}
protected function parse_mc($qrec, $question) {
$question = $this->add_blank_combined_feedback($question);
$answer = 'choice-'.strtolower(trim($qrec['answer'][0]['#']));
$choices = $qrec['choices'][0]['#'];
foreach ($choices as $key => $value) {
if (strpos(trim($key), 'choice-') !== false) {
$question->answer[] = $this->text_field(s($this->unxmlise($value[0]['#'])));
if (strcmp($key, $answer) == 0) {
$question->fraction[] = 1;
$question->feedback[] = $this->text_field(get_string('correct', 'question'));
} else {
$question->fraction[] = 0;
$question->feedback[] = $this->text_field(get_string('incorrect', 'question'));
}
}
}
return $question;
}
protected function parse_co($qrec, $question) {
$question->usecase = 0;
$answer = trim($this->unxmlise($qrec['answer'][0]['#']));
$answer = strip_tags( $answer );
$answers = explode("\n", $answer);
foreach ($answers as $key => $value) {
$value = trim($value);
if (strlen($value) > 0) {
$question->answer[] = $value;
$question->fraction[] = 1;
$question->feedback[] = $this->text_field(get_string('correct', 'question'));
}
}
$question->answer[] = '*';
$question->fraction[] = 0;
$question->feedback[] = $this->text_field(get_string('incorrect', 'question'));
return $question;
}
protected function parse_es($qrec, $question) {
$feedback = trim($this->unxmlise($qrec['answer'][0]['#']));
$question->graderinfo = $this->text_field($feedback);
$question->responsetemplate = $this->text_field('');
$question->responserequired = 1;
$question->feedback = $feedback;
$question->responseformat = 'editor';
$question->responsefieldlines = 15;
$question->attachments = 0;
$question->attachmentsrequired = 0;
$question->fraction = 0;
return $question;
}
protected function parse_nr($qrec, $question) {
$answer = trim($this->unxmlise($qrec['answer'][0]['#']));
$answer = strip_tags( $answer );
$answers = explode("\n", $answer);
foreach ($answers as $key => $value) {
$value = trim($value);
if (is_numeric($value)) {
$errormargin = 0;
$question->answer[] = $value;
$question->fraction[] = 1;
$question->feedback[] = $this->text_field(get_string('correct', 'question'));
$question->tolerance[] = $errormargin;
}
}
return $question;
}
}
// End class.
<?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/>.
/**
* Strings for component 'qformat_examview', language 'en', branch 'MOODLE_20_STABLE'
*
* @package qformat_examview
* @copyright 2010 Helen Foster
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['pluginname'] = 'Examview';
$string['pluginname_help'] = 'Examview format enables the import of questions from Examview 4 XML files. For newer versions of Examview, Blackboard format may be used.';
$string['privacy:metadata'] = 'The Examview question format plugin does not store any personal data.';
<?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/>.
/**
* Unit tests for the Moodle Examview format.
*
* @package qformat_examview
* @copyright 2012 jean-Michel Vedrine
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->libdir . '/questionlib.php');
require_once($CFG->dirroot . '/question/format.php');
require_once($CFG->dirroot . '/question/format/examview/format.php');
require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
/**
* Unit tests for the examview question import format.
*
* @copyright 2012 Jean-Michel Vedrine
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qformat_examview_test extends question_testcase {
public function make_test_xml() {
$xml = $xml = file_get_contents(__DIR__ . '/fixtures/examview_sample.xml');
return array(0=>$xml);
}
public function test_import_truefalse() {
$xml = $this->make_test_xml();
$questions = array();
$importer = new qformat_examview();
$questions = $importer->readquestions($xml);
$q = $questions[0];
$expectedq = new stdClass();
$expectedq->qtype = 'truefalse';
$expectedq->name = '42 is the Absolute Answer to everything.';
$expectedq->questiontext = "42 is the Absolute Answer to everything.";
$expectedq->questiontextformat = FORMAT_HTML;
$expectedq->generalfeedback = '';
$expectedq->generalfeedbackformat = FORMAT_MOODLE;
$expectedq->defaultmark = 1;
$expectedq->length = 1;
$expectedq->correctanswer = 0;
$expectedq->feedbacktrue = array(
'text' => get_string('incorrect', 'question'),
'format' => FORMAT_HTML,
'files' => array(),
);
$expectedq->feedbackfalse = array(
'text' => get_string('correct', 'question'),
'format' => FORMAT_HTML,
'files' => array(),
);
$this->assert(new question_check_specified_fields_expectation($expectedq), $q);
}
public function test_import_multichoice_single() {
$xml = $this->make_test_xml();
$questions = array();
$importer = new qformat_examview();
$questions = $importer->readquestions($xml);
$q = $questions[1];
$expectedq = new stdClass();
$expectedq->qtype = 'multichoice';
$expectedq->single = 1;
$expectedq->name = "What's between orange and green in the spectrum?";
$expectedq->questiontext = "What's between orange and green in the spectrum?";
$expectedq->questiontextformat = FORMAT_HTML;
$expectedq->correctfeedback = array('text' => '',
'format' => FORMAT_HTML, 'files' => array());
$expectedq->partiallycorrectfeedback = array('text' => '',
'format' => FORMAT_HTML, 'files' => array());
$expectedq->incorrectfeedback = array('text' => '',
'format' => FORMAT_HTML, 'files' => array());
$expectedq->generalfeedback = '';
$expectedq->generalfeedbackformat = FORMAT_MOODLE;
$expectedq->defaultmark = 1;
$expectedq->length = 1;
$expectedq->penalty = 0.3333333;
$expectedq->shuffleanswers = get_config('quiz', 'shuffleanswers');
$expectedq->answer = array(
0 => array(
'text' => 'red',
'format' => FORMAT_HTML,
'files' => array(),
),
1 => array(
'text' => 'yellow',
'format' => FORMAT_HTML,
'files' => array(),
),
2 => array(
'text' => 'blue',
'format' => FORMAT_HTML,
'files' => array(),
)
);
$expectedq->fraction = array(0, 1, 0);
$expectedq->feedback = array(
0 => array(
'text' => get_string('incorrect', 'question'),
'format' => FORMAT_HTML,
'files' => array(),
),
1 => array(
'text' => get_string('correct', 'question'),
'format' => FORMAT_HTML,
'files' => array(),
),
2 => array(
'text' => get_string('incorrect', 'question'),
'format' => FORMAT_HTML,
'files' => array(),
)
);
$this->assert(new question_check_specified_fields_expectation($expectedq), $q);
}
public function test_import_numerical() {
$xml = $this->make_test_xml();
$questions = array();
$importer = new qformat_examview();
$questions = $importer->readquestions($xml);
$q = $questions[2];
$expectedq = new stdClass();
$expectedq->qtype = 'numerical';
$expectedq->name = 'This is a numeric response question. How much is 12 * 2?';
$expectedq->questiontext = 'This is a numeric response question. How much is 12 * 2?';
$expectedq->questiontextformat = FORMAT_HTML;
$expectedq->generalfeedback = '';
$expectedq->generalfeedbackformat = FORMAT_MOODLE;
$expectedq->defaultmark = 1;
$expectedq->length = 1;
$expectedq->penalty = 0.3333333;
$expectedq->shuffleanswers = get_config('quiz', 'shuffleanswers');