Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

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