[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Drag-and-drop onto image question definition class. 19 * 20 * @package qtype_ddimageortext 21 * @copyright 2009 The Open University 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 require_once($CFG->dirroot . '/question/type/questionbase.php'); 29 require_once($CFG->dirroot . '/question/type/gapselect/questionbase.php'); 30 31 32 /** 33 * Represents a drag-and-drop onto image question. 34 * 35 * @copyright 2009 The Open University 36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 37 */ 38 class qtype_ddtoimage_question_base extends qtype_gapselect_question_base { 39 public function clear_wrong_from_response(array $response) { 40 foreach ($this->places as $place => $notused) { 41 if (array_key_exists($this->field($place), $response) && 42 $response[$this->field($place)] != $this->get_right_choice_for($place)) { 43 $response[$this->field($place)] = ''; 44 } 45 } 46 return $response; 47 } 48 49 public function get_right_choice_for($placeno) { 50 $place = $this->places[$placeno]; 51 foreach ($this->choiceorder[$place->group] as $choicekey => $choiceid) { 52 if ($this->rightchoices[$placeno] == $choiceid) { 53 return $choicekey; 54 } 55 } 56 } 57 public function summarise_response(array $response) { 58 $allblank = true; 59 foreach ($this->places as $placeno => $place) { 60 $summariseplace = $place->summarise(); 61 if (array_key_exists($this->field($placeno), $response) && 62 $response[$this->field($placeno)]) { 63 $selected = $this->get_selected_choice($place->group, 64 $response[$this->field($placeno)]); 65 $summarisechoice = $selected->summarise(); 66 $allblank = false; 67 } else { 68 $summarisechoice = ''; 69 } 70 $choices[] = "$summariseplace -> {{$summarisechoice}}"; 71 } 72 if ($allblank) { 73 return null; 74 } 75 return implode(' ', $choices); 76 } 77 78 public function check_file_access($qa, $options, $component, $filearea, $args, $forcedownload) { 79 if ($filearea == 'bgimage' || $filearea == 'dragimage') { 80 $validfilearea = true; 81 } else { 82 $validfilearea = false; 83 } 84 if ($component == 'qtype_ddimageortext' && $validfilearea) { 85 $question = $qa->get_question(); 86 $itemid = reset($args); 87 if ($filearea == 'bgimage') { 88 return $itemid == $question->id; 89 } else if ($filearea == 'dragimage') { 90 foreach ($question->choices as $group) { 91 foreach ($group as $drag) { 92 if ($drag->id == $itemid) { 93 return true; 94 } 95 } 96 } 97 return false; 98 } 99 } else { 100 return parent::check_file_access($qa, $options, $component, 101 $filearea, $args, $forcedownload); 102 } 103 } 104 public function get_validation_error(array $response) { 105 if ($this->is_complete_response($response)) { 106 return ''; 107 } 108 return get_string('pleasedraganimagetoeachdropregion', 'qtype_ddimageortext'); 109 } 110 111 public function classify_response(array $response) { 112 $parts = array(); 113 foreach ($this->places as $placeno => $place) { 114 $group = $place->group; 115 if (!array_key_exists($this->field($placeno), $response) || 116 !$response[$this->field($placeno)]) { 117 $parts[$placeno] = question_classified_response::no_response(); 118 continue; 119 } 120 121 $fieldname = $this->field($placeno); 122 $choicekey = $this->choiceorder[$group][$response[$fieldname]]; 123 $choice = $this->choices[$group][$choicekey]; 124 125 $correct = $this->get_right_choice_for($placeno) == $response[$fieldname]; 126 if ($correct) { 127 $grade = 1; 128 } else { 129 $grade = 0; 130 } 131 $parts[$placeno] = new question_classified_response($choice->no, $choice->summarise(), $grade); 132 } 133 return $parts; 134 } 135 136 public function get_random_guess_score() { 137 $accum = 0; 138 139 foreach ($this->places as $place) { 140 foreach ($this->choices[$place->group] as $choice) { 141 if ($choice->infinite) { 142 return null; 143 } 144 } 145 $accum += 1 / count($this->choices[$place->group]); 146 } 147 148 return $accum / count($this->places); 149 } 150 151 152 public function get_question_summary() { 153 $summary = ''; 154 if (!html_is_blank($this->questiontext)) { 155 $question = $this->html_to_text($this->questiontext, $this->questiontextformat); 156 $summary .= $question . '; '; 157 } 158 $places = array(); 159 foreach ($this->places as $place) { 160 $cs = array(); 161 foreach ($this->choices[$place->group] as $choice) { 162 $cs[] = $choice->summarise(); 163 } 164 $places[] = '[[' . $place->summarise() . ']] -> {' . implode(' / ', $cs) . '}'; 165 } 166 $summary .= implode('; ', $places); 167 return $summary; 168 } 169 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |