[ 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 * 19 * Data structure to count responses for each of the sub parts of a question. 20 * 21 * @package core_question 22 * @copyright 2014 The Open University 23 * @author James Pratt me@jamiep.org 24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 25 */ 26 27 namespace core_question\statistics\responses; 28 29 /** 30 * Representing the analysis of each of the sub parts of each variant of the question. 31 * 32 * - There is a separate data structure for each question or sub question's analysis 33 * {@link \core_question\statistics\responses\analysis_for_question} 34 * or {@link \core_question\statistics\responses\analysis_for_question_all_tries}. 35 * - There are separate analysis for each variant in this top level instance. 36 * - Then there are class instances representing the analysis of each of the sub parts of each variant of the question. 37 * {@link \core_question\statistics\responses\analysis_for_subpart}. 38 * - Then within the sub part analysis there are response class analysis 39 * {@link \core_question\statistics\responses\analysis_for_class}. 40 * - Then within each class analysis there are analysis for each actual response 41 * {@link \core_question\statistics\responses\analysis_for_actual_response}. 42 * 43 * @package core_question 44 * @copyright 2014 The Open University 45 * @author James Pratt me@jamiep.org 46 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 47 */ 48 class analysis_for_subpart { 49 50 /** 51 * Takes an array of possible_responses as returned from {@link \question_type::get_possible_responses()}. 52 * 53 * @param \question_possible_response[] $responseclasses as returned from {@link \question_type::get_possible_responses()}. 54 */ 55 public function __construct(array $responseclasses = null) { 56 if (is_array($responseclasses)) { 57 foreach ($responseclasses as $responseclassid => $responseclass) { 58 $this->responseclasses[$responseclassid] = new analysis_for_class($responseclass, $responseclassid); 59 } 60 } 61 } 62 63 /** 64 * @var analysis_for_class[] 65 */ 66 protected $responseclasses; 67 68 /** 69 * Unique ids for response classes. 70 * 71 * @return string[] 72 */ 73 public function get_response_class_ids() { 74 return array_keys($this->responseclasses); 75 } 76 77 /** 78 * Get the instance of the class handling the analysis of $classid for this sub part. 79 * 80 * @param string $classid id for response class. 81 * @return analysis_for_class 82 */ 83 public function get_response_class($classid) { 84 return $this->responseclasses[$classid]; 85 } 86 87 /** 88 * Whether there is more than one response class for responses in this question sub part? 89 * 90 * @return bool Are there? 91 */ 92 public function has_multiple_response_classes() { 93 return count($this->get_response_class_ids()) > 1; 94 } 95 96 /** 97 * Count a part of a response. 98 * 99 * @param \question_classified_response $subpart 100 * @param int $try the try number or zero if not keeping track of try number 101 */ 102 public function count_response($subpart, $try = 0) { 103 $responseanalysisforclass = $this->get_response_class($subpart->responseclassid); 104 $responseanalysisforclass->count_response($subpart->response, $subpart->fraction, $try); 105 } 106 107 /** 108 * Cache analysis for sub part. 109 * 110 * @param \qubaid_condition $qubaids which question usages have been analysed. 111 * @param string $whichtries which tries have been analysed? 112 * @param int $questionid which question. 113 * @param int $variantno which variant. 114 * @param string $subpartid which sub part. 115 */ 116 public function cache($qubaids, $whichtries, $questionid, $variantno, $subpartid) { 117 foreach ($this->get_response_class_ids() as $responseclassid) { 118 $analysisforclass = $this->get_response_class($responseclassid); 119 $analysisforclass->cache($qubaids, $whichtries, $questionid, $variantno, $subpartid, $responseclassid); 120 } 121 } 122 123 /** 124 * Has actual responses different to the model response for this class? 125 * 126 * @return bool whether this analysis has a response class with more than one 127 * different actual response, or if the actual response is different from 128 * the model response. 129 */ 130 public function has_actual_responses() { 131 foreach ($this->get_response_class_ids() as $responseclassid) { 132 if ($this->get_response_class($responseclassid)->has_actual_responses()) { 133 return true; 134 } 135 } 136 return false; 137 } 138 139 /** 140 * What is the highest try number for this sub part? 141 * 142 * @return int max tries 143 */ 144 public function get_maximum_tries() { 145 $max = 1; 146 foreach ($this->get_response_class_ids() as $responseclassid) { 147 $max = max($max, $this->get_response_class($responseclassid)->get_maximum_tries()); 148 } 149 return $max; 150 } 151 }
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 |