/** * Generates the table of summarydata * * @param quiz_attempt $attemptobj * @param mod_quiz_display_options $displayoptions */ public function summary_table($attemptobj, $displayoptions) { // Prepare the summary table header. $table = new html_table(); $table->attributes['class'] = 'generaltable quizsummaryofattempt boxaligncenter'; $table->head = array(get_string('question', 'quiz'), get_string('status', 'quiz')); $table->align = array('left', 'left'); $table->size = array('', ''); $markscolumn = $displayoptions->marks >= question_display_options::MARK_AND_MAX; if ($markscolumn) { $table->head[] = get_string('marks', 'quiz'); $table->align[] = 'left'; $table->size[] = ''; } $table->data = array(); // Get the summary info for each question. $slots = $attemptobj->get_slots(); foreach ($slots as $slot) { if (!$attemptobj->is_real_question($slot)) { continue; } $flag = ''; if ($attemptobj->is_question_flagged($slot)) { $flag = html_writer::empty_tag('img', array('src' => $this->pix_url('i/flagged'), 'alt' => get_string('flagged', 'question'), 'class' => 'questionflag')); } if ($attemptobj->can_navigate_to($slot)) { $row = array(html_writer::link($attemptobj->attempt_url($slot), $attemptobj->get_question_number($slot) . $flag), $attemptobj->get_question_status($slot, $displayoptions->correctness)); } else { $row = array($attemptobj->get_question_number($slot) . $flag, $attemptobj->get_question_status($slot, $displayoptions->correctness)); } if ($markscolumn) { $row[] = $attemptobj->get_question_mark($slot); } $table->data[] = $row; $table->rowclasses[] = $attemptobj->get_question_state_class( $slot, $displayoptions->correctness); } // Print the summary table. $output = html_writer::table($table); return $output; }
/** * Get the buttons and section headings to go in the quiz navigation block. * @return renderable[] the buttons, possibly interleaved with section headings. */ public function get_question_buttons() { $buttons = array(); foreach ($this->attemptobj->get_slots() as $slot) { if ($heading = $this->attemptobj->get_heading_before_slot($slot)) { $buttons[] = new quiz_nav_section_heading(format_string($heading)); } $qa = $this->attemptobj->get_question_attempt($slot); $showcorrectness = $this->options->correctness && $qa->has_marks(); $button = new quiz_nav_question_button(); $button->id = 'quiznavbutton' . $slot; $button->number = $this->attemptobj->get_question_number($slot); $button->stateclass = $qa->get_state_class($showcorrectness); $button->navmethod = $this->attemptobj->get_navigation_method(); if (!$showcorrectness && $button->stateclass == 'notanswered') { $button->stateclass = 'complete'; } $button->statestring = $this->get_state_string($qa, $showcorrectness); $button->page = $this->attemptobj->get_question_page($slot); $button->currentpage = $this->showall || $button->page == $this->page; $button->flagged = $qa->is_flagged(); $button->url = $this->get_question_url($slot); if ($this->attemptobj->is_blocked_by_previous_question($slot)) { $button->url = null; $button->stateclass = 'blocked'; $button->statestring = get_string('questiondependsonprevious', 'quiz'); } $buttons[] = $button; } return $buttons; }
/** * Generates the table of summarydata * * @param quiz_attempt $attemptobj * @param mod_quiz_display_options $displayoptions */ public function summary_table($attemptobj, $displayoptions) { // Prepare the summary table header. $table = new html_table(); $table->attributes['class'] = 'generaltable quizsummaryofattempt boxaligncenter'; $table->head = array(get_string('question', 'quiz'), get_string('status', 'quiz')); $table->align = array('left', 'left'); $table->size = array('', ''); $markscolumn = $displayoptions->marks >= question_display_options::MARK_AND_MAX; if ($markscolumn) { $table->head[] = get_string('marks', 'quiz'); $table->align[] = 'left'; $table->size[] = ''; } $tablewidth = count($table->align); $table->data = array(); // Get the summary info for each question. $slots = $attemptobj->get_slots(); foreach ($slots as $slot) { // Add a section headings if we need one here. $heading = $attemptobj->get_heading_before_slot($slot); if ($heading) { $cell = new html_table_cell(format_string($heading)); $cell->header = true; $cell->colspan = $tablewidth; $table->data[] = array($cell); } // Don't display information items. if (!$attemptobj->is_real_question($slot)) { continue; } // Real question, show it. $flag = ''; if ($attemptobj->is_question_flagged($slot)) { $flag = html_writer::empty_tag('img', array('src' => $this->pix_url('i/flagged'), 'alt' => get_string('flagged', 'question'), 'class' => 'questionflag icon-post')); } if ($attemptobj->can_navigate_to($slot)) { $row = array(html_writer::link($attemptobj->attempt_url($slot), $attemptobj->get_question_number($slot) . $flag), $attemptobj->get_question_status($slot, $displayoptions->correctness)); } else { $row = array($attemptobj->get_question_number($slot) . $flag, $attemptobj->get_question_status($slot, $displayoptions->correctness)); } if ($markscolumn) { $row[] = $attemptobj->get_question_mark($slot); } $table->data[] = $row; $table->rowclasses[] = 'quizsummary' . $slot . ' ' . $attemptobj->get_question_state_class($slot, $displayoptions->correctness); } // Print the summary table. $output = html_writer::table($table); return $output; }
/** * Return questions information for a given attempt. * * @param quiz_attempt $attemptobj the quiz attempt object * @param bool $review whether if we are in review mode or not * @param mixed $page string 'all' or integer page number * @return array array of questions including data */ private static function get_attempt_questions_data(quiz_attempt $attemptobj, $review, $page = 'all') { global $PAGE; $questions = array(); $contextid = $attemptobj->get_quizobj()->get_context()->id; $displayoptions = $attemptobj->get_display_options($review); $renderer = $PAGE->get_renderer('mod_quiz'); foreach ($attemptobj->get_slots($page) as $slot) { $question = array('slot' => $slot, 'type' => $attemptobj->get_question_type_name($slot), 'page' => $attemptobj->get_question_page($slot), 'flagged' => $attemptobj->is_question_flagged($slot), 'html' => $attemptobj->render_question($slot, $review, $renderer) . $PAGE->requires->get_end_code()); if ($attemptobj->is_real_question($slot)) { $question['number'] = $attemptobj->get_question_number($slot); $question['state'] = (string) $attemptobj->get_question_state($slot); $question['status'] = $attemptobj->get_question_status($slot, $displayoptions->correctness); } if ($displayoptions->marks >= question_display_options::MAX_ONLY) { $question['maxmark'] = $attemptobj->get_question_attempt($slot)->get_max_mark(); } if ($displayoptions->marks >= question_display_options::MARK_AND_MAX) { $question['mark'] = $attemptobj->get_question_mark($slot); } $questions[] = $question; } return $questions; }
public function get_question_buttons() { $buttons = array(); foreach ($this->attemptobj->get_slots() as $slot) { $qa = $this->attemptobj->get_question_attempt($slot); $showcorrectness = $this->options->correctness && $qa->has_marks(); $button = new quiz_nav_question_button(); $button->id = 'quiznavbutton' . $slot; $button->number = $this->attemptobj->get_question_number($slot); $button->stateclass = $qa->get_state_class($showcorrectness); $button->navmethod = $this->attemptobj->get_navigation_method(); if (!$showcorrectness && $button->stateclass == 'notanswered') { $button->stateclass = 'complete'; } $button->statestring = $this->get_state_string($qa, $showcorrectness); $button->currentpage = $this->attemptobj->get_question_page($slot) == $this->page; $button->flagged = $qa->is_flagged(); $button->url = $this->get_question_url($slot); $buttons[] = $button; } return $buttons; }