Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/question/type/calculated/simpletest/helper.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00016 
00027 defined('MOODLE_INTERNAL') || die();
00028 
00029 require_once($CFG->dirroot . '/question/type/calculated/question.php');
00030 
00031 
00038 class qtype_calculated_test_helper extends question_test_helper {
00039     public function get_test_questions() {
00040         return array('sum');
00041     }
00042 
00047     public function make_calculated_question_sum() {
00048         question_bank::load_question_definition_classes('calculated');
00049         $q = new qtype_calculated_question();
00050         test_question_maker::initialise_a_question($q);
00051         $q->name = 'Simple sum';
00052         $q->questiontext = 'What is {a} + {b}?';
00053         $q->generalfeedback = 'Generalfeedback: {={a} + {b}} is the right answer.';
00054 
00055         $q->answers = array(
00056             13 => new qtype_numerical_answer(13, '{a} + {b}', 1.0, 'Very good.', FORMAT_HTML, 0),
00057             14 => new qtype_numerical_answer(14, '{a} - {b}', 0.0, 'Add. not subtract!.',
00058                     FORMAT_HTML, 0),
00059             17 => new qtype_numerical_answer(17, '*', 0.0, 'Completely wrong.', FORMAT_HTML, 0),
00060         );
00061         foreach ($q->answers as $answer) {
00062             $answer->correctanswerlength = 2;
00063             $answer->correctanswerformat = 1;
00064         }
00065 
00066         $q->qtype = question_bank::get_qtype('calculated');
00067         $q->unitdisplay = qtype_numerical::UNITNONE;
00068         $q->unitgradingtype = 0;
00069         $q->unitpenalty = 0;
00070         $q->ap = new qtype_numerical_answer_processor(array());
00071         $q->synchronised = false;
00072 
00073         $q->datasetloader = new qtype_calculated_test_dataset_loader(0, array(
00074             array('a' => 1, 'b' => 5),
00075             array('a' => 3, 'b' => 4),
00076         ));
00077 
00078         return $q;
00079     }
00080 
00085     public function get_calculated_question_data_sum() {
00086         question_bank::load_question_definition_classes('calculated');
00087         $qdata = new stdClass();
00088         test_question_maker::initialise_question_data($qdata);
00089 
00090         $qdata->qtype = 'calculated';
00091         $qdata->name = 'Simple sum';
00092         $qdata->questiontext = 'What is {a} + {b}?';
00093         $qdata->generalfeedback = 'Generalfeedback: {={a} + {b}} is the right answer.';
00094 
00095         $qdata->options = new stdClass();
00096         $qdata->options->unitgradingtype = 0;
00097         $qdata->options->unitpenalty = 0.0;
00098         $qdata->options->showunits = qtype_numerical::UNITNONE;
00099         $qdata->options->unitsleft = 0;
00100         $qdata->options->synchronize = 0;
00101 
00102         $qdata->options->answers = array(
00103             13 => new qtype_numerical_answer(13, '{a} + {b}', 1.0, 'Very good.', FORMAT_HTML, 0.001),
00104             14 => new qtype_numerical_answer(14, '{a} - {b}', 0.0, 'Add. not subtract!.',
00105                     FORMAT_HTML, 0.001),
00106             17 => new qtype_numerical_answer(17, '*', 0.0, 'Completely wrong.', FORMAT_HTML, 0),
00107         );
00108         foreach ($qdata->options->answers as $answer) {
00109             $answer->correctanswerlength = 2;
00110             $answer->correctanswerformat = 1;
00111         }
00112 
00113         $qdata->options->units = array();
00114 
00115         return $qdata;
00116     }
00117 }
00118 
00119 
00127 class qtype_calculated_test_dataset_loader extends qtype_calculated_dataset_loader{
00128     protected $valuesets;
00129     protected $aresynchronised = array();
00130 
00131     public function __construct($questionid, array $valuesets) {
00132         parent::__construct($questionid);
00133         $this->valuesets = $valuesets;
00134     }
00135 
00136     public function get_number_of_items() {
00137         return count($this->valuesets);
00138     }
00139 
00140     public function load_values($itemnumber) {
00141         return $this->valuesets[$itemnumber - 1];
00142     }
00143 
00144     public function datasets_are_synchronised($category) {
00145         return !empty($this->aresynchronised[$category]);
00146     }
00147 
00153     public function set_are_synchronised($category, $aresychronised) {
00154         $this->aresynchronised[$category] = $aresychronised;
00155     }
00156 }
 All Data Structures Namespaces Files Functions Variables Enumerations