~ubuntu-branches/ubuntu/utopic/moodle/utopic

« back to all changes in this revision

Viewing changes to question/classes/statistics/responses/analysis_for_actual_response.php

  • Committer: Package Import Robot
  • Author(s): Thijs Kinkhorst
  • Date: 2014-05-12 16:10:38 UTC
  • mfrom: (36.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20140512161038-puyqf65k4e0s8ytz
Tags: 2.6.3-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 * @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
 
22
 */
 
23
 
 
24
namespace core_question\statistics\responses;
 
25
 
 
26
 
 
27
class analysis_for_actual_response {
 
28
    /**
 
29
     * @var int count of this response
 
30
     */
 
31
    protected $count;
 
32
 
 
33
    /**
 
34
     * @var float grade for this response, normally between 0 and 1.
 
35
     */
 
36
    protected $fraction;
 
37
 
 
38
    /**
 
39
     * @var string the response as it will be displayed in report.
 
40
     */
 
41
    protected $response;
 
42
 
 
43
    /**
 
44
     * @param string $response
 
45
     * @param float  $fraction
 
46
     * @param int    $count     defaults to zero, this param used when loading from db.
 
47
     */
 
48
    public function __construct($response, $fraction, $count = 0) {
 
49
        $this->response = $response;
 
50
        $this->fraction = $fraction;
 
51
        $this->count = $count;
 
52
    }
 
53
 
 
54
    /**
 
55
     * Used to count the occurrences of response sub parts.
 
56
     */
 
57
    public function increment_count() {
 
58
        $this->count++;
 
59
    }
 
60
 
 
61
 
 
62
    /**
 
63
     * @param \qubaid_condition $qubaids
 
64
     * @param int               $questionid the question id
 
65
     * @param string            $subpartid
 
66
     * @param string            $responseclassid
 
67
     */
 
68
    public function cache($qubaids, $questionid, $subpartid, $responseclassid) {
 
69
        global $DB;
 
70
        $row = new \stdClass();
 
71
        $row->hashcode = $qubaids->get_hash_code();
 
72
        $row->questionid = $questionid;
 
73
        $row->subqid = $subpartid;
 
74
        if ($responseclassid === '') {
 
75
            $row->aid = null;
 
76
        } else {
 
77
            $row->aid = $responseclassid;
 
78
        }
 
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);
 
84
    }
 
85
 
 
86
    public function response_matches($response) {
 
87
        return $response == $this->response;
 
88
    }
 
89
 
 
90
    /**
 
91
     * @param string $partid
 
92
     * @param string $modelresponse
 
93
     * @return object
 
94
     */
 
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;
 
102
        return $rowdata;
 
103
    }
 
104
}