Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/quiz/index.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 
00027 require_once("../../config.php");
00028 require_once("locallib.php");
00029 
00030 $id = required_param('id', PARAM_INT);
00031 $PAGE->set_url('/mod/quiz/index.php', array('id'=>$id));
00032 if (!$course = $DB->get_record('course', array('id' => $id))) {
00033     print_error('invalidcourseid');
00034 }
00035 $coursecontext = get_context_instance(CONTEXT_COURSE, $id);
00036 require_login($course->id);
00037 $PAGE->set_pagelayout('incourse');
00038 
00039 add_to_log($course->id, "quiz", "view all", "index.php?id=$course->id", "");
00040 
00041 // Print the header
00042 $strquizzes = get_string("modulenameplural", "quiz");
00043 $streditquestions = '';
00044 $editqcontexts = new question_edit_contexts($coursecontext);
00045 if ($editqcontexts->have_one_edit_tab_cap('questions')) {
00046     $streditquestions =
00047             "<form target=\"_parent\" method=\"get\" action=\"$CFG->wwwroot/question/edit.php\">
00048                <div>
00049                <input type=\"hidden\" name=\"courseid\" value=\"$course->id\" />
00050                <input type=\"submit\" value=\"".get_string("editquestions", "quiz")."\" />
00051                </div>
00052              </form>";
00053 }
00054 $PAGE->navbar->add($strquizzes);
00055 $PAGE->set_title($strquizzes);
00056 $PAGE->set_button($streditquestions);
00057 $PAGE->set_heading($course->fullname);
00058 echo $OUTPUT->header();
00059 
00060 // Get all the appropriate data
00061 if (!$quizzes = get_all_instances_in_course("quiz", $course)) {
00062     notice(get_string('thereareno', 'moodle', $strquizzes), "../../course/view.php?id=$course->id");
00063     die;
00064 }
00065 $sections = get_all_sections($course->id);
00066 
00067 // Check if we need the closing date header
00068 $showclosingheader = false;
00069 $showfeedback = false;
00070 foreach ($quizzes as $quiz) {
00071     if ($quiz->timeclose!=0) {
00072         $showclosingheader=true;
00073     }
00074     if (quiz_has_feedback($quiz)) {
00075         $showfeedback=true;
00076     }
00077     if ($showclosingheader && $showfeedback) {
00078         break;
00079     }
00080 }
00081 
00082 // Configure table for displaying the list of instances.
00083 $headings = array(get_string('name'));
00084 $align = array('left');
00085 
00086 if ($showclosingheader) {
00087     array_push($headings, get_string('quizcloses', 'quiz'));
00088     array_push($align, 'left');
00089 }
00090 
00091 array_unshift($headings, get_string('sectionname', 'format_'.$course->format));
00092 array_unshift($align, 'center');
00093 
00094 $showing = '';  // default
00095 
00096 if (has_capability('mod/quiz:viewreports', $coursecontext)) {
00097     array_push($headings, get_string('attempts', 'quiz'));
00098     array_push($align, 'left');
00099     $showing = 'stats';
00100 
00101 } else if (has_any_capability(array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'),
00102         $coursecontext)) {
00103     array_push($headings, get_string('grade', 'quiz'));
00104     array_push($align, 'left');
00105     if ($showfeedback) {
00106         array_push($headings, get_string('feedback', 'quiz'));
00107         array_push($align, 'left');
00108     }
00109     $showing = 'grades';  // default
00110 
00111     $grades = $DB->get_records_sql_menu('
00112             SELECT qg.quiz, qg.grade
00113             FROM {quiz_grades} qg
00114             JOIN {quiz} q ON q.id = qg.quiz
00115             WHERE q.course = ? AND qg.userid = ?',
00116             array($course->id, $USER->id));
00117 }
00118 
00119 $table = new html_table();
00120 $table->head = $headings;
00121 $table->align = $align;
00122 
00123 // Populate the table with the list of instances.
00124 $currentsection = '';
00125 foreach ($quizzes as $quiz) {
00126     $cm = get_coursemodule_from_instance('quiz', $quiz->id);
00127     $context = get_context_instance(CONTEXT_MODULE, $cm->id);
00128     $data = array();
00129 
00130     // Section number if necessary.
00131     $strsection = '';
00132     if ($quiz->section != $currentsection) {
00133         if ($quiz->section) {
00134             $strsection = $quiz->section;
00135             $strsection = get_section_name($course, $sections[$quiz->section]);
00136         }
00137         if ($currentsection) {
00138             $learningtable->data[] = 'hr';
00139         }
00140         $currentsection = $quiz->section;
00141     }
00142     $data[] = $strsection;
00143 
00144     // Link to the instance.
00145     $class = '';
00146     if (!$quiz->visible) {
00147         $class = ' class="dimmed"';
00148     }
00149     $data[] = "<a$class href=\"view.php?id=$quiz->coursemodule\">" .
00150             format_string($quiz->name, true) . '</a>';
00151 
00152     // Close date.
00153     if ($quiz->timeclose) {
00154         $data[] = userdate($quiz->timeclose);
00155     } else if ($showclosingheader) {
00156         $data[] = '';
00157     }
00158 
00159     if ($showing == 'stats') {
00160         // The $quiz objects returned by get_all_instances_in_course have the necessary $cm
00161         // fields set to make the following call work.
00162         $data[] = quiz_attempt_summary_link_to_reports($quiz, $cm, $context);
00163 
00164     } else if ($showing == 'grades') {
00165         // Grade and feedback.
00166         $attempts = quiz_get_user_attempts($quiz->id, $USER->id, 'all');
00167         list($someoptions, $alloptions) = quiz_get_combined_reviewoptions(
00168                 $quiz, $attempts, $context);
00169 
00170         $grade = '';
00171         $feedback = '';
00172         if ($quiz->grade && array_key_exists($quiz->id, $grades)) {
00173             if ($alloptions->marks >= question_display_options::MARK_AND_MAX) {
00174                 $a = new stdClass();
00175                 $a->grade = quiz_format_grade($quiz, $grades[$quiz->id]);
00176                 $a->maxgrade = quiz_format_grade($quiz, $quiz->grade);
00177                 $grade = get_string('outofshort', 'quiz', $a);
00178             }
00179             if ($alloptions->overallfeedback) {
00180                 $feedback = quiz_feedback_for_grade($grades[$quiz->id], $quiz, $context);
00181             }
00182         }
00183         $data[] = $grade;
00184         if ($showfeedback) {
00185             $data[] = $feedback;
00186         }
00187     }
00188 
00189     $table->data[] = $data;
00190 } // End of loop over quiz instances.
00191 
00192 // Display the table.
00193 echo html_writer::table($table);
00194 
00195 // Finish the page
00196 echo $OUTPUT->footer();
 All Data Structures Namespaces Files Functions Variables Enumerations