|
Moodle
2.2.1
http://www.collinsharper.com
|
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/multichoice/question.php'); 00030 require_once($CFG->dirroot . '/question/type/calculated/question.php'); 00031 00032 00039 class qtype_calculatedmulti_single_question extends qtype_multichoice_single_question 00040 implements qtype_calculated_question_with_expressions { 00041 00043 public $datasetloader; 00044 00046 public $vs; 00047 00052 public $synchronised; 00053 00054 public function start_attempt(question_attempt_step $step, $variant) { 00055 qtype_calculated_question_helper::start_attempt($this, $step, $variant); 00056 parent::start_attempt($step, $variant); 00057 } 00058 00059 public function apply_attempt_state(question_attempt_step $step) { 00060 qtype_calculated_question_helper::apply_attempt_state($this, $step); 00061 parent::apply_attempt_state($step); 00062 } 00063 00064 public function calculate_all_expressions() { 00065 qtype_calculatedmulti_calculate_helper::calculate_all_expressions($this); 00066 } 00067 00068 00069 public function get_num_variants() { 00070 return $this->datasetloader->get_number_of_items(); 00071 } 00072 00073 public function get_variants_selection_seed() { 00074 if (!empty($this->synchronised) && 00075 $this->datasetloader->datasets_are_synchronised($this->category)) { 00076 return 'category' . $this->category; 00077 } else { 00078 return parent::get_variants_selection_seed(); 00079 } 00080 } 00081 } 00082 00083 00090 class qtype_calculatedmulti_multi_question extends qtype_multichoice_multi_question 00091 implements qtype_calculated_question_with_expressions { 00092 00094 public $datasetloader; 00095 00097 public $vs; 00098 00103 public $synchronised; 00104 00105 public function start_attempt(question_attempt_step $step, $variant) { 00106 qtype_calculated_question_helper::start_attempt($this, $step); 00107 parent::start_attempt($step, $variant); 00108 } 00109 00110 public function apply_attempt_state(question_attempt_step $step) { 00111 qtype_calculated_question_helper::apply_attempt_state($this, $step); 00112 parent::apply_attempt_state($step); 00113 } 00114 00115 public function calculate_all_expressions() { 00116 qtype_calculatedmulti_calculate_helper::calculate_all_expressions($this); 00117 } 00118 } 00119 00120 00128 abstract class qtype_calculatedmulti_calculate_helper { 00134 public static function calculate_all_expressions( 00135 qtype_calculated_question_with_expressions $question) { 00136 $question->questiontext = $question->vs->replace_expressions_in_text( 00137 $question->questiontext); 00138 $question->generalfeedback = $question->vs->replace_expressions_in_text( 00139 $question->generalfeedback); 00140 00141 foreach ($question->answers as $ans) { 00142 if ($ans->answer && $ans->answer !== '*') { 00143 $ans->answer = $question->vs->replace_expressions_in_text($ans->answer, 00144 $ans->correctanswerlength, $ans->correctanswerformat); 00145 } 00146 $ans->feedback = $question->vs->replace_expressions_in_text($ans->feedback, 00147 $ans->correctanswerlength, $ans->correctanswerformat); 00148 } 00149 } 00150 }