Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/quiz/grade.php
Go to the documentation of this file.
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 
00028 require_once(dirname(__FILE__) . '/../../config.php');
00029 require_once($CFG->dirroot . '/mod/quiz/locallib.php');
00030 require_once($CFG->dirroot . '/mod/quiz/report/reportlib.php');
00031 
00032 
00033 $id = required_param('id', PARAM_INT);
00034 $userid = optional_param('userid', 0, PARAM_INT);
00035 
00036 $cm = get_coursemodule_from_id('quiz', $id, 0, false, MUST_EXIST);
00037 $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
00038 $quiz = $DB->get_record('quiz', array('id' => $cm->instance), '*', MUST_EXIST);
00039 require_login($course, false, $cm);
00040 
00041 $reportlist = quiz_report_list(context_module::instance($cm->id));
00042 if (empty($reportlist) || $userid == $USER->id) {
00043     // If the user cannot see reports, or can see reports but is looking
00044     // at their own grades, redirect them to the view.php page.
00045     // (The looking at their own grades case is unlikely, since users who
00046     // appear in the gradebook are unlikely to be able to see quiz reports,
00047     // but it is possible.)
00048     redirect(new moodle_url('/mod/quiz/view.php', array('id' => $cm->id)));
00049 }
00050 
00051 // Now we know the user is interested in reports. If they are interested in a
00052 // specific other user, try to send them to the most appropriate attempt review page.
00053 if ($userid) {
00054 
00055     // Work out which attempt is most significant from a grading point of view.
00056     $attempts = quiz_get_user_attempts($quiz->id, $userid, 'finished');
00057     $attempt = null;
00058     switch ($quiz->grademethod) {
00059         case QUIZ_ATTEMPTFIRST:
00060             $attempt = reset($attempts);
00061             break;
00062 
00063         case QUIZ_ATTEMPTLAST:
00064         case QUIZ_GRADEAVERAGE:
00065             $attempt = end($attempts);
00066             break;
00067 
00068         case QUIZ_GRADEHIGHEST:
00069             $maxmark = 0;
00070             foreach ($attempts as $at) {
00071                 // >=, since we want to most recent relevant attempt.
00072                 if ((float) $at->sumgrades >= $maxmark) {
00073                     $maxmark = $at->sumgrades;
00074                     $attempt = $at;
00075                 }
00076             }
00077             break;
00078     }
00079 
00080     // If the user can review the relevant attempt, redirect to it.
00081     if ($attempt) {
00082         $attemptobj = new quiz_attempt($attempt, $quiz, $cm, $course, false);
00083         if ($attemptobj->is_review_allowed()) {
00084             redirect($attemptobj->review_url());
00085         }
00086     }
00087 
00088     // Otherwise, fall thorugh to the generic case.
00089 }
00090 
00091 // Send the user to the first report they can see.
00092 redirect(new moodle_url('/mod/quiz/report.php', array(
00093         'id' => $cm->id, 'mode' => reset($reportlist))));
 All Data Structures Namespaces Files Functions Variables Enumerations