Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 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    moodlecore
  21   * @subpackage questionbank
  22   * @copyright  2011 The Open University
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  
  30  /**
  31   * This renderer outputs parts of the question bank.
  32   *
  33   * @copyright  2011 The Open University
  34   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  35   */
  36  class core_question_bank_renderer extends plugin_renderer_base {
  37  
  38      /**
  39       * Display additional navigation if needed.
  40       *
  41       * @return string
  42       */
  43      public function extra_horizontal_navigation() {
  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                  $active = $questionnode->find_active_node()->key;
  52                  return \html_writer::div(print_tabs([$tabs], $active, null, null, true), 'questionbank-navigation');
  53              }
  54          }
  55          return '';
  56      }
  57  
  58      /**
  59       * Output the icon for a question type.
  60       *
  61       * @param string $qtype the question type.
  62       * @return string HTML fragment.
  63       */
  64      public function qtype_icon($qtype) {
  65          $qtype = question_bank::get_qtype($qtype, false);
  66          $namestr = $qtype->local_name();
  67  
  68          return $this->image_icon('icon', $namestr, $qtype->plugin_name(), array('title' => $namestr));
  69      }
  70  
  71      /**
  72       * Render a qbank_chooser.
  73       *
  74       * @param renderable $qbankchooser The chooser.
  75       * @return string
  76       */
  77      public function render_qbank_chooser(renderable $qbankchooser) {
  78          return $this->render_from_template('core_question/qbank_chooser', $qbankchooser->export_for_template($this));
  79      }
  80  
  81      /**
  82       * Build the HTML for the question chooser javascript popup.
  83       *
  84       * @param array $real A set of real question types
  85       * @param array $fake A set of fake question types
  86       * @param object $course The course that will be displayed
  87       * @param array $hiddenparams Any hidden parameters to add to the form
  88       * @return string The composed HTML for the questionbank chooser
  89       */
  90      public function qbank_chooser($real, $fake, $course, $hiddenparams) {
  91          debugging('Method core_question_bank_renderer::qbank_chooser() is deprecated, ' .
  92              'see core_question_bank_renderer::render_qbank_chooser().', DEBUG_DEVELOPER);
  93          return '';
  94      }
  95  
  96      /**
  97       * Build the HTML for a specified set of question types.
  98       *
  99       * @param array $types A set of question types as used by the qbank_chooser_module function
 100       * @return string The composed HTML for the module
 101       */
 102      protected function qbank_chooser_types($types) {
 103          debugging('Method core_question_bank_renderer::qbank_chooser_types() is deprecated, ' .
 104              'see core_question_bank_renderer::render_qbank_chooser().', DEBUG_DEVELOPER);
 105          return '';
 106      }
 107  
 108      /**
 109       * Return the HTML for the specified question type, adding any required classes.
 110       *
 111       * @param object $qtype An object containing the title, and link. An icon, and help text may optionally be specified.
 112       * If the module contains subtypes in the types option, then these will also be displayed.
 113       * @param array $classes Additional classes to add to the encompassing div element
 114       * @return string The composed HTML for the question type
 115       */
 116      protected function qbank_chooser_qtype($qtype, $classes = array()) {
 117          debugging('Method core_question_bank_renderer::qbank_chooser_qtype() is deprecated, ' .
 118              'see core_question_bank_renderer::render_qbank_chooser().', DEBUG_DEVELOPER);
 119          return '';
 120      }
 121  
 122      /**
 123       * Return the title for the question bank chooser.
 124       *
 125       * @param string $title The language string identifier
 126       * @param string $identifier The component identifier
 127       * @return string The composed HTML for the title
 128       */
 129      protected function qbank_chooser_title($title, $identifier = null) {
 130          debugging('Method core_question_bank_renderer::qbank_chooser_title() is deprecated, ' .
 131              'see core_question_bank_renderer::render_qbank_chooser().', DEBUG_DEVELOPER);
 132          return '';
 133      }
 134  }