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 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  namespace core_question\output;
  18  
  19  use moodle_url;
  20  use renderer_base;
  21  use templatable;
  22  use renderable;
  23  use url_select;
  24  
  25  /**
  26   * Rendered HTML elements for tertiary nav for Question bank.
  27   *
  28   * Provides the links for question bank tertiary navigation, below
  29   * are the links provided for the urlselector:
  30   * Questions, Categories, Import and Export
  31   * Also "Add category" button is added to tertiary nav for the categories.
  32   * The "Add category" would take the user to separate page, add category page.
  33   *
  34   * @package   core_question
  35   * @copyright 2021 Sujith Haridasan <sujith@moodle.com>
  36   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  37   */
  38  class qbank_action_menu implements templatable, renderable {
  39      /** @var moodle_url */
  40      private $currenturl;
  41  
  42      /**
  43       * qbank_actionbar constructor.
  44       *
  45       * @param moodle_url $currenturl The current URL.
  46       */
  47      public function __construct(moodle_url $currenturl) {
  48          $this->currenturl = $currenturl;
  49      }
  50  
  51      /**
  52       * Provides the data for the template.
  53       *
  54       * @param renderer_base $output renderer_base object.
  55       * @return array data for the template
  56       */
  57      public function export_for_template(renderer_base $output): array {
  58          $questionslink = new moodle_url('/question/edit.php', $this->currenturl->params());
  59          if (\core\plugininfo\qbank::is_plugin_enabled("qbank_managecategories")) {
  60              $categorylink = new moodle_url('/question/bank/managecategories/category.php', $this->currenturl->params());
  61          }
  62          $importlink = new moodle_url('/question/bank/importquestions/import.php', $this->currenturl->params());
  63          $exportlink = new moodle_url('/question/bank/exportquestions/export.php', $this->currenturl->params());
  64  
  65          $menu = [
  66              $questionslink->out(false) => get_string('questions', 'question'),
  67          ];
  68  
  69          if (\core\plugininfo\qbank::is_plugin_enabled("qbank_managecategories")) {
  70              $menu[$categorylink->out(false)] = get_string('categories', 'question');
  71          }
  72          $menu[$importlink->out(false)] = get_string('import', 'question');
  73          $menu[$exportlink->out(false)] = get_string('export', 'question');
  74  
  75          $addcategory = null;
  76          if (strpos($this->currenturl->get_path(), 'category.php') !== false &&
  77                  $this->currenturl->param('edit') === null) {
  78              $addcategory = $this->currenturl->out(false, ['edit' => 0]);
  79          }
  80  
  81          $urlselect = new url_select($menu, $this->currenturl->out(false), null, 'questionbankaction');
  82          $urlselect->set_label(get_string('questionbanknavigation', 'question'), ['class' => 'accesshide']);
  83  
  84          return [
  85              'questionbankselect' => $urlselect->export_for_template($output),
  86              'addcategory' => $addcategory
  87          ];
  88      }
  89  }