Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 310 and 400] [Versions 311 and 400] [Versions 39 and 400] [Versions 400 and 402] [Versions 400 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   * Defines the renderer for the quiz_grading module.
  19   *
  20   * @package   quiz_grading
  21   * @copyright 2018 Huong Nguyen <huongnv13@gmail.com>
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  /**
  26   * The renderer for the quiz_grading module.
  27   *
  28   * @copyright  2018 Huong Nguyen <huongnv13@gmail.com>
  29   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  30   */
  31  class quiz_grading_renderer extends plugin_renderer_base {
  32  
  33      /**
  34       * Render no question notification.
  35       *
  36       * @param object $quiz The quiz settings.
  37       * @param object $cm The course-module for this quiz.
  38       * @param object $context The quiz context.
  39       * @return string The HTML for the no questions message.
  40       */
  41      public function render_quiz_no_question_notification($quiz, $cm, $context) {
  42          return quiz_no_questions_message($quiz, $cm, $context);
  43      }
  44  
  45      /**
  46       * Render no question need to grade notification.
  47       *
  48       * @throws coding_exception
  49       */
  50      public function render_quiz_no_grade_question_notification() {
  51          return $this->notification(get_string('nothingfound', 'quiz_grading'));
  52      }
  53  
  54      /**
  55       * Render index display.
  56       *
  57       * @param string $linktext The text of the link.
  58       * @param moodle_url $listquestionurl Url of the page that list all questions.
  59       * @return string The HTML for the display heading.
  60       * @throws coding_exception
  61       */
  62      public function render_display_index_heading($linktext, $listquestionurl) {
  63          $output = '';
  64  
  65          $output .= $this->heading(get_string('questionsthatneedgrading', 'quiz_grading'), 3);
  66          $output .= html_writer::tag('p', html_writer::link($listquestionurl, $linktext), ['class' => 'toggleincludeauto']);
  67  
  68          return $output;
  69      }
  70  
  71      /**
  72       * Render questions list table.
  73       *
  74       * @param bool $includeauto True to show automatically graded questions.
  75       * @param array $data List of questions.
  76       * @param array $header List of table headers.
  77       * @return string The HTML for the question table.
  78       * @throws coding_exception
  79       */
  80      public function render_questions_table($includeauto, $data, $header) {
  81          if (empty($data)) {
  82              return $this->render_quiz_no_grade_question_notification();
  83          }
  84          $output = '';
  85  
  86          $table = new html_table();
  87          $table->class = 'generaltable';
  88          $table->id = 'questionstograde';
  89          $table->head = $header;
  90          $table->data = $data;
  91  
  92          $output .= html_writer::table($table);
  93  
  94          return $output;
  95      }
  96  
  97      /**
  98       * Render grade link for question.
  99       *
 100       * @param object $counts
 101       * @param string $type Type of grade.
 102       * @param string $gradestring Lang string.
 103       * @param moodle_url $gradequestionurl Url to grade question.
 104       * @return string The HTML for the question grade link.
 105       * @throws coding_exception
 106       */
 107      public function render_grade_link($counts, $type, $gradestring, $gradequestionurl) {
 108          $output = '';
 109          if ($counts->$type > 0) {
 110              $output .= ' ' . html_writer::link(
 111                              $gradequestionurl,
 112                              get_string($gradestring, 'quiz_grading'),
 113                              ['class' => 'gradetheselink']);
 114          }
 115          return $output;
 116      }
 117  
 118      /**
 119       * Render grading page.
 120       *
 121       * @param object $questioninfo Information of a question.
 122       * @param moodle_url $listquestionsurl Url of the page that list all questions.
 123       * @param quiz_grading_settings_form $filterform Question filter form.
 124       * @param object $paginginfo Pagination information.
 125       * @param object $pagingbar Pagination bar information.
 126       * @param moodle_url $formaction Form submit url.
 127       * @param array $hiddeninputs List of hidden input fields.
 128       * @param string $gradequestioncontent HTML string of question content.
 129       * @return string The HTML for the grading interface.
 130       * @throws coding_exception
 131       * @throws moodle_exception
 132       */
 133      public function render_grading_interface($questioninfo, $listquestionsurl, $filterform, $paginginfo, $pagingbar, $formaction,
 134              $hiddeninputs, $gradequestioncontent) {
 135          $output = '';
 136  
 137          $output .= question_engine::initialise_js();
 138  
 139          $output .= $this->heading(get_string('gradingquestionx', 'quiz_grading', $questioninfo), 3);
 140  
 141          $output .= html_writer::tag('p', html_writer::link($listquestionsurl,
 142                  get_string('backtothelistofquestions', 'quiz_grading')),
 143                  ['class' => 'mdl-align']);
 144  
 145          $output .= $filterform->render();
 146  
 147          $output .= $this->heading(get_string('gradingattemptsxtoyofz', 'quiz_grading', $paginginfo), 3);
 148  
 149          $output .= $this->render_paging_bar($pagingbar);
 150  
 151          $output .= html_writer::start_tag('form', [
 152                  'method' => 'post',
 153                  'action' => $formaction,
 154                  'class' => 'mform',
 155                  'id' => 'manualgradingform'
 156          ]);
 157          $output .= html_writer::start_tag('div');
 158          $output .= html_writer::input_hidden_params(new moodle_url('', $hiddeninputs));
 159  
 160          $output .= $gradequestioncontent;
 161  
 162          $output .= html_writer::tag('div', html_writer::empty_tag('input', [
 163                  'type' => 'submit',
 164                  'class' => 'btn btn-primary',
 165                  'value' => get_string('saveandnext', 'quiz_grading')
 166          ]), ['class' => 'mdl-align']);
 167          $output .= html_writer::end_tag('div') . html_writer::end_tag('form');
 168  
 169          $output .= $this->render_paging_bar($pagingbar);
 170  
 171          // Add the form change checker.
 172          $this->page->requires->js_call_amd('core_form/changechecker', 'watchFormById', ['manualgradingform']);
 173  
 174          return $output;
 175      }
 176  
 177      /**
 178       * Render grade question content.
 179       *
 180       * @param question_usage_by_activity $questionusage The question usage that need to grade.
 181       * @param int $slot the number used to identify this question within this usage.
 182       * @param question_display_options $displayoptions the display options to use.
 183       * @param int $questionnumber the number of the question to check.
 184       * @param string $heading the question heading text.
 185       * @return string The HTML for the question display.
 186       */
 187      public function render_grade_question($questionusage, $slot, $displayoptions, $questionnumber, $heading) {
 188          $output = '';
 189  
 190          if ($heading) {
 191              $output .= $this->heading($heading, 4);
 192          }
 193  
 194          $output .= $questionusage->render_question($slot, $displayoptions, $questionnumber);
 195  
 196          return $output;
 197      }
 198  
 199      /**
 200       * Render paging bar.
 201       *
 202       * @param object $pagingbar Pagination bar information.
 203       * @return string The HTML for the question display.
 204       */
 205      public function render_paging_bar(object $pagingbar): string {
 206          if ($pagingbar->count > $pagingbar->pagesize && $pagingbar->order != 'random') {
 207              return $this->paging_bar($pagingbar->count, $pagingbar->page, $pagingbar->pagesize, $pagingbar->pagingurl);
 208          }
 209          return '';
 210      }
 211  }