Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | 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
namespace mod_quiz\local\reports;
18
 
19
use html_writer;
20
use MoodleQuickForm;
21
 
22
defined('MOODLE_INTERNAL') || die();
23
 
24
require_once($CFG->libdir . '/formslib.php');
25
 
26
/**
27
 * Base class for the settings form for {@see attempts_report}s.
28
 *
29
 * @package   mod_quiz
30
 * @copyright 2012 The Open University
31
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32
 */
33
abstract class attempts_report_options_form extends \moodleform {
34
 
35
    protected function definition() {
36
        $mform = $this->_form;
37
 
38
        $mform->addElement('header', 'preferencespage',
39
                get_string('reportwhattoinclude', 'quiz'));
40
 
41
        $this->standard_attempt_fields($mform);
42
        $this->other_attempt_fields($mform);
43
 
44
        $mform->addElement('header', 'preferencesuser',
45
                get_string('reportdisplayoptions', 'quiz'));
46
 
47
        $this->standard_preference_fields($mform);
48
        $this->other_preference_fields($mform);
49
 
50
        $mform->addElement('submit', 'submitbutton',
51
                get_string('showreport', 'quiz'));
52
    }
53
 
54
    /**
55
     * Add the standard form fields for selecting which attempts to include in the report.
56
     *
57
     * @param MoodleQuickForm $mform the form we are building.
58
     */
59
    protected function standard_attempt_fields(MoodleQuickForm $mform) {
60
 
61
        $mform->addElement('select', 'attempts', get_string('reportattemptsfrom', 'quiz'), [
62
                    attempts_report::ENROLLED_WITH    => get_string('reportuserswith', 'quiz'),
63
                    attempts_report::ENROLLED_WITHOUT => get_string('reportuserswithout', 'quiz'),
64
                    attempts_report::ENROLLED_ALL     => get_string('reportuserswithorwithout', 'quiz'),
65
                    attempts_report::ALL_WITH         => get_string('reportusersall', 'quiz'),
66
        ]);
67
 
68
        $stategroup = [
1441 ariadna 69
            $mform->createElement('advcheckbox', 'statenotstarted', '',
70
                    get_string('statenotstarted', 'quiz')),
1 efrain 71
            $mform->createElement('advcheckbox', 'stateinprogress', '',
72
                    get_string('stateinprogress', 'quiz')),
73
            $mform->createElement('advcheckbox', 'stateoverdue', '',
74
                    get_string('stateoverdue', 'quiz')),
1441 ariadna 75
            $mform->createElement('advcheckbox', 'statesubmitted', '',
76
                    get_string('statesubmitted', 'quiz')),
1 efrain 77
            $mform->createElement('advcheckbox', 'statefinished', '',
78
                    get_string('statefinished', 'quiz')),
79
            $mform->createElement('advcheckbox', 'stateabandoned', '',
80
                    get_string('stateabandoned', 'quiz')),
81
        ];
82
        $mform->addGroup($stategroup, 'stateoptions',
83
                get_string('reportattemptsthatare', 'quiz'), [' '], false);
1441 ariadna 84
        $mform->addHelpButton('stateoptions', 'stateoptions', 'quiz');
85
        $mform->setDefault('statenotstarted', 1);
1 efrain 86
        $mform->setDefault('stateinprogress', 1);
87
        $mform->setDefault('stateoverdue',    1);
1441 ariadna 88
        $mform->setDefault('statesubmitted', 1);
1 efrain 89
        $mform->setDefault('statefinished',   1);
90
        $mform->setDefault('stateabandoned',  1);
1441 ariadna 91
        $mform->disabledIf('statenotstarted', 'attempts', 'eq', attempts_report::ENROLLED_WITHOUT);
1 efrain 92
        $mform->disabledIf('stateinprogress', 'attempts', 'eq', attempts_report::ENROLLED_WITHOUT);
93
        $mform->disabledIf('stateoverdue',    'attempts', 'eq', attempts_report::ENROLLED_WITHOUT);
1441 ariadna 94
        $mform->disabledIf('statesubmitted', 'attempts', 'eq', attempts_report::ENROLLED_WITHOUT);
1 efrain 95
        $mform->disabledIf('statefinished',   'attempts', 'eq', attempts_report::ENROLLED_WITHOUT);
96
        $mform->disabledIf('stateabandoned',  'attempts', 'eq', attempts_report::ENROLLED_WITHOUT);
97
 
98
        if (quiz_report_can_filter_only_graded($this->_customdata['quiz'])) {
99
            $gm = html_writer::tag('span',
100
                    quiz_get_grading_option_name($this->_customdata['quiz']->grademethod),
101
                    ['class' => 'highlight']);
102
            $mform->addElement('advcheckbox', 'onlygraded', '',
103
                    get_string('reportshowonlyfinished', 'quiz', $gm));
104
            $mform->disabledIf('onlygraded', 'attempts', 'eq', attempts_report::ENROLLED_WITHOUT);
105
            $mform->disabledIf('onlygraded', 'statefinished', 'notchecked');
106
        }
107
    }
108
 
109
    /**
110
     * Extension point to allow subclasses to add their own fields in the attempts section.
111
     *
112
     * @param MoodleQuickForm $mform the form we are building.
113
     */
114
    protected function other_attempt_fields(MoodleQuickForm $mform) {
115
    }
116
 
117
    /**
118
     * Add the standard options fields to the form.
119
     *
120
     * @param MoodleQuickForm $mform the form we are building.
121
     */
122
    protected function standard_preference_fields(MoodleQuickForm $mform) {
123
        $mform->addElement('text', 'pagesize', get_string('pagesize', 'quiz'));
124
        $mform->setType('pagesize', PARAM_INT);
125
    }
126
 
127
    /**
128
     * Extension point to allow subclasses to add their own fields in the options section.
129
     *
130
     * @param MoodleQuickForm $mform the form we are building.
131
     */
132
    protected function other_preference_fields(MoodleQuickForm $mform) {
133
    }
134
 
135
    public function validation($data, $files) {
136
        $errors = parent::validation($data, $files);
137
 
1441 ariadna 138
        if (
139
            $data['attempts'] != attempts_report::ENROLLED_WITHOUT &&
140
            !(
141
                $data['stateinprogress']
142
                || $data['stateoverdue']
143
                || $data['statefinished']
144
                || $data['stateabandoned']
145
                || $data['statenotstarted']
146
                || $data['statesubmitted']
147
            )
148
        ) {
1 efrain 149
            $errors['stateoptions'] = get_string('reportmustselectstate', 'quiz');
150
        }
151
 
152
        return $errors;
153
    }
154
}