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