2
// This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18
* @package core_question
19
* @copyright 2013 The Open University
20
* @author James Pratt me@jamiep.org
21
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
namespace core_question\statistics\responses;
27
class analysis_for_actual_response {
29
* @var int count of this response
34
* @var float grade for this response, normally between 0 and 1.
39
* @var string the response as it will be displayed in report.
44
* @param string $response
45
* @param float $fraction
46
* @param int $count defaults to zero, this param used when loading from db.
48
public function __construct($response, $fraction, $count = 0) {
49
$this->response = $response;
50
$this->fraction = $fraction;
51
$this->count = $count;
55
* Used to count the occurrences of response sub parts.
57
public function increment_count() {
63
* @param \qubaid_condition $qubaids
64
* @param int $questionid the question id
65
* @param string $subpartid
66
* @param string $responseclassid
68
public function cache($qubaids, $questionid, $subpartid, $responseclassid) {
70
$row = new \stdClass();
71
$row->hashcode = $qubaids->get_hash_code();
72
$row->questionid = $questionid;
73
$row->subqid = $subpartid;
74
if ($responseclassid === '') {
77
$row->aid = $responseclassid;
79
$row->response = $this->response;
80
$row->rcount = $this->count;
81
$row->credit = $this->fraction;
82
$row->timemodified = time();
83
$DB->insert_record('question_response_analysis', $row, false);
86
public function response_matches($response) {
87
return $response == $this->response;
91
* @param string $partid
92
* @param string $modelresponse
95
public function data_for_question_response_table($partid, $modelresponse) {
96
$rowdata = new \stdClass();
97
$rowdata->part = $partid;
98
$rowdata->responseclass = $modelresponse;
99
$rowdata->response = $this->response;
100
$rowdata->fraction = $this->fraction;
101
$rowdata->count = $this->count;