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
/**
18
 * This script lists all the instances of quiz in a particular course
19
 *
20
 * @package    mod_quiz
21
 * @copyright  1999 onwards Martin Dougiamas  {@link http://moodle.com}
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
use mod_quiz\output\grades\grade_out_of;
1441 ariadna 26
use mod_quiz\output\renderer;
1 efrain 27
 
28
require_once("../../config.php");
29
require_once("locallib.php");
30
 
31
$id = required_param('id', PARAM_INT);
32
 
33
$PAGE->set_url('/mod/quiz/index.php', ['id' => $id]);
34
$course = get_course($id);
35
$coursecontext = context_course::instance($id);
36
require_login($course);
37
$PAGE->set_pagelayout('incourse');
38
 
39
$params = [
40
    'context' => $coursecontext
41
];
42
$event = \mod_quiz\event\course_module_instance_list_viewed::create($params);
43
$event->trigger();
44
 
45
// Print the header.
46
$strquizzes = get_string("modulenameplural", "quiz");
47
$PAGE->navbar->add($strquizzes);
48
$PAGE->set_title($strquizzes);
49
$PAGE->set_heading($course->fullname);
1441 ariadna 50
/** @var renderer $output */
51
$output = $PAGE->get_renderer('mod_quiz');
52
echo $output->header();
53
echo $output->heading($strquizzes, 2);
1 efrain 54
 
55
// Get all the appropriate data.
56
if (!$quizzes = get_all_instances_in_course("quiz", $course)) {
57
    notice(get_string('thereareno', 'moodle', $strquizzes), "../../course/view.php?id=$course->id");
58
    die;
59
}
60
 
61
// Check if we need the feedback header.
62
$showfeedback = false;
63
foreach ($quizzes as $quiz) {
64
    if (quiz_has_feedback($quiz)) {
65
        $showfeedback=true;
66
    }
67
    if ($showfeedback) {
68
        break;
69
    }
70
}
71
 
72
// Configure table for displaying the list of instances.
73
$headings = [get_string('name')];
74
$align = ['left'];
75
 
76
array_push($headings, get_string('quizcloses', 'quiz'));
77
array_push($align, 'left');
78
 
79
if (course_format_uses_sections($course->format)) {
1441 ariadna 80
    array_unshift($headings, course_get_format($course)->get_generic_section_name());
1 efrain 81
} else {
82
    array_unshift($headings, '');
83
}
84
array_unshift($align, 'center');
85
 
86
$showing = '';
87
 
88
if (has_capability('mod/quiz:viewreports', $coursecontext)) {
89
    array_push($headings, get_string('attempts', 'quiz'));
90
    array_push($align, 'left');
91
    $showing = 'stats';
92
 
93
} else if (has_any_capability(['mod/quiz:reviewmyattempts', 'mod/quiz:attempt'],
94
        $coursecontext)) {
95
    array_push($headings, get_string('gradenoun'));
96
    array_push($align, 'left');
97
    if ($showfeedback) {
98
        array_push($headings, get_string('feedback', 'quiz'));
99
        array_push($align, 'left');
100
    }
101
    $showing = 'grades';
102
 
103
    $grades = $DB->get_records_sql_menu('
104
            SELECT qg.quiz, qg.grade
105
            FROM {quiz_grades} qg
106
            JOIN {quiz} q ON q.id = qg.quiz
107
            WHERE q.course = ? AND qg.userid = ?',
108
            [$course->id, $USER->id]);
109
}
110
 
111
$table = new html_table();
112
$table->head = $headings;
113
$table->align = $align;
114
 
115
// Populate the table with the list of instances.
116
$currentsection = '';
117
// Get all closing dates.
118
$timeclosedates = quiz_get_user_timeclose($course->id);
119
foreach ($quizzes as $quiz) {
120
    $cm = get_coursemodule_from_instance('quiz', $quiz->id);
121
    $context = context_module::instance($cm->id);
122
    $data = [];
123
 
124
    // Section number if necessary.
125
    $strsection = '';
126
    if ($quiz->section != $currentsection) {
127
        if ($quiz->section) {
128
            $strsection = $quiz->section;
129
            $strsection = get_section_name($course, $quiz->section);
130
        }
131
        if ($currentsection !== "") {
132
            $table->data[] = 'hr';
133
        }
134
        $currentsection = $quiz->section;
135
    }
136
    $data[] = $strsection;
137
 
138
    // Link to the instance.
139
    $class = '';
140
    if (!$quiz->visible) {
141
        $class = ' class="dimmed"';
142
    }
143
    $data[] = "<a$class href=\"view.php?id=$quiz->coursemodule\">" .
144
            format_string($quiz->name, true) . '</a>';
145
 
146
    // Close date.
147
    if (($timeclosedates[$quiz->id]->usertimeclose != 0)) {
148
        $data[] = userdate($timeclosedates[$quiz->id]->usertimeclose);
149
    } else {
150
        $data[] = get_string('noclose', 'quiz');
151
    }
152
 
153
    if ($showing == 'stats') {
154
        // The $quiz objects returned by get_all_instances_in_course have the necessary $cm
155
        // fields set to make the following call work.
156
        $data[] = quiz_attempt_summary_link_to_reports($quiz, $cm, $context);
157
 
158
    } else if ($showing == 'grades') {
159
        // Grade and feedback.
160
        $attempts = quiz_get_user_attempts($quiz->id, $USER->id, 'all');
161
        list($someoptions, $alloptions) = quiz_get_combined_reviewoptions(
162
                $quiz, $attempts);
163
 
164
        $grade = '';
165
        $feedback = '';
166
        if ($quiz->grade && array_key_exists($quiz->id, $grades)) {
167
            if ($alloptions->marks >= question_display_options::MARK_AND_MAX) {
1441 ariadna 168
                $grade = $output->render(new grade_out_of(
169
                        $quiz, $grades[$quiz->id], $quiz->grade, $quiz->sumgrades, style: grade_out_of::SHORT));
1 efrain 170
            }
171
            if ($alloptions->overallfeedback) {
172
                $feedback = quiz_feedback_for_grade($grades[$quiz->id], $quiz, $context);
173
            }
174
        }
175
        $data[] = $grade;
176
        if ($showfeedback) {
177
            $data[] = $feedback;
178
        }
179
    }
180
 
181
    $table->data[] = $data;
182
} // End of loop over quiz instances.
183
 
184
// Display the table.
185
echo html_writer::table($table);
186
 
187
// Finish the page.
1441 ariadna 188
echo $output->footer();