|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00030 require_once(dirname(__FILE__) . '/../../config.php'); 00031 require_once($CFG->dirroot . '/mod/quiz/locallib.php'); 00032 require_once($CFG->dirroot . '/mod/quiz/report/reportlib.php'); 00033 00034 $attemptid = required_param('attempt', PARAM_INT); 00035 $page = optional_param('page', 0, PARAM_INT); 00036 $showall = optional_param('showall', 0, PARAM_BOOL); 00037 00038 $url = new moodle_url('/mod/quiz/review.php', array('attempt'=>$attemptid)); 00039 if ($page !== 0) { 00040 $url->param('page', $page); 00041 } 00042 if ($showall !== 0) { 00043 $url->param('showall', $showall); 00044 } 00045 $PAGE->set_url($url); 00046 00047 $attemptobj = quiz_attempt::create($attemptid); 00048 00049 // Check login. 00050 require_login($attemptobj->get_course(), false, $attemptobj->get_cm()); 00051 $attemptobj->check_review_capability(); 00052 00053 // Create an object to manage all the other (non-roles) access rules. 00054 $accessmanager = $attemptobj->get_access_manager(time()); 00055 $options = $attemptobj->get_display_options(true); 00056 00057 // Check permissions. 00058 if ($attemptobj->is_own_attempt()) { 00059 if (!$attemptobj->is_finished()) { 00060 redirect($attemptobj->attempt_url(null, $page)); 00061 00062 } else if (!$options->attempt) { 00063 $accessmanager->back_to_view_page($PAGE->get_renderer('mod_quiz'), 00064 $attemptobj->cannot_review_message()); 00065 } 00066 00067 } else if (!$attemptobj->is_review_allowed()) { 00068 throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'noreviewattempt'); 00069 } 00070 00071 // Load the questions and states needed by this page. 00072 if ($showall) { 00073 $questionids = $attemptobj->get_slots(); 00074 } else { 00075 $questionids = $attemptobj->get_slots($page); 00076 } 00077 00078 // Save the flag states, if they are being changed. 00079 if ($options->flags == question_display_options::EDITABLE && optional_param('savingflags', false, 00080 PARAM_BOOL)) { 00081 require_sesskey(); 00082 $attemptobj->save_question_flags(); 00083 redirect($attemptobj->review_url(null, $page, $showall)); 00084 } 00085 00086 // Log this review. 00087 add_to_log($attemptobj->get_courseid(), 'quiz', 'review', 'review.php?attempt=' . 00088 $attemptobj->get_attemptid(), $attemptobj->get_quizid(), $attemptobj->get_cmid()); 00089 00090 // Work out appropriate title and whether blocks should be shown 00091 if ($attemptobj->is_preview_user() && $attemptobj->is_own_attempt()) { 00092 $strreviewtitle = get_string('reviewofpreview', 'quiz'); 00093 navigation_node::override_active_url($attemptobj->start_attempt_url()); 00094 00095 } else { 00096 $strreviewtitle = get_string('reviewofattempt', 'quiz', $attemptobj->get_attempt_number()); 00097 if (empty($attemptobj->get_quiz()->showblocks) && !$attemptobj->is_preview_user()) { 00098 $PAGE->blocks->show_only_fake_blocks(); 00099 } 00100 } 00101 00102 // Set up the page header 00103 $headtags = $attemptobj->get_html_head_contributions($page, $showall); 00104 $PAGE->set_title(format_string($attemptobj->get_quiz_name())); 00105 $PAGE->set_heading($attemptobj->get_course()->fullname); 00106 $accessmanager->setup_attempt_page($PAGE); 00107 00108 // Summary table start ============================================================================ 00109 00110 // Work out some time-related things. 00111 $attempt = $attemptobj->get_attempt(); 00112 $quiz = $attemptobj->get_quiz(); 00113 $overtime = 0; 00114 00115 if ($attempt->timefinish) { 00116 if ($timetaken = ($attempt->timefinish - $attempt->timestart)) { 00117 if ($quiz->timelimit && $timetaken > ($quiz->timelimit + 60)) { 00118 $overtime = $timetaken - $quiz->timelimit; 00119 $overtime = format_time($overtime); 00120 } 00121 $timetaken = format_time($timetaken); 00122 } else { 00123 $timetaken = "-"; 00124 } 00125 } else { 00126 $timetaken = get_string('unfinished', 'quiz'); 00127 } 00128 00129 // Prepare summary informat about the whole attempt. 00130 $summarydata = array(); 00131 if (!$attemptobj->get_quiz()->showuserpicture && $attemptobj->get_userid() != $USER->id) { 00132 // If showuserpicture is true, the picture is shown elsewhere, so don't repeat it. 00133 $student = $DB->get_record('user', array('id' => $attemptobj->get_userid())); 00134 $usrepicture = new user_picture($student); 00135 $usrepicture->courseid = $attemptobj->get_courseid(); 00136 $summarydata['user'] = array( 00137 'title' => $usrepicture, 00138 'content' => new action_link(new moodle_url('/user/view.php', array( 00139 'id' => $student->id, 'course' => $attemptobj->get_courseid())), 00140 fullname($student, true)), 00141 ); 00142 } 00143 if ($attemptobj->has_capability('mod/quiz:viewreports')) { 00144 $attemptlist = $attemptobj->links_to_other_attempts($attemptobj->review_url(null, $page, 00145 $showall)); 00146 if ($attemptlist) { 00147 $summarydata['attemptlist'] = array( 00148 'title' => get_string('attempts', 'quiz'), 00149 'content' => $attemptlist, 00150 ); 00151 } 00152 } 00153 00154 // Timing information. 00155 $summarydata['startedon'] = array( 00156 'title' => get_string('startedon', 'quiz'), 00157 'content' => userdate($attempt->timestart), 00158 ); 00159 00160 if ($attempt->timefinish) { 00161 $summarydata['completedon'] = array( 00162 'title' => get_string('completedon', 'quiz'), 00163 'content' => userdate($attempt->timefinish), 00164 ); 00165 $summarydata['timetaken'] = array( 00166 'title' => get_string('timetaken', 'quiz'), 00167 'content' => $timetaken, 00168 ); 00169 } 00170 00171 if (!empty($overtime)) { 00172 $summarydata['overdue'] = array( 00173 'title' => get_string('overdue', 'quiz'), 00174 'content' => $overtime, 00175 ); 00176 } 00177 00178 // Show marks (if the user is allowed to see marks at the moment). 00179 $grade = quiz_rescale_grade($attempt->sumgrades, $quiz, false); 00180 if ($options->marks >= question_display_options::MARK_AND_MAX && quiz_has_grades($quiz)) { 00181 00182 if (!$attempt->timefinish) { 00183 $summarydata['grade'] = array( 00184 'title' => get_string('grade', 'quiz'), 00185 'content' => get_string('attemptstillinprogress', 'quiz'), 00186 ); 00187 00188 } else if (is_null($grade)) { 00189 $summarydata['grade'] = array( 00190 'title' => get_string('grade', 'quiz'), 00191 'content' => quiz_format_grade($quiz, $grade), 00192 ); 00193 00194 } else { 00195 // Show raw marks only if they are different from the grade (like on the view page). 00196 if ($quiz->grade != $quiz->sumgrades) { 00197 $a = new stdClass(); 00198 $a->grade = quiz_format_grade($quiz, $attempt->sumgrades); 00199 $a->maxgrade = quiz_format_grade($quiz, $quiz->sumgrades); 00200 $summarydata['marks'] = array( 00201 'title' => get_string('marks', 'quiz'), 00202 'content' => get_string('outofshort', 'quiz', $a), 00203 ); 00204 } 00205 00206 // Now the scaled grade. 00207 $a = new stdClass(); 00208 $a->grade = html_writer::tag('b', quiz_format_grade($quiz, $grade)); 00209 $a->maxgrade = quiz_format_grade($quiz, $quiz->grade); 00210 if ($quiz->grade != 100) { 00211 $a->percent = html_writer::tag('b', format_float( 00212 $attempt->sumgrades * 100 / $quiz->sumgrades, 0)); 00213 $formattedgrade = get_string('outofpercent', 'quiz', $a); 00214 } else { 00215 $formattedgrade = get_string('outof', 'quiz', $a); 00216 } 00217 $summarydata['grade'] = array( 00218 'title' => get_string('grade', 'quiz'), 00219 'content' => $formattedgrade, 00220 ); 00221 } 00222 } 00223 00224 // Feedback if there is any, and the user is allowed to see it now. 00225 $feedback = $attemptobj->get_overall_feedback($grade); 00226 if ($options->overallfeedback && $feedback) { 00227 $summarydata['feedback'] = array( 00228 'title' => get_string('feedback', 'quiz'), 00229 'content' => $feedback, 00230 ); 00231 } 00232 00233 // Summary table end ============================================================================== 00234 00235 if ($showall) { 00236 $slots = $attemptobj->get_slots(); 00237 $lastpage = true; 00238 } else { 00239 $slots = $attemptobj->get_slots($page); 00240 $lastpage = $attemptobj->is_last_page($page); 00241 } 00242 00243 $output = $PAGE->get_renderer('mod_quiz'); 00244 00245 // Arrange for the navigation to be displayed. 00246 $navbc = $attemptobj->get_navigation_panel($output, 'quiz_review_nav_panel', $page, $showall); 00247 $firstregion = reset($PAGE->blocks->get_regions()); 00248 $PAGE->blocks->add_fake_block($navbc, $firstregion); 00249 00250 echo $output->review_page($attemptobj, $slots, $page, $showall, $lastpage, $options, $summarydata);