MDL-20636 Conversion of the description question type.

This commit is contained in:
Tim Hunt
2011-01-13 18:35:54 +00:00
parent 481dc639b3
commit 32d8935c8d
7 changed files with 102 additions and 143 deletions
+1 -1
View File
@@ -813,7 +813,7 @@ ORDER BY
* @param array $questionids of question ids.
* @return boolean whether any of these questions are being used by the question engine.
*/
public static function questions_in_use(array $questionids) {
public function questions_in_use(array $questionids) {
list($test, $params) = $this->db->get_in_or_equal($questionids);
return $this->db->record_exists_select('question_attempts',
'questionid ' . $test, $params);
+21 -21
View File
@@ -208,17 +208,6 @@ DONE question/type/rendererbase.php | 265 ++ -- TODO diff q
DONE question/type/simpletest/testquestionbase.php | 117 +
DONE question/type/simpletest/testquestiontype.php | 91 +-
DONE question/type/truefalse/db/upgrade.php | 2 -
DONE question/type/truefalse/display.html | 30 -
DONE question/type/truefalse/edit_truefalse_form.php | 53 +-
DONE question/type/truefalse/lang/en_utf8/qtype_truefalse.php | 14 +
DONE question/type/truefalse/question.php | 97 +
DONE question/type/truefalse/questiontype.php | 212 +-
DONE question/type/truefalse/renderer.php | 142 +
DONE question/type/truefalse/simpletest/testquestion.php | 99 +
DONE question/type/truefalse/simpletest/testquestiontype.php | 73 +
DONE question/type/truefalse/version.php | 4 +-
DONE question/behaviour/behaviourbase.php | 627 +++++
DONE question/behaviour/rendererbase.php | 200 ++
@@ -431,16 +420,27 @@ DONE question/behaviour/opaque/lang/en_utf8/qbehaviour_opaque.php | 4 +
question/type/randomsamatch/questiontype.php | 10 +-
question/type/randomsamatch/version.php | 2 -
question/type/shortanswer/db/upgrade.php | 2 -
question/type/shortanswer/display.html | 24 -
question/type/shortanswer/edit_shortanswer_form.php | 53 +-
question/type/shortanswer/lang/en_utf8/qtype_shortanswer.php | 17 +
question/type/shortanswer/question.php | 100 +
question/type/shortanswer/questiontype.php | 298 +--
question/type/shortanswer/renderer.php | 119 +
question/type/shortanswer/simpletest/testquestion.php | 146 +
question/type/shortanswer/simpletest/testquestiontype.php | 283 +--
question/type/shortanswer/version.php | 4 +-
DONE question/type/shortanswer/db/upgrade.php | 2 -
DONE question/type/shortanswer/display.html | 24 -
DONE question/type/shortanswer/edit_shortanswer_form.php | 53 +-
DONE question/type/shortanswer/lang/en_utf8/qtype_shortanswer.php | 17 +
DONE question/type/shortanswer/question.php | 100 +
DONE question/type/shortanswer/questiontype.php | 298 +--
DONE question/type/shortanswer/renderer.php | 119 +
DONE question/type/shortanswer/simpletest/testquestion.php | 146 +
DONE question/type/shortanswer/simpletest/testquestiontype.php | 283 +--
DONE question/type/shortanswer/version.php | 4 +-
DONE question/type/truefalse/db/upgrade.php | 2 -
DONE question/type/truefalse/display.html | 30 -
DONE question/type/truefalse/edit_truefalse_form.php | 53 +-
DONE question/type/truefalse/lang/en_utf8/qtype_truefalse.php | 14 +
DONE question/type/truefalse/question.php | 97 +
DONE question/type/truefalse/questiontype.php | 212 +-
DONE question/type/truefalse/renderer.php | 142 +
DONE question/type/truefalse/simpletest/testquestion.php | 99 +
DONE question/type/truefalse/simpletest/testquestiontype.php | 73 +
DONE question/type/truefalse/version.php | 4 +-
theme/standard/styles_color.css | 72 +-
theme/standard/styles_fonts.css | 20 +-
@@ -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
@@ -18,15 +17,15 @@
/**
* Defines the editing form for the description question type.
*
* @package qtype
* @subpackage description
* @copyright &copy; 2007 Jamie Pratt
* @author Jamie Pratt [email protected]
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package questionbank
* @subpackage questiontypes
*/
/**
* description editing form definition.
* Description editing form definition.
*/
class question_edit_description_form extends question_edit_form {
/**
@@ -34,16 +33,14 @@ class question_edit_description_form extends question_edit_form {
*
* @param MoodleQuickForm $mform the form being built.
*/
function definition_inner(&$mform) {
//don't need these default elements :
$mform->removeElement('defaultgrade');
$mform->removeElement('penalty');
$mform->addElement('hidden', 'defaultgrade', 0);
$mform->setType('defaultgrade', PARAM_RAW);
protected function definition_inner($mform) {
// We don't need this default element.
$mform->removeElement('defaultmark');
$mform->addElement('hidden', 'defaultmark', 0);
$mform->setType('defaultmark', PARAM_RAW);
}
function qtype() {
public function qtype() {
return 'description';
}
}
@@ -1,92 +0,0 @@
<?php
///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.org //
// //
// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
// //
// This program 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 2 of the License, or //
// (at your option) any later version. //
// //
// This program 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: //
// //
// http://www.gnu.org/copyleft/gpl.html //
// //
///////////////////////////////////////////////////////////////////////////
/**
* The description question type is not acutally a question, it is just a way
* to add some static content in the middle of a quiz, or other place that
* questions are used.
*
* @package questionbank
* @subpackage questiontypes
*/
class description_qtype extends default_questiontype {
function name() {
return 'description';
}
function is_real_question_type() {
return false;
}
function is_usable_by_random() {
return false;
}
function save_question($question, $form) {
// Make very sure that descriptions can'e be created with a grade of
// anything other than 0.
$form->defaultgrade = 0;
return parent::save_question($question, $form);
}
function get_question_options(&$question) {
return true;
}
function save_question_options($question) {
return true;
}
function print_question(&$question, &$state, $number, $cmoptions, $options) {
global $CFG;
$isfinished = question_state_is_graded($state->last_graded) || $state->event == QUESTION_EVENTCLOSE;
// For editing teachers print a link to an editing popup window
$editlink = $this->get_question_edit_link($question, $cmoptions, $options);
$questiontext = $this->format_text($question->questiontext, $question->questiontextformat, $cmoptions);
$generalfeedback = '';
if ($isfinished && $options->generalfeedback) {
$generalfeedback = $this->format_text($question->generalfeedback,
$question->generalfeedbackformat, $cmoptions);
}
include "$CFG->dirroot/question/type/description/question.html";
}
function actual_number_of_questions($question) {
return 0;
}
function grade_responses(&$question, &$state, $cmoptions) {
$state->raw_grade = 0;
$state->penalty = 0;
return true;
}
}
// Register this question type with questionlib.php.
question_register_questiontype(new description_qtype());
+5 -14
View File
@@ -19,7 +19,8 @@
/**
* Question type class for the description 'question' type.
*
* @package qtype_description
* @package qtype
* @subpackage description
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -33,7 +34,7 @@ require_once($CFG->libdir . '/questionlib.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_description extends question_type {
function is_real_question_type() {
public function is_real_question_type() {
return false;
}
@@ -45,21 +46,11 @@ class qtype_description extends question_type {
return false;
}
public function save_question($question, $form, $course) {
public function save_question($question, $form) {
// Make very sure that descriptions can'e be created with a grade of
// anything other than 0.
$form->defaultmark = 0;
return parent::save_question($question, $form, $course);
}
public function get_question_options(&$question) {
// No options to be restored for this question type
return true;
}
public function save_question_options($question) {
/// No options to be saved for this question type:
return true;
return parent::save_question($question, $form);
}
public function actual_number_of_questions($question) {
@@ -0,0 +1,65 @@
<?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 description question type class.
*
* @package qtype_description
* @copyright 2010 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once($CFG->dirroot . '/question/type/description/questiontype.php');
/**
* Unit tests for the description question type class.
*
* @copyright 2010 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_description_test extends UnitTestCase {
var $qtype;
public function setUp() {
$this->qtype = new qtype_description();
}
public function tearDown() {
$this->qtype = null;
}
public function test_name() {
$this->assertEqual($this->qtype->name(), 'description');
}
public function test_actual_number_of_questions() {
$this->assertEqual(0, $this->qtype->actual_number_of_questions(null));
}
public function test_can_analyse_responses() {
$this->assertFalse($this->qtype->can_analyse_responses());
}
public function test_get_random_guess_score() {
$this->assertNull($this->qtype->get_random_guess_score(null));
}
public function test_get_possible_responses() {
$this->assertEqual(array(), $this->qtype->get_possible_responses(null));
}
}
-2
View File
@@ -458,8 +458,6 @@ class question_type {
$extra_answer_fields = $this->extra_answer_fields();
// TODO save the answers, with any extra data.
return null;
}
public function save_hints($formdata, $withparts = false) {