[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/mod/quiz/report/responses/ -> report.php (source)

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * This file defines the quiz responses report class.
  19   *
  20   * @package   quiz_responses
  21   * @copyright 2006 Jean-Michel Vedrine
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  require_once($CFG->dirroot . '/mod/quiz/report/attemptsreport.php');
  29  require_once($CFG->dirroot . '/mod/quiz/report/responses/responses_options.php');
  30  require_once($CFG->dirroot . '/mod/quiz/report/responses/responses_form.php');
  31  require_once($CFG->dirroot . '/mod/quiz/report/responses/last_responses_table.php');
  32  require_once($CFG->dirroot . '/mod/quiz/report/responses/first_or_all_responses_table.php');
  33  
  34  
  35  /**
  36   * Quiz report subclass for the responses report.
  37   *
  38   * This report lists some combination of
  39   *  * what question each student saw (this makes sense if random questions were used).
  40   *  * the response they gave,
  41   *  * and what the right answer is.
  42   *
  43   * Like the overview report, there are options for showing students with/without
  44   * attempts, and for deleting selected attempts.
  45   *
  46   * @copyright 1999 onwards Martin Dougiamas and others {@link http://moodle.com}
  47   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  48   */
  49  class quiz_responses_report extends quiz_attempts_report {
  50  
  51      public function display($quiz, $cm, $course) {
  52          global $OUTPUT;
  53  
  54          list($currentgroup, $students, $groupstudents, $allowed) =
  55                  $this->init('responses', 'quiz_responses_settings_form', $quiz, $cm, $course);
  56          $options = new quiz_responses_options('responses', $quiz, $cm, $course);
  57  
  58          if ($fromform = $this->form->get_data()) {
  59              $options->process_settings_from_form($fromform);
  60  
  61          } else {
  62              $options->process_settings_from_params();
  63          }
  64  
  65          $this->form->set_data($options->get_initial_form_data());
  66  
  67          if ($options->attempts == self::ALL_WITH) {
  68              // This option is only available to users who can access all groups in
  69              // groups mode, so setting allowed to empty (which means all quiz attempts
  70              // are accessible, is not a security porblem.
  71              $allowed = array();
  72          }
  73  
  74          // Load the required questions.
  75          $questions = quiz_report_get_significant_questions($quiz);
  76  
  77          // Prepare for downloading, if applicable.
  78          $courseshortname = format_string($course->shortname, true,
  79                  array('context' => context_course::instance($course->id)));
  80          if ($options->whichtries === question_attempt::LAST_TRY) {
  81              $tableclassname = 'quiz_last_responses_table';
  82          } else {
  83              $tableclassname = 'quiz_first_or_all_responses_table';
  84          }
  85          $table = new $tableclassname($quiz, $this->context, $this->qmsubselect,
  86                  $options, $groupstudents, $students, $questions, $options->get_url());
  87          $filename = quiz_report_download_filename(get_string('responsesfilename', 'quiz_responses'),
  88                  $courseshortname, $quiz->name);
  89          $table->is_downloading($options->download, $filename,
  90                  $courseshortname . ' ' . format_string($quiz->name, true));
  91          if ($table->is_downloading()) {
  92              raise_memory_limit(MEMORY_EXTRA);
  93          }
  94  
  95          $this->process_actions($quiz, $cm, $currentgroup, $groupstudents, $allowed, $options->get_url());
  96  
  97          // Start output.
  98          if (!$table->is_downloading()) {
  99              // Only print headers if not asked to download data.
 100              $this->print_header_and_tabs($cm, $course, $quiz, $this->mode);
 101          }
 102  
 103          if ($groupmode = groups_get_activity_groupmode($cm)) {
 104              // Groups are being used, so output the group selector if we are not downloading.
 105              if (!$table->is_downloading()) {
 106                  groups_print_activity_menu($cm, $options->get_url());
 107              }
 108          }
 109  
 110          // Print information on the number of existing attempts.
 111          if (!$table->is_downloading()) {
 112              // Do not print notices when downloading.
 113              if ($strattemptnum = quiz_num_attempt_summary($quiz, $cm, true, $currentgroup)) {
 114                  echo '<div class="quizattemptcounts">' . $strattemptnum . '</div>';
 115              }
 116          }
 117  
 118          $hasquestions = quiz_has_questions($quiz->id);
 119          if (!$table->is_downloading()) {
 120              if (!$hasquestions) {
 121                  echo quiz_no_questions_message($quiz, $cm, $this->context);
 122              } else if (!$students) {
 123                  echo $OUTPUT->notification(get_string('nostudentsyet'));
 124              } else if ($currentgroup && !$groupstudents) {
 125                  echo $OUTPUT->notification(get_string('nostudentsingroup'));
 126              }
 127  
 128              // Print the display options.
 129              $this->form->display();
 130          }
 131  
 132          $hasstudents = $students && (!$currentgroup || $groupstudents);
 133          if ($hasquestions && ($hasstudents || $options->attempts == self::ALL_WITH)) {
 134  
 135              list($fields, $from, $where, $params) = $table->base_sql($allowed);
 136  
 137              $table->set_count_sql("SELECT COUNT(1) FROM $from WHERE $where", $params);
 138  
 139              $table->set_sql($fields, $from, $where, $params);
 140  
 141              if (!$table->is_downloading()) {
 142                  // Print information on the grading method.
 143                  if ($strattempthighlight = quiz_report_highlighting_grading_method(
 144                          $quiz, $this->qmsubselect, $options->onlygraded)) {
 145                      echo '<div class="quizattemptcounts">' . $strattempthighlight . '</div>';
 146                  }
 147              }
 148  
 149              // Define table columns.
 150              $columns = array();
 151              $headers = array();
 152  
 153              if (!$table->is_downloading() && $options->checkboxcolumn) {
 154                  $columns[] = 'checkbox';
 155                  $headers[] = null;
 156              }
 157  
 158              $this->add_user_columns($table, $columns, $headers);
 159              $this->add_state_column($columns, $headers);
 160  
 161              if ($table->is_downloading()) {
 162                  $this->add_time_columns($columns, $headers);
 163              }
 164  
 165              $this->add_grade_columns($quiz, $options->usercanseegrades, $columns, $headers);
 166  
 167              foreach ($questions as $id => $question) {
 168                  if ($options->showqtext) {
 169                      $columns[] = 'question' . $id;
 170                      $headers[] = get_string('questionx', 'question', $question->number);
 171                  }
 172                  if ($options->showresponses) {
 173                      $columns[] = 'response' . $id;
 174                      $headers[] = get_string('responsex', 'quiz_responses', $question->number);
 175                  }
 176                  if ($options->showright) {
 177                      $columns[] = 'right' . $id;
 178                      $headers[] = get_string('rightanswerx', 'quiz_responses', $question->number);
 179                  }
 180              }
 181  
 182              $table->define_columns($columns);
 183              $table->define_headers($headers);
 184              $table->sortable(true, 'uniqueid');
 185  
 186              // Set up the table.
 187              $table->define_baseurl($options->get_url());
 188  
 189              $this->configure_user_columns($table);
 190  
 191              $table->no_sorting('feedbacktext');
 192              $table->column_class('sumgrades', 'bold');
 193  
 194              $table->set_attribute('id', 'responses');
 195  
 196              $table->collapsible(true);
 197  
 198              $table->out($options->pagesize, true);
 199          }
 200          return true;
 201      }
 202  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1