Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 21... Línea 21...
21
 * @package   mod_quiz
21
 * @package   mod_quiz
22
 * @copyright 1999 onwards Martin Dougiamas  {@link http://moodle.com}
22
 * @copyright 1999 onwards Martin Dougiamas  {@link http://moodle.com}
23
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
24
 */
Línea -... Línea 25...
-
 
25
 
25
 
26
use core\output\notification;
26
use mod_quiz\access_manager;
27
use mod_quiz\access_manager;
27
use mod_quiz\output\list_of_attempts;
28
use mod_quiz\output\list_of_attempts;
28
use mod_quiz\output\renderer;
29
use mod_quiz\output\renderer;
29
use mod_quiz\output\view_page;
30
use mod_quiz\output\view_page;
Línea 66... Línea 67...
66
// Trigger course_module_viewed event and completion.
67
// Trigger course_module_viewed event and completion.
67
quiz_view($quiz, $course, $cm, $context);
68
quiz_view($quiz, $course, $cm, $context);
Línea 68... Línea 69...
68
 
69
 
69
// Initialize $PAGE, compute blocks.
70
// Initialize $PAGE, compute blocks.
-
 
71
$PAGE->set_url('/mod/quiz/view.php', ['id' => $cm->id]);
-
 
72
// On the quiz view page, the browser back/forwards buttons should force a reload.
Línea 70... Línea 73...
70
$PAGE->set_url('/mod/quiz/view.php', ['id' => $cm->id]);
73
$PAGE->set_cacheable(false);
71
 
74
 
72
// Create view object which collects all the information the renderer will need.
75
// Create view object which collects all the information the renderer will need.
73
$viewobj = new view_page();
76
$viewobj = new view_page();
Línea 111... Línea 114...
111
foreach (array_reverse($viewobj->attemptobjs) as $attemptobj) {
114
foreach (array_reverse($viewobj->attemptobjs) as $attemptobj) {
112
    $viewobj->attemptslist->add_attempt($attemptobj);
115
    $viewobj->attemptslist->add_attempt($attemptobj);
113
}
116
}
Línea 114... Línea 117...
114
 
117
 
-
 
118
// Work out the final grade, checking whether it was overridden in the gradebook.
115
// Work out the final grade, checking whether it was overridden in the gradebook.
119
// First, get an initial grade to display.
116
if (!$canpreview) {
120
if (!$canpreview) {
117
    $mygrade = quiz_get_best_grade($quiz, $USER->id);
121
    $mygrade = quiz_get_best_grade($quiz, $USER->id);
118
} else if ($lastfinishedattempt) {
122
} else if ($lastfinishedattempt) {
119
    // Users who can preview the quiz don't get a proper grade, so work out a
123
    // Users who can preview the quiz don't get a proper grade, so work out a
120
    // plausible value to display instead, so the page looks right.
124
    // plausible value to display instead, so the page looks right.
121
    $mygrade = quiz_rescale_grade($lastfinishedattempt->sumgrades, $quiz, false);
125
    $mygrade = quiz_rescale_grade($lastfinishedattempt->sumgrades, $quiz, false);
122
} else {
126
} else {
123
    $mygrade = null;
127
    $mygrade = null;
Línea -... Línea 128...
-
 
128
}
124
}
129
 
125
 
130
// Now, check the grade in the gradebook, if there is one.
Línea 126... Línea 131...
126
$mygradeoverridden = false;
131
$mygradeoverridden = false;
127
$gradebookfeedback = '';
132
$gradebookfeedback = '';
Línea 132... Línea 137...
132
    'iteminstance' => $quiz->id,
137
    'iteminstance' => $quiz->id,
133
    'itemnumber' => 0,
138
    'itemnumber' => 0,
134
    'courseid' => $course->id,
139
    'courseid' => $course->id,
135
]);
140
]);
Línea -... Línea 141...
-
 
141
 
-
 
142
// If there's a grade item grade, then get that grade for this user.
-
 
143
// Users who can preview the quiz (eg teachers) won't have a proper grade,
136
 
