[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/mod/quiz/ -> index.php (source)

   1  <?php // $Id: index.php,v 1.46.2.11 2008/04/23 10:54:57 tjhunt Exp $
   2  /**
   3   * This page lists all the instances of quiz in a particular course
   4   *
   5   * @author Martin Dougiamas and many others.
   6   * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
   7   * @package quiz
   8   */
   9      require_once("../../config.php");
  10      require_once ("locallib.php");
  11  
  12      $id = required_param('id', PARAM_INT);
  13      if (!$course = get_record("course", "id", $id)) {
  14          error("Course ID is incorrect");
  15      }
  16      $coursecontext = get_context_instance(CONTEXT_COURSE, $id);
  17      require_login($course->id);
  18      add_to_log($course->id, "quiz", "view all", "index.php?id=$course->id", "");
  19  
  20  // Print the header
  21      $strquizzes = get_string("modulenameplural", "quiz");
  22      $streditquestions = '';
  23      $editqcontexts = new question_edit_contexts($coursecontext);
  24      if ($editqcontexts->have_one_edit_tab_cap('questions')) {
  25          $streditquestions =
  26                  "<form target=\"_parent\" method=\"get\" action=\"$CFG->wwwroot/question/edit.php\">
  27                     <div>
  28                     <input type=\"hidden\" name=\"courseid\" value=\"$course->id\" />
  29                     <input type=\"submit\" value=\"".get_string("editquestions", "quiz")."\" />
  30                     </div>
  31                   </form>";
  32      }
  33      $navlinks = array();
  34      $navlinks[] = array('name' => $strquizzes, 'link' => '', 'type' => 'activity');
  35      $navigation = build_navigation($navlinks);
  36  
  37      print_header_simple($strquizzes, '', $navigation,
  38                   '', '', true, $streditquestions, navmenu($course));
  39  
  40  // Get all the appropriate data
  41      if (!$quizzes = get_all_instances_in_course("quiz", $course)) {
  42          notice(get_string('thereareno', 'moodle', $strquizzes), "../../course/view.php?id=$course->id");
  43          die;
  44      }
  45  
  46  // Configure table for displaying the list of instances.
  47      $headings = array(get_string('name'), get_string('quizcloses', 'quiz'));
  48      $align = array('left', 'left');
  49      if ($course->format == 'weeks' or $course->format == 'weekscss') {
  50          array_unshift($headings, get_string('week'));
  51      } else {
  52          array_unshift($headings, get_string('section'));
  53      }
  54      array_unshift($align, 'center');
  55  
  56      $showing = 'scores';  // default
  57  
  58      if (has_capability('mod/quiz:viewreports', $coursecontext)) {
  59          array_push($headings, get_string('attempts', 'quiz'));
  60          array_push($align, 'left');
  61          $showing = 'stats';
  62      } else if (has_capability('mod/quiz:attempt', $coursecontext)) {
  63          array_push($headings, get_string('bestgrade', 'quiz'), get_string('feedback', 'quiz'));
  64          array_push($align, 'left', 'left');
  65      }
  66  
  67      $table->head = $headings;
  68      $table->align = $align;
  69  
  70  /// Populate the table with the list of instances.
  71      $currentsection = '';
  72      foreach ($quizzes as $quiz) {
  73          $cm = get_coursemodule_from_instance('quiz', $quiz->id);
  74          $context = get_context_instance(CONTEXT_MODULE, $cm->id);
  75          $data = array();
  76  
  77          // Section number if necessary.
  78          $strsection = '';
  79          if ($quiz->section != $currentsection) {
  80              if ($quiz->section) {
  81                  $strsection = $quiz->section;
  82              }
  83              if ($currentsection) {
  84                  $learningtable->data[] = 'hr';
  85              }
  86              $currentsection = $quiz->section;
  87          }
  88          $data[] = $strsection;
  89  
  90          // Link to the instance.
  91          $class = '';
  92          if (!$quiz->visible) {
  93              $class = ' class="dimmed"';
  94          }
  95          $data[] = "<a$class href=\"view.php?id=$quiz->coursemodule\">" . format_string($quiz->name, true) . '</a>';
  96  
  97          // Close date.
  98          if ($quiz->timeclose) {
  99              $data[] = userdate($quiz->timeclose);
 100          } else {
 101              $data[] = '';
 102          }
 103  
 104          if ($showing == 'stats') {
 105              // The $quiz objects returned by get_all_instances_in_course have the necessary $cm
 106              // fields set to make the following call work.
 107              $attemptcount = quiz_num_attempt_summary($quiz, $quiz);
 108              if ($attemptcount) {
 109                  $data[] = "<a$class href=\"report.php?id=$quiz->coursemodule\">$attemptcount</a>";
 110              } else {
 111                  $data[] = '';
 112              }
 113          } else if ($showing == 'scores') {
 114  
 115              // Grade and feedback.
 116              $bestgrade = quiz_get_best_grade($quiz, $USER->id);
 117              $attempts = quiz_get_user_attempts($quiz->id, $USER->id, 'all');
 118              list($someoptions, $alloptions) = quiz_get_combined_reviewoptions($quiz, $attempts, $context);
 119  
 120              $grade = '';
 121              $feedback = '';
 122              if ($quiz->grade && !is_null($bestgrade)) {
 123                  if ($alloptions->scores) {
 124                      $grade = "$bestgrade / $quiz->grade";
 125                  }
 126                  if ($alloptions->overallfeedback) {
 127                      $feedback = quiz_feedback_for_grade($bestgrade, $quiz->id);
 128                  }
 129              }
 130              $data[] = $grade;
 131              $data[] = $feedback;
 132          }
 133  
 134          $table->data[] = $data;
 135      } // End of loop over quiz instances.
 136  
 137  // Display the table.
 138      echo '<br />';
 139      print_table($table);
 140  
 141  // Finish the page
 142      print_footer($course);
 143  ?>


Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7