Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402] [Versions 402 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   * Renderers for outputting parts of the question bank.
  19   *
  20   * @package    core_question
  21   * @copyright  2011 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  
  29  /**
  30   * This renderer outputs parts of the question bank.
  31   *
  32   * @copyright  2011 The Open University
  33   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  34   */
  35  class core_question_bank_renderer extends plugin_renderer_base {
  36  
  37      /**
  38       * Display additional navigation if needed.
  39       *
  40       * @param string $active
  41       * @return string
  42       */
  43      public function extra_horizontal_navigation($active = null) {
  44          // Horizontal navigation for question bank.
  45          if ($questionnode = $this->page->settingsnav->find("questionbank", \navigation_node::TYPE_CONTAINER)) {
  46              if ($children = $questionnode->children) {
  47                  $tabs = [];
  48                  foreach ($children as $key => $node) {
  49                      $tabs[] = new \tabobject($node->key, $node->action, $node->text);
  50                  }
  51                  if (empty($active) && $questionnode->find_active_node()) {
  52                      $active = $questionnode->find_active_node()->key;
  53                  }
  54                  return \html_writer::div(print_tabs([$tabs], $active, null, null, true),
  55                          'questionbank-navigation');
  56              }
  57          }
  58          return '';
  59      }
  60  
  61      /**
  62       * Output the icon for a question type.
  63       *
  64       * @param string $qtype the question type.
  65       * @return string HTML fragment.
  66       */
  67      public function qtype_icon($qtype) {
  68          $qtype = question_bank::get_qtype($qtype, false);
  69          $namestr = $qtype->local_name();
  70  
  71          return $this->image_icon('icon', $namestr, $qtype->plugin_name(), array('title' => $namestr));
  72      }
  73  
  74      /**
  75       * Render the column headers.
  76       *
  77       * @param array $qbankheaderdata
  78       * @return bool|string
  79       */
  80      public function render_column_header($qbankheaderdata) {
  81          return $this->render_from_template('core_question/column_header', $qbankheaderdata);
  82      }
  83  
  84      /**
  85       * Render the column sort elements.
  86       *
  87       * @param array $sortdata
  88       * @return bool|string
  89       */
  90      public function render_column_sort($sortdata) {
  91          return $this->render_from_template('core_question/column_sort', $sortdata);
  92      }
  93  
  94      /**
  95       * Render a qbank_chooser.
  96       *
  97       * @param renderable $qbankchooser The chooser.
  98       * @return string
  99       * @deprecated since Moodle 4.0
 100       * @see \qbank_editquestion\output\renderer
 101       * @todo Final deprecation on Moodle 4.4 MDL-72438
 102       */
 103      public function render_qbank_chooser(renderable $qbankchooser) {
 104          debugging('Function render_qbank_chooser is deprecated,
 105           please use qbank_editquestion renderer instead.', DEBUG_DEVELOPER);
 106          return $this->render_from_template('core_question/qbank_chooser', $qbankchooser->export_for_template($this));
 107      }
 108  
 109      /**
 110       * Render category condition.
 111       *
 112       * @param array $displaydata
 113       * @return bool|string
 114       */
 115      public function render_category_condition($displaydata) {
 116          return $this->render_from_template('core_question/category_condition', $displaydata);
 117      }
 118  
 119      /**
 120       * Render category condition advanced.
 121       *
 122       * @param array $displaydata
 123       * @return bool|string
 124       */
 125      public function render_category_condition_advanced($displaydata) {
 126          return $this->render_from_template('core_question/category_condition_advanced', $displaydata);
 127      }
 128  
 129      /**
 130       * Render hidden condition advanced.
 131       *
 132       * @param array $displaydata
 133       * @return bool|string
 134       */
 135      public function render_hidden_condition_advanced($displaydata) {
 136          return $this->render_from_template('core_question/hidden_condition_advanced', $displaydata);
 137      }
 138  
 139      /**
 140       * Render question pagination.
 141       *
 142       * @param array $displaydata
 143       * @return bool|string
 144       */
 145      public function render_question_pagination($displaydata) {
 146          return $this->render_from_template('core_question/question_pagination', $displaydata);
 147      }
 148  
 149      /**
 150       * Render the showtext option.
 151       *
 152       * It's not a checkbox any more! [Name your API after the purpose, not the implementation!]
 153       *
 154       * @param array $displaydata
 155       * @return string
 156       */
 157      public function render_showtext_checkbox($displaydata) {
 158          return $this->render_from_template('core_question/showtext_option',
 159                  ['selected' . $displaydata['checked'] => true]);
 160      }
 161  
 162      /**
 163       * Render bulk actions ui.
 164       *
 165       * @param array $displaydata
 166       * @return bool|string
 167       */
 168      public function render_bulk_actions_ui($displaydata) {
 169          return $this->render_from_template('core_question/bulk_actions_ui', $displaydata);
 170      }
 171  
 172      /**
 173       * Build the HTML for the question chooser javascript popup.
 174       *
 175       * @param array $real A set of real question types
 176       * @param array $fake A set of fake question types
 177       * @param object $course The course that will be displayed
 178       * @param array $hiddenparams Any hidden parameters to add to the form
 179       * @return string The composed HTML for the questionbank chooser
 180       * @todo Final deprecation on Moodle 4.4 MDL-72438
 181       */
 182      public function qbank_chooser($real, $fake, $course, $hiddenparams) {
 183          debugging('Method core_question_bank_renderer::qbank_chooser() is deprecated, ' .
 184                  'see core_question_bank_renderer::render_qbank_chooser().', DEBUG_DEVELOPER);
 185          return '';
 186      }
 187  
 188      /**
 189       * Build the HTML for a specified set of question types.
 190       *
 191       * @param array $types A set of question types as used by the qbank_chooser_module function
 192       * @return string The composed HTML for the module
 193       * @todo Final deprecation on Moodle 4.4 MDL-72438
 194       */
 195      protected function qbank_chooser_types($types) {
 196          debugging('Method core_question_bank_renderer::qbank_chooser_types() is deprecated, ' .
 197                  'see core_question_bank_renderer::render_qbank_chooser().', DEBUG_DEVELOPER);
 198          return '';
 199      }
 200  
 201      /**
 202       * Return the HTML for the specified question type, adding any required classes.
 203       *
 204       * @param object $qtype An object containing the title, and link. An icon, and help text may optionally be specified.
 205       * If the module contains subtypes in the types option, then these will also be displayed.
 206       * @param array $classes Additional classes to add to the encompassing div element
 207       * @return string The composed HTML for the question type
 208       * @todo Final deprecation on Moodle 4.4 MDL-72438
 209       */
 210      protected function qbank_chooser_qtype($qtype, $classes = array()) {
 211          debugging('Method core_question_bank_renderer::qbank_chooser_qtype() is deprecated, ' .
 212                  'see core_question_bank_renderer::render_qbank_chooser().', DEBUG_DEVELOPER);
 213          return '';
 214      }
 215  
 216      /**
 217       * Return the title for the question bank chooser.
 218       *
 219       * @param string $title The language string identifier
 220       * @param string $identifier The component identifier
 221       * @return string The composed HTML for the title
 222       * @todo Final deprecation on Moodle 4.4 MDL-72438
 223       */
 224      protected function qbank_chooser_title($title, $identifier = null) {
 225          debugging('Method core_question_bank_renderer::qbank_chooser_title() is deprecated, ' .
 226                  'see core_question_bank_renderer::render_qbank_chooser().', DEBUG_DEVELOPER);
 227          return '';
 228      }
 229  
 230  }