Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]

   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   * Base class for the table used by a {@link quiz_attempts_report}.
  19   *
  20   * @package   mod_quiz
  21   * @copyright 2010 The Open University
  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->libdir.'/tablelib.php');
  29  
  30  
  31  /**
  32   * Base class for the table used by a {@link quiz_attempts_report}.
  33   *
  34   * @copyright 2010 The Open University
  35   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  36   */
  37  abstract class quiz_attempts_report_table extends table_sql {
  38      public $useridfield = 'userid';
  39  
  40      /** @var moodle_url the URL of this report. */
  41      protected $reporturl;
  42  
  43      /** @var array the display options. */
  44      protected $displayoptions;
  45  
  46      /**
  47       * @var array information about the latest step of each question.
  48       * Loaded by {@link load_question_latest_steps()}, if applicable.
  49       */
  50      protected $lateststeps = null;
  51  
  52      /** @var object the quiz settings for the quiz we are reporting on. */
  53      protected $quiz;
  54  
  55      /** @var context the quiz context. */
  56      protected $context;
  57  
  58      /** @var string HTML fragment to select the first/best/last attempt, if appropriate. */
  59      protected $qmsubselect;
  60  
  61      /** @var object mod_quiz_attempts_report_options the options affecting this report. */
  62      protected $options;
  63  
  64      /** @var \core\dml\sql_join Contains joins, wheres, params to find students
  65       * in the currently selected group, if applicable.
  66       */
  67      protected $groupstudentsjoins;
  68  
  69      /** @var \core\dml\sql_join Contains joins, wheres, params to find the students in the course. */
  70      protected $studentsjoins;
  71  
  72      /** @var object the questions that comprise this quiz.. */
  73      protected $questions;
  74  
  75      /** @var bool whether to include the column with checkboxes to select each attempt. */
  76      protected $includecheckboxes;
  77  
  78      /** @var string The toggle group name for the checkboxes in the checkbox column. */
  79      protected $togglegroup = 'quiz-attempts';
  80  
  81      /**
  82       * Constructor
  83       * @param string $uniqueid
  84       * @param object $quiz
  85       * @param context $context
  86       * @param string $qmsubselect
  87       * @param mod_quiz_attempts_report_options $options
  88       * @param \core\dml\sql_join $groupstudentsjoins Contains joins, wheres, params
  89       * @param \core\dml\sql_join $studentsjoins Contains joins, wheres, params
  90       * @param array $questions
  91       * @param moodle_url $reporturl
  92       */
  93      public function __construct($uniqueid, $quiz, $context, $qmsubselect,
  94              mod_quiz_attempts_report_options $options, \core\dml\sql_join $groupstudentsjoins, \core\dml\sql_join $studentsjoins,
  95              $questions, $reporturl) {
  96          parent::__construct($uniqueid);
  97          $this->quiz = $quiz;
  98          $this->context = $context;
  99          $this->qmsubselect = $qmsubselect;
 100          $this->groupstudentsjoins = $groupstudentsjoins;
 101          $this->studentsjoins = $studentsjoins;
 102          $this->questions = $questions;
 103          $this->includecheckboxes = $options->checkboxcolumn;
 104          $this->reporturl = $reporturl;
 105          $this->options = $options;
 106      }
 107  
 108      /**
 109       * Generate the display of the checkbox column.
 110       * @param object $attempt the table row being output.
 111       * @return string HTML content to go inside the td.
 112       */
 113      public function col_checkbox($attempt) {
 114          global $OUTPUT;
 115  
 116          if ($attempt->attempt) {
 117              $checkbox = new \core\output\checkbox_toggleall($this->togglegroup, false, [
 118                  'id' => "attemptid_{$attempt->attempt}",
 119                  'name' => 'attemptid[]',
 120                  'value' => $attempt->attempt,
 121                  'label' => get_string('selectattempt', 'quiz'),
 122                  'labelclasses' => 'accesshide',
 123              ]);
 124              return $OUTPUT->render($checkbox);
 125          } else {
 126              return '';
 127          }
 128      }
 129  
 130      /**
 131       * Generate the display of the user's picture column.
 132       * @param object $attempt the table row being output.
 133       * @return string HTML content to go inside the td.
 134       */
 135      public function col_picture($attempt) {
 136          global $OUTPUT;
 137          $user = new stdClass();
 138          $additionalfields = explode(',', user_picture::fields());
 139          $user = username_load_fields_from_object($user, $attempt, null, $additionalfields);
 140          $user->id = $attempt->userid;
 141          return $OUTPUT->user_picture($user);
 142      }
 143  
 144      /**
 145       * Generate the display of the user's full name column.
 146       * @param object $attempt the table row being output.
 147       * @return string HTML content to go inside the td.
 148       */
 149      public function col_fullname($attempt) {
 150          $html = parent::col_fullname($attempt);
 151          if ($this->is_downloading() || empty($attempt->attempt)) {
 152              return $html;
 153          }
 154  
 155          return $html . html_writer::empty_tag('br') . html_writer::link(
 156                  new moodle_url('/mod/quiz/review.php', array('attempt' => $attempt->attempt)),
 157                  get_string('reviewattempt', 'quiz'), array('class' => 'reviewlink'));
 158      }
 159  
 160      /**
 161       * Generate the display of the attempt state column.
 162       * @param object $attempt the table row being output.
 163       * @return string HTML content to go inside the td.
 164       */
 165      public function col_state($attempt) {
 166          if (!is_null($attempt->attempt)) {
 167              return quiz_attempt::state_name($attempt->state);
 168          } else {
 169              return  '-';
 170          }
 171      }
 172  
 173      /**
 174       * Generate the display of the start time column.
 175       * @param object $attempt the table row being output.
 176       * @return string HTML content to go inside the td.
 177       */
 178      public function col_timestart($attempt) {
 179          if ($attempt->attempt) {
 180              return userdate($attempt->timestart, $this->strtimeformat);
 181          } else {
 182              return  '-';
 183          }
 184      }
 185  
 186      /**
 187       * Generate the display of the finish time column.
 188       * @param object $attempt the table row being output.
 189       * @return string HTML content to go inside the td.
 190       */
 191      public function col_timefinish($attempt) {
 192          if ($attempt->attempt && $attempt->timefinish) {
 193              return userdate($attempt->timefinish, $this->strtimeformat);
 194          } else {
 195              return  '-';
 196          }
 197      }
 198  
 199      /**
 200       * Generate the display of the time taken column.
 201       * @param object $attempt the table row being output.
 202       * @return string HTML content to go inside the td.
 203       */
 204      public function col_duration($attempt) {
 205          if ($attempt->timefinish) {
 206              return format_time($attempt->timefinish - $attempt->timestart);
 207          } else {
 208              return '-';
 209          }
 210      }
 211  
 212      /**
 213       * Generate the display of the feedback column.
 214       * @param object $attempt the table row being output.
 215       * @return string HTML content to go inside the td.
 216       */
 217      public function col_feedbacktext($attempt) {
 218          if ($attempt->state != quiz_attempt::FINISHED) {
 219              return '-';
 220          }
 221  
 222          $feedback = quiz_report_feedback_for_grade(
 223                  quiz_rescale_grade($attempt->sumgrades, $this->quiz, false),
 224                  $this->quiz->id, $this->context);
 225  
 226          if ($this->is_downloading()) {
 227              $feedback = strip_tags($feedback);
 228          }
 229  
 230          return $feedback;
 231      }
 232  
 233      public function get_row_class($attempt) {
 234          if ($this->qmsubselect && $attempt->gradedattempt) {
 235              return 'gradedattempt';
 236          } else {
 237              return '';
 238          }
 239      }
 240  
 241      /**
 242       * Make a link to review an individual question in a popup window.
 243       *
 244       * @param string $data HTML fragment. The text to make into the link.
 245       * @param object $attempt data for the row of the table being output.
 246       * @param int $slot the number used to identify this question within this usage.
 247       */
 248      public function make_review_link($data, $attempt, $slot) {
 249          global $OUTPUT;
 250  
 251          $flag = '';
 252          if ($this->is_flagged($attempt->usageid, $slot)) {
 253              $flag = $OUTPUT->pix_icon('i/flagged', get_string('flagged', 'question'),
 254                      'moodle', array('class' => 'questionflag'));
 255          }
 256  
 257          $feedbackimg = '';
 258          $state = $this->slot_state($attempt, $slot);
 259          if ($state->is_finished() && $state != question_state::$needsgrading) {
 260              $feedbackimg = $this->icon_for_fraction($this->slot_fraction($attempt, $slot));
 261          }
 262  
 263          $output = html_writer::tag('span', $feedbackimg . html_writer::tag('span',
 264                  $data, array('class' => $state->get_state_class(true))) . $flag, array('class' => 'que'));
 265  
 266          $reviewparams = array('attempt' => $attempt->attempt, 'slot' => $slot);
 267          if (isset($attempt->try)) {
 268              $reviewparams['step'] = $this->step_no_for_try($attempt->usageid, $slot, $attempt->try);
 269          }
 270          $url = new moodle_url('/mod/quiz/reviewquestion.php', $reviewparams);
 271          $output = $OUTPUT->action_link($url, $output,
 272                  new popup_action('click', $url, 'reviewquestion',
 273                          array('height' => 450, 'width' => 650)),
 274                  array('title' => get_string('reviewresponse', 'quiz')));
 275  
 276          return $output;
 277      }
 278  
 279      /**
 280       * @param object $attempt the row data
 281       * @param int $slot
 282       * @return question_state
 283       */
 284      protected function slot_state($attempt, $slot) {
 285          $stepdata = $this->lateststeps[$attempt->usageid][$slot];
 286          return question_state::get($stepdata->state);
 287      }
 288  
 289      /**
 290       * @param int $questionusageid
 291       * @param int $slot
 292       * @return bool
 293       */
 294      protected function is_flagged($questionusageid, $slot) {
 295          $stepdata = $this->lateststeps[$questionusageid][$slot];
 296          return $stepdata->flagged;
 297      }
 298  
 299  
 300      /**
 301       * @param object $attempt the row data
 302       * @param int $slot
 303       * @return float
 304       */
 305      protected function slot_fraction($attempt, $slot) {
 306          $stepdata = $this->lateststeps[$attempt->usageid][$slot];
 307          return $stepdata->fraction;
 308      }
 309  
 310      /**
 311       * Return an appropriate icon (green tick, red cross, etc.) for a grade.
 312       * @param float $fraction grade on a scale 0..1.
 313       * @return string html fragment.
 314       */
 315      protected function icon_for_fraction($fraction) {
 316          global $OUTPUT;
 317  
 318          $feedbackclass = question_state::graded_state_for_fraction($fraction)->get_feedback_class();
 319          return $OUTPUT->pix_icon('i/grade_' . $feedbackclass, get_string($feedbackclass, 'question'),
 320                  'moodle', array('class' => 'icon'));
 321      }
 322  
 323      /**
 324       * Load any extra data after main query. At this point you can call {@link get_qubaids_condition} to get the condition that
 325       * limits the query to just the question usages shown in this report page or alternatively for all attempts if downloading a
 326       * full report.
 327       */
 328      protected function load_extra_data() {
 329          $this->lateststeps = $this->load_question_latest_steps();
 330      }
 331  
 332      /**
 333       * Load information about the latest state of selected questions in selected attempts.
 334       *
 335       * The results are returned as an two dimensional array $qubaid => $slot => $dataobject
 336       *
 337       * @param qubaid_condition|null $qubaids used to restrict which usages are included
 338       * in the query. See {@link qubaid_condition}.
 339       * @return array of records. See the SQL in this function to see the fields available.
 340       */
 341      protected function load_question_latest_steps(qubaid_condition $qubaids = null) {
 342          if ($qubaids === null) {
 343              $qubaids = $this->get_qubaids_condition();
 344          }
 345          $dm = new question_engine_data_mapper();
 346          $latesstepdata = $dm->load_questions_usages_latest_steps(
 347                  $qubaids, array_keys($this->questions));
 348  
 349          $lateststeps = array();
 350          foreach ($latesstepdata as $step) {
 351              $lateststeps[$step->questionusageid][$step->slot] = $step;
 352          }
 353  
 354          return $lateststeps;
 355      }
 356  
 357      /**
 358       * Does this report require loading any more data after the main query. After the main query then
 359       * you can use $this->get
 360       *
 361       * @return bool should {@link query_db()} call {@link load_extra_data}?
 362       */
 363      protected function requires_extra_data() {
 364          return $this->requires_latest_steps_loaded();
 365      }
 366  
 367      /**
 368       * Does this report require the detailed information for each question from the
 369       * question_attempts_steps table?
 370       * @return bool should {@link load_extra_data} call {@link load_question_latest_steps}?
 371       */
 372      protected function requires_latest_steps_loaded() {
 373          return false;
 374      }
 375  
 376      /**
 377       * Is this a column that depends on joining to the latest state information?
 378       * If so, return the corresponding slot. If not, return false.
 379       * @param string $column a column name
 380       * @return int false if no, else a slot.
 381       */
 382      protected function is_latest_step_column($column) {
 383          return false;
 384      }
 385  
 386      /**
 387       * Get any fields that might be needed when sorting on date for a particular slot.
 388       *
 389       * Note: these values are only used for sorting. The values displayed are taken
 390       * from $this->lateststeps loaded in load_extra_data().
 391       *
 392       * @param int $slot the slot for the column we want.
 393       * @param string $alias the table alias for latest state information relating to that slot.
 394       * @return string definitions of extra fields to add to the SELECT list of the query.
 395       */
 396      protected function get_required_latest_state_fields($slot, $alias) {
 397          return '';
 398      }
 399  
 400      /**
 401       * Contruct all the parts of the main database query.
 402       * @param \core\dml\sql_join $allowedstudentsjoins (joins, wheres, params) defines allowed users for the report.
 403       * @return array with 4 elements ($fields, $from, $where, $params) that can be used to
 404       *     build the actual database query.
 405       */
 406      public function base_sql(\core\dml\sql_join $allowedstudentsjoins) {
 407          global $DB;
 408  
 409          // Please note this uniqueid column is not the same as quiza.uniqueid.
 410          $fields = 'DISTINCT ' . $DB->sql_concat('u.id', "'#'", 'COALESCE(quiza.attempt, 0)') . ' AS uniqueid,';
 411  
 412          if ($this->qmsubselect) {
 413              $fields .= "\n(CASE WHEN $this->qmsubselect THEN 1 ELSE 0 END) AS gradedattempt,";
 414          }
 415  
 416          $extrafields = get_extra_user_fields_sql($this->context, 'u', '',
 417                  array('id', 'idnumber', 'firstname', 'lastname', 'picture',
 418                  'imagealt', 'institution', 'department', 'email'));
 419          $allnames = get_all_user_name_fields(true, 'u');
 420          $fields .= '
 421                  quiza.uniqueid AS usageid,
 422                  quiza.id AS attempt,
 423                  u.id AS userid,
 424                  u.idnumber, ' . $allnames . ',
 425                  u.picture,
 426                  u.imagealt,
 427                  u.institution,
 428                  u.department,
 429                  u.email' . $extrafields . ',
 430                  quiza.state,
 431                  quiza.sumgrades,
 432                  quiza.timefinish,
 433                  quiza.timestart,
 434                  CASE WHEN quiza.timefinish = 0 THEN null
 435                       WHEN quiza.timefinish > quiza.timestart THEN quiza.timefinish - quiza.timestart
 436                       ELSE 0 END AS duration';
 437              // To explain that last bit, timefinish can be non-zero and less
 438              // than timestart when you have two load-balanced servers with very
 439              // badly synchronised clocks, and a student does a really quick attempt.
 440  
 441          // This part is the same for all cases. Join the users and quiz_attempts tables.
 442          $from = " {user} u";
 443          $from .= "\nLEFT JOIN {quiz_attempts} quiza ON
 444                                      quiza.userid = u.id AND quiza.quiz = :quizid";
 445          $params = array('quizid' => $this->quiz->id);
 446  
 447          if ($this->qmsubselect && $this->options->onlygraded) {
 448              $from .= " AND (quiza.state <> :finishedstate OR $this->qmsubselect)";
 449              $params['finishedstate'] = quiz_attempt::FINISHED;
 450          }
 451  
 452          switch ($this->options->attempts) {
 453              case quiz_attempts_report::ALL_WITH:
 454                  // Show all attempts, including students who are no longer in the course.
 455                  $where = 'quiza.id IS NOT NULL AND quiza.preview = 0';
 456                  break;
 457              case quiz_attempts_report::ENROLLED_WITH:
 458                  // Show only students with attempts.
 459                  $from .= "\n" . $allowedstudentsjoins->joins;
 460                  $where = "quiza.preview = 0 AND quiza.id IS NOT NULL AND " . $allowedstudentsjoins->wheres;
 461                  $params = array_merge($params, $allowedstudentsjoins->params);
 462                  break;
 463              case quiz_attempts_report::ENROLLED_WITHOUT:
 464                  // Show only students without attempts.
 465                  $from .= "\n" . $allowedstudentsjoins->joins;
 466                  $where = "quiza.id IS NULL AND " . $allowedstudentsjoins->wheres;
 467                  $params = array_merge($params, $allowedstudentsjoins->params);
 468                  break;
 469              case quiz_attempts_report::ENROLLED_ALL:
 470                  // Show all students with or without attempts.
 471                  $from .= "\n" . $allowedstudentsjoins->joins;
 472                  $where = "(quiza.preview = 0 OR quiza.preview IS NULL) AND " . $allowedstudentsjoins->wheres;
 473                  $params = array_merge($params, $allowedstudentsjoins->params);
 474                  break;
 475          }
 476  
 477          if ($this->options->states) {
 478              list($statesql, $stateparams) = $DB->get_in_or_equal($this->options->states,
 479                      SQL_PARAMS_NAMED, 'state');
 480              $params += $stateparams;
 481              $where .= " AND (quiza.state $statesql OR quiza.state IS NULL)";
 482          }
 483  
 484          return array($fields, $from, $where, $params);
 485      }
 486  
 487      /**
 488       * A chance for subclasses to modify the SQL after the count query has been generated,
 489       * and before the full query is constructed.
 490       * @param string $fields SELECT list.
 491       * @param string $from JOINs part of the SQL.
 492       * @param string $where WHERE clauses.
 493       * @param array $params Query params.
 494       * @return array with 4 elements ($fields, $from, $where, $params) as from base_sql.
 495       */
 496      protected function update_sql_after_count($fields, $from, $where, $params) {
 497          return [$fields, $from, $where, $params];
 498      }
 499  
 500      /**
 501       * Set up the SQL queries (count rows, and get data).
 502       *
 503       * @param \core\dml\sql_join $allowedjoins (joins, wheres, params) defines allowed users for the report.
 504       */
 505      public function setup_sql_queries($allowedjoins) {
 506          list($fields, $from, $where, $params) = $this->base_sql($allowedjoins);
 507  
 508          // The WHERE clause is vital here, because some parts of tablelib.php will expect to
 509          // add bits like ' AND x = 1' on the end, and that needs to leave to valid SQL.
 510          $this->set_count_sql("SELECT COUNT(1) FROM (SELECT $fields FROM $from WHERE $where) temp WHERE 1 = 1", $params);
 511  
 512          list($fields, $from, $where, $params) = $this->update_sql_after_count($fields, $from, $where, $params);
 513          $this->set_sql($fields, $from, $where, $params);
 514      }
 515  
 516      /**
 517       * Add the information about the latest state of the question with slot
 518       * $slot to the query.
 519       *
 520       * The extra information is added as a join to a
 521       * 'table' with alias qa$slot, with columns that are a union of
 522       * the columns of the question_attempts and question_attempts_states tables.
 523       *
 524       * @param int $slot the question to add information for.
 525       */
 526      protected function add_latest_state_join($slot) {
 527          $alias = 'qa' . $slot;
 528  
 529          $fields = $this->get_required_latest_state_fields($slot, $alias);
 530          if (!$fields) {
 531              return;
 532          }
 533  
 534          // This condition roughly filters the list of attempts to be considered.
 535          // It is only used in a subselect to help crappy databases (see MDL-30122)
 536          // therefore, it is better to use a very simple join, which may include
 537          // too many records, than to do a super-accurate join.
 538          $qubaids = new qubaid_join("{quiz_attempts} {$alias}quiza", "{$alias}quiza.uniqueid",
 539                  "{$alias}quiza.quiz = :{$alias}quizid", array("{$alias}quizid" => $this->sql->params['quizid']));
 540  
 541          $dm = new question_engine_data_mapper();
 542          list($inlineview, $viewparams) = $dm->question_attempt_latest_state_view($alias, $qubaids);
 543  
 544          $this->sql->fields .= ",\n$fields";
 545          $this->sql->from .= "\nLEFT JOIN $inlineview ON " .
 546                  "$alias.questionusageid = quiza.uniqueid AND $alias.slot = :{$alias}slot";
 547          $this->sql->params[$alias . 'slot'] = $slot;
 548          $this->sql->params = array_merge($this->sql->params, $viewparams);
 549      }
 550  
 551      /**
 552       * Get an appropriate qubaid_condition for loading more data about the
 553       * attempts we are displaying.
 554       * @return qubaid_condition
 555       */
 556      protected function get_qubaids_condition() {
 557          if (is_null($this->rawdata)) {
 558              throw new coding_exception(
 559                      'Cannot call get_qubaids_condition until the main data has been loaded.');
 560          }
 561  
 562          if ($this->is_downloading()) {
 563              // We want usages for all attempts.
 564              return new qubaid_join("(
 565                  SELECT DISTINCT quiza.uniqueid
 566                    FROM " . $this->sql->from . "
 567                   WHERE " . $this->sql->where . "
 568                      ) quizasubquery", 'quizasubquery.uniqueid',
 569                      "1 = 1", $this->sql->params);
 570          }
 571  
 572          $qubaids = array();
 573          foreach ($this->rawdata as $attempt) {
 574              if ($attempt->usageid > 0) {
 575                  $qubaids[] = $attempt->usageid;
 576              }
 577          }
 578  
 579          return new qubaid_list($qubaids);
 580      }
 581  
 582      public function query_db($pagesize, $useinitialsbar = true) {
 583          $doneslots = array();
 584          foreach ($this->get_sort_columns() as $column => $notused) {
 585              $slot = $this->is_latest_step_column($column);
 586              if ($slot && !in_array($slot, $doneslots)) {
 587                  $this->add_latest_state_join($slot);
 588                  $doneslots[] = $slot;
 589              }
 590          }
 591  
 592          parent::query_db($pagesize, $useinitialsbar);
 593  
 594          if ($this->requires_extra_data()) {
 595              $this->load_extra_data();
 596          }
 597      }
 598  
 599      public function get_sort_columns() {
 600          // Add attemptid as a final tie-break to the sort. This ensures that
 601          // Attempts by the same student appear in order when just sorting by name.
 602          $sortcolumns = parent::get_sort_columns();
 603          $sortcolumns['quiza.id'] = SORT_ASC;
 604          return $sortcolumns;
 605      }
 606  
 607      public function wrap_html_start() {
 608          if ($this->is_downloading() || !$this->includecheckboxes) {
 609              return;
 610          }
 611  
 612          $url = $this->options->get_url();
 613          $url->param('sesskey', sesskey());
 614  
 615          echo '<div id="tablecontainer">';
 616          echo '<form id="attemptsform" method="post" action="' . $url->out_omit_querystring() . '">';
 617  
 618          echo html_writer::input_hidden_params($url);
 619          echo '<div>';
 620      }
 621  
 622      public function wrap_html_finish() {
 623          global $PAGE;
 624          if ($this->is_downloading() || !$this->includecheckboxes) {
 625              return;
 626          }
 627  
 628          echo '<div id="commands">';
 629          $this->submit_buttons();
 630          echo '</div>';
 631  
 632          // Close the form.
 633          echo '</div>';
 634          echo '</form></div>';
 635      }
 636  
 637      /**
 638       * Output any submit buttons required by the $this->includecheckboxes form.
 639       */
 640      protected function submit_buttons() {
 641          global $PAGE;
 642          if (has_capability('mod/quiz:deleteattempts', $this->context)) {
 643              $deletebuttonparams = [
 644                  'type'  => 'submit',
 645                  'class' => 'btn btn-secondary mr-1',
 646                  'id'    => 'deleteattemptsbutton',
 647                  'name'  => 'delete',
 648                  'value' => get_string('deleteselected', 'quiz_overview'),
 649                  'data-action' => 'toggle',
 650                  'data-togglegroup' => $this->togglegroup,
 651                  'data-toggle' => 'action',
 652                  'disabled' => true
 653              ];
 654              echo html_writer::empty_tag('input', $deletebuttonparams);
 655              $PAGE->requires->event_handler('#deleteattemptsbutton', 'click', 'M.util.show_confirm_dialog',
 656                      array('message' => get_string('deleteattemptcheck', 'quiz')));
 657          }
 658      }
 659  
 660      /**
 661       * Generates the contents for the checkbox column header.
 662       *
 663       * It returns the HTML for a master \core\output\checkbox_toggleall component that selects/deselects all quiz attempts.
 664       *
 665       * @param string $columnname The name of the checkbox column.
 666       * @return string
 667       */
 668      public function checkbox_col_header(string $columnname) {
 669          global $OUTPUT;
 670  
 671          // Make sure to disable sorting on this column.
 672          $this->no_sorting($columnname);
 673  
 674          // Build the select/deselect all control.
 675          $selectallid = $this->uniqueid . '-selectall-attempts';
 676          $selectalltext = get_string('selectall', 'quiz');
 677          $deselectalltext = get_string('selectnone', 'quiz');
 678          $mastercheckbox = new \core\output\checkbox_toggleall($this->togglegroup, true, [
 679              'id' => $selectallid,
 680              'name' => $selectallid,
 681              'value' => 1,
 682              'label' => $selectalltext,
 683              'labelclasses' => 'accesshide',
 684              'selectall' => $selectalltext,
 685              'deselectall' => $deselectalltext,
 686          ]);
 687  
 688          return $OUTPUT->render($mastercheckbox);
 689      }
 690  }