1 |
efrain |
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 |
* This file contains a class to analyse all the responses for multiple tries at a particular question.
|
|
|
19 |
*
|
|
|
20 |
* @package core_question
|
|
|
21 |
* @copyright 2014 Open University
|
|
|
22 |
* @author Jamie Pratt <me@jamiep.org>
|
|
|
23 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
24 |
*/
|
|
|
25 |
|
|
|
26 |
namespace core_question\statistics\responses;
|
|
|
27 |
|
|
|
28 |
/**
|
|
|
29 |
* Analysis for possible responses for parts of a question with multiple submitted responses.
|
|
|
30 |
*
|
|
|
31 |
* If the analysis was for a single try it would be handled by {@link \core_question\statistics\responses\analysis_for_question}.
|
|
|
32 |
*
|
|
|
33 |
* - There is a separate data structure for each question or sub question's analysis
|
|
|
34 |
* {@link \core_question\statistics\responses\analysis_for_question}
|
|
|
35 |
* or {@link \core_question\statistics\responses\analysis_for_question_all_tries}.
|
|
|
36 |
* - There are separate analysis for each variant in this top level instance.
|
|
|
37 |
* - Then there are class instances representing the analysis of each of the sub parts of each variant of the question.
|
|
|
38 |
* {@link \core_question\statistics\responses\analysis_for_subpart}.
|
|
|
39 |
* - Then within the sub part analysis there are response class analysis
|
|
|
40 |
* {@link \core_question\statistics\responses\analysis_for_class}.
|
|
|
41 |
* - Then within each class analysis there are analysis for each actual response
|
|
|
42 |
* {@link \core_question\statistics\responses\analysis_for_actual_response}.
|
|
|
43 |
*
|
|
|
44 |
* @package core_question
|
|
|
45 |
* @copyright 2014 The Open University
|
|
|
46 |
* @author James Pratt me@jamiep.org
|
|
|
47 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
48 |
*/
|
|
|
49 |
class analysis_for_question_all_tries extends analysis_for_question{
|
|
|
50 |
/**
|
|
|
51 |
* Constructor.
|
|
|
52 |
*
|
|
|
53 |
* @param int $variantno variant number
|
|
|
54 |
* @param \array[] $responsepartsforeachtry for question with multiple tries we expect an array with first index being try no
|
|
|
55 |
* then second index is subpartid and values are \question_classified_response
|
|
|
56 |
*/
|
|
|
57 |
public function count_response_parts($variantno, $responsepartsforeachtry) {
|
|
|
58 |
foreach ($responsepartsforeachtry as $try => $responseparts) {
|
|
|
59 |
foreach ($responseparts as $subpartid => $responsepart) {
|
|
|
60 |
$this->get_analysis_for_subpart($variantno, $subpartid)->count_response($responsepart, $try);
|
|
|
61 |
}
|
|
|
62 |
}
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
public function has_multiple_tries_data() {
|
|
|
66 |
return true;
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
/**
|
|
|
70 |
* What is the highest number of tries at this question?
|
|
|
71 |
*
|
|
|
72 |
* @return int try number
|
|
|
73 |
*/
|
|
|
74 |
public function get_maximum_tries() {
|
|
|
75 |
$max = 1;
|
|
|
76 |
foreach ($this->get_variant_nos() as $variantno) {
|
|
|
77 |
foreach ($this->get_subpart_ids($variantno) as $subpartid) {
|
|
|
78 |
$max = max($max, $this->get_analysis_for_subpart($variantno, $subpartid)->get_maximum_tries());
|
|
|
79 |
}
|
|
|
80 |
}
|
|
|
81 |
return $max;
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
}
|