Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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
use mod_quiz\local\reports\attempts_report;
18
use mod_quiz\local\reports\attempts_report_options;
19
 
20
/**
21
 * Class to store the options for a {@link quiz_responses_report}.
22
 *
23
 * @copyright 2012 The Open University
24
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
 */
26
class quiz_responses_options extends attempts_report_options {
27
 
28
    /** @var bool whether to show the question text columns. */
29
    public $showqtext = false;
30
 
31
    /** @var bool whether to show the students' response columns. */
32
    public $showresponses = true;
33
 
34
    /** @var bool whether to show the correct response columns. */
35
    public $showright = false;
36
 
37
    /** @var bool which try/tries to show responses from. */
38
    public $whichtries = question_attempt::LAST_TRY;
39
 
40
    protected function get_url_params() {
41
        $params = parent::get_url_params();
42
        $params['qtext']      = $this->showqtext;
43
        $params['resp']       = $this->showresponses;
44
        $params['right']      = $this->showright;
45
        if (quiz_allows_multiple_tries($this->quiz)) {
46
            $params['whichtries'] = $this->whichtries;
47
        }
48
        return $params;
49
    }
50
 
51
    public function get_initial_form_data() {
52
        $toform = parent::get_initial_form_data();
53
        $toform->qtext      = $this->showqtext;
54
        $toform->resp       = $this->showresponses;
55
        $toform->right      = $this->showright;
56
        if (quiz_allows_multiple_tries($this->quiz)) {
57
            $toform->whichtries = $this->whichtries;
58
        }
59
 
60
        return $toform;
61
    }
62
 
63
    public function setup_from_form_data($fromform) {
64
        parent::setup_from_form_data($fromform);
65
 
66
        $this->showqtext     = $fromform->qtext;
67
        $this->showresponses = $fromform->resp;
68
        $this->showright     = $fromform->right;
69
        if (quiz_allows_multiple_tries($this->quiz)) {
70
            $this->whichtries = $fromform->whichtries;
71
        }
72
    }
73
 
74
    public function setup_from_params() {
75
        parent::setup_from_params();
76
 
77
        $this->showqtext     = optional_param('qtext', $this->showqtext,     PARAM_BOOL);
78
        $this->showresponses = optional_param('resp',  $this->showresponses, PARAM_BOOL);
79
        $this->showright     = optional_param('right', $this->showright,     PARAM_BOOL);
80
        if (quiz_allows_multiple_tries($this->quiz)) {
81
            $this->whichtries    = optional_param('whichtries', $this->whichtries, PARAM_ALPHA);
82
        }
83
    }
84
 
85
    public function setup_from_user_preferences() {
86
        parent::setup_from_user_preferences();
87
 
88
        $this->showqtext     = get_user_preferences('quiz_report_responses_qtext', $this->showqtext);
89
        $this->showresponses = get_user_preferences('quiz_report_responses_resp',  $this->showresponses);
90
        $this->showright     = get_user_preferences('quiz_report_responses_right', $this->showright);
91
        if (quiz_allows_multiple_tries($this->quiz)) {
92
            $this->whichtries    = get_user_preferences('quiz_report_responses_which_tries', $this->whichtries);
93
        }
94
    }
95
 
96
    public function update_user_preferences() {
97
        parent::update_user_preferences();
98
 
99
        set_user_preference('quiz_report_responses_qtext', $this->showqtext);
100
        set_user_preference('quiz_report_responses_resp',  $this->showresponses);
101
        set_user_preference('quiz_report_responses_right', $this->showright);
102
        if (quiz_allows_multiple_tries($this->quiz)) {
103
            set_user_preference('quiz_report_responses_which_tries', $this->whichtries);
104
        }
105
    }
106
 
107
    public function resolve_dependencies() {
108
        parent::resolve_dependencies();
109
 
110
        if (!$this->showqtext && !$this->showresponses && !$this->showright) {
111
            // We have to show at least something.
112
            $this->showresponses = true;
113
        }
114
 
115
        // We only want to show the checkbox to delete attempts
116
        // if the user has permissions and if the report mode is showing attempts.
117
        $this->checkboxcolumn = has_capability('mod/quiz:deleteattempts', context_module::instance($this->cm->id))
118
                && ($this->attempts != attempts_report::ENROLLED_WITHOUT);
119
    }
120
}