/** * Send the user back to the quiz view page. Normally this is just a redirect, but * If we were in a secure window, we close this window, and reload the view window we came from. * * This method does not return; * * @param mod_quiz_renderer $output the quiz renderer. * @param string $message optional message to output while redirecting. */ public function back_to_view_page($output, $message = '') { if ($this->attempt_must_be_in_popup()) { echo $output->close_attempt_popup($this->quizobj->view_url(), $message); die(); } else { redirect($this->quizobj->view_url(), $message); } }
public function render_end_bits(mod_quiz_renderer $output) { $html = ''; if ($this->attemptobj->get_num_pages() > 1) { if ($this->showall) { $html .= html_writer::link($this->attemptobj->review_url(null, 0, false), get_string('showeachpage', 'quiz')); } else { $html .= html_writer::link($this->attemptobj->review_url(null, 0, true), get_string('showall', 'quiz')); } } $html .= $output->finish_review_link($this->attemptobj); $html .= $this->render_restart_preview_link($output); return $html; }
/** * Generates the table of data * * @param array $quiz Array contining quiz data * @param int $context The page context ID * @param mod_quiz_view_object $viewobj */ public function view_table($quiz, $context, $viewobj) { // Most of the following code is unfortunately a duplicate of the existing renderer. There was no way to reuse the existing // code and add the extra columns we wanted so I had to duplicate it. // New parts of the code are marked with a comment // Grade by category code start. and // Grade by category code end. global $DB; // Grade by category code start. // If gradebycategory setting is not on then just use the existing renderer. if (!$quiz->gradebycategory) { return parent::view_table($quiz, $context, $viewobj); } // Grade by category code end. if (!$viewobj->attempts) { return ''; } // Prepare table header. $table = new html_table(); $table->attributes['class'] = 'generaltable quizattemptsummary'; $table->head = array(); $table->align = array(); $table->size = array(); if ($viewobj->attemptcolumn) { $table->head[] = get_string('attemptnumber', 'quiz'); $table->align[] = 'center'; $table->size[] = ''; } $table->head[] = get_string('attemptstate', 'quiz'); $table->align[] = 'left'; $table->size[] = ''; if ($viewobj->markcolumn) { $table->head[] = get_string('marks', 'quiz') . ' / ' . quiz_format_grade($quiz, $quiz->sumgrades); $table->align[] = 'center'; $table->size[] = ''; } if ($viewobj->gradecolumn) { $table->head[] = get_string('grade') . ' / ' . quiz_format_grade($quiz, $quiz->grade); $table->align[] = 'center'; $table->size[] = ''; } // Grade by category code start. $catgrades = new quizaccess_gradebycategory_calculator($quiz); // $this->lateststeps may or may not already have been loaded depending if the reoprt // is set to show question grades. $catgrades->load_latest_steps($viewobj->attempts); $categorynames = $catgrades->load_cat_data(); // Output column headings for category averages foreach ($categorynames as $catname) { $table->head[] = $catname . ' / ' . quiz_format_grade($quiz, 100); $table->align[] = 'center'; $table->size[] = ''; } // Grade by category code end. if ($viewobj->canreviewmine) { $table->head[] = get_string('review', 'quiz'); $table->align[] = 'center'; $table->size[] = ''; } if ($viewobj->feedbackcolumn) { $table->head[] = get_string('feedback', 'quiz'); $table->align[] = 'left'; $table->size[] = ''; } // One row for each attempt. foreach ($viewobj->attemptobjs as $attemptobj) { $attemptoptions = $attemptobj->get_display_options(true); $row = array(); // Add the attempt number. if ($viewobj->attemptcolumn) { if ($attemptobj->is_preview()) { $row[] = get_string('preview', 'quiz'); } else { $row[] = $attemptobj->get_attempt_number(); } } $row[] = $this->attempt_state($attemptobj); if ($viewobj->markcolumn) { if ($attemptoptions->marks >= question_display_options::MARK_AND_MAX && $attemptobj->is_finished()) { $row[] = quiz_format_grade($quiz, $attemptobj->get_sum_marks()); } else { $row[] = ''; } } // Outside the if because we may be showing feedback but not grades. $attemptgrade = quiz_rescale_grade($attemptobj->get_sum_marks(), $quiz, false); if ($viewobj->gradecolumn) { if ($attemptoptions->marks >= question_display_options::MARK_AND_MAX && $attemptobj->is_finished()) { // Highlight the highest grade if appropriate. if ($viewobj->overallstats && !$attemptobj->is_preview() && $viewobj->numattempts > 1 && !is_null($viewobj->mygrade) && $attemptgrade == $viewobj->mygrade && $quiz->grademethod == QUIZ_GRADEHIGHEST) { $table->rowclasses[$attemptobj->get_attempt_number()] = 'bestrow'; } $row[] = quiz_format_grade($quiz, $attemptgrade); } else { $row[] = ''; } } // Grade by category code start. // Output cell contents for category average. foreach (array_keys($categorynames) as $catid) { $row[] = $catgrades->grade_by_category($attemptobj->get_uniqueid(), $catid); } // Grade by category code end. if ($viewobj->canreviewmine) { $row[] = $viewobj->accessmanager->make_review_link($attemptobj->get_attempt(), $attemptoptions, $this); } if ($viewobj->feedbackcolumn && $attemptobj->is_finished()) { if ($attemptoptions->overallfeedback) { $row[] = quiz_feedback_for_grade($attemptgrade, $quiz, $context); } else { $row[] = ''; } } if ($attemptobj->is_preview()) { $table->data['preview'] = $row; } else { $table->data[$attemptobj->get_attempt_number()] = $row; } } // End of loop over attempts. $output = ''; $output .= $this->view_table_heading(); $output .= html_writer::table($table); return $output; }