144
// so no point getting their grades here.
137
if ($gradeitem) {
145
if (!$canpreview && $gradeitem) {
138
    if ($gradeitem->refresh_grades($USER->id)) {
146
    $grade = $gradeitem->get_grade($USER->id, false);
-
 
147
    $mygrade = $grade->finalgrade; // Use this grade to display in the view page.
139
        $grade = $gradeitem->get_grade($USER->id, false);
148
 
140
        if ($grade->overridden) {
149
    if ($grade->overridden) {
141
            if ($gradeitem->needsupdate) {
150
        if ($gradeitem->needsupdate) {
142
                // It is Error, but let's be consistent with the old code.
151
            // It is Error, but let's be consistent with the old code.
143
                $mygrade = 0;
-
 
144
            } else {
-
 
145
                $mygrade = $grade->finalgrade;
-
 
146
            }
-
 
147
            $mygradeoverridden = true;
152
            $mygrade = 0;
-
 
153
        }
-
 
154
        $mygradeoverridden = true;
Línea 148... Línea 155...
148
        }
155
    }
149
 
156
 
150
        if (!empty($grade->feedback)) {
-
 
151
            $gradebookfeedback = $grade->feedback;
-
 
152
        }
-
 
153
    } else {
-
 
154
        // It is Error, but let's be consistent with the old code.
157
    if (!empty($grade->feedback)) {
155
        $mygrade = 0;
158
        $gradebookfeedback = $grade->feedback;
Línea 156... Línea 159...
156
    }
159
    }
157
}
160
}
Línea 164... Línea 167...
164
}
167
}
165
$PAGE->add_body_class('limitedwidth');
168
$PAGE->add_body_class('limitedwidth');
166
/** @var renderer $output */
169
/** @var renderer $output */
167
$output = $PAGE->get_renderer('mod_quiz');
170
$output = $PAGE->get_renderer('mod_quiz');
Línea 168... Línea 171...
168
 
171
 
169
// Print table with existing attempts.
172
// Print overall stats and table with existing attempts.
170
if ($attempts) {
173
if ($attempts) {
171
    // Work out which columns we need, taking account what data is available in each attempt.
174
    // Work out which columns we need, taking account what data is available in each attempt.
Línea 172... Línea 175...
172
    list($someoptions, $alloptions) = quiz_get_combined_reviewoptions($quiz, $attempts);
175
    list($someoptions, $alloptions) = quiz_get_combined_reviewoptions($quiz, $attempts);
Línea 257... Línea 260...
257
            if ($viewobj->preventmessages) {
260
            if ($viewobj->preventmessages) {
258
                $viewobj->buttontext = '';
261
                $viewobj->buttontext = '';
259
            }
262
            }
260
        }
263
        }
261
    }
264
    }
-
 
265
 
-
 
266
    // If the quiz has any invalid questions, we cannot attempt it.
-
 
267
    if (in_array('missingtype', $quizobj->get_all_question_types_used())) {
-
 
268
        $viewobj->preventmessages[] = $OUTPUT->notification(
-
 
269
            get_string('quizinvalidquestions', 'mod_quiz'), notification::NOTIFY_ERROR, false);
-
 
270
        $viewobj->buttontext = '';
-
 
271
    }
262
}
272
}
Línea 263... Línea 273...
263
 
273
 
264
$viewobj->showbacktocourse = ($viewobj->buttontext === '' &&
274
$viewobj->showbacktocourse = ($viewobj->buttontext === '' &&
Línea 265... Línea 275...
265
        course_get_format($course)->has_view_page());
275
        course_get_format($course)->has_view_page());
Línea 266... Línea 276...
266
 
276
 
267
echo $OUTPUT->header();
277
echo $OUTPUT->header();
268
 
278
 
269
if (!empty($gradinginfo->errors)) {
279
if (!empty($gradinginfo->errors)) {
270
    foreach ($gradinginfo->errors as $error) {
280
    foreach ($gradinginfo->errors as $error) {
271
        $errortext = new \core\output\notification($error, \core\output\notification::NOTIFY_ERROR);
281
        $errortext = new notification($error, notification::NOTIFY_ERROR);
Línea 272... Línea 282...
272
        echo $OUTPUT->render($errortext);
282
        echo $OUTPUT->render($errortext);