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.
   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 mod_workshop\output;
  18  
  19  use moodle_url;
  20  use renderer_base;
  21  use url_select;
  22  use renderable;
  23  use templatable;
  24  
  25  /**
  26   * Output the rendered elements for the tertiary nav for page action.
  27   *
  28   * @package   mod_workshop
  29   * @copyright 2021 Sujith Haridasan <sujith@moodle.com>
  30   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  31   */
  32  class actionbar implements renderable, templatable {
  33      /**
  34       * The current url.
  35       *
  36       * @var moodle_url $currenturl
  37       */
  38      private $currenturl;
  39  
  40      /**
  41       * The workshop object.
  42       * @var \workshop $workshop
  43       */
  44      private $workshop;
  45  
  46      /**
  47       * actionbar constructor.
  48       *
  49       * @param moodle_url $currenturl The current URL.
  50       * @param \workshop $workshop The workshop object.
  51       */
  52      public function __construct(moodle_url $currenturl, \workshop $workshop) {
  53          $this->currenturl = $currenturl;
  54          $this->workshop = $workshop;
  55      }
  56  
  57      /**
  58       * Export the data so it can be used as the context for a mustache template.
  59       *
  60       * @param renderer_base $output
  61       * @return array The urlselect menu and the heading to be used
  62       */
  63      public function export_for_template(renderer_base $output): array {
  64          $allocators = \workshop::installed_allocators();
  65          $menu = [];
  66  
  67          foreach (array_keys($allocators) as $methodid) {
  68              $selectorname = get_string('pluginname', 'workshopallocation_' . $methodid);
  69              $menu[$this->workshop->allocation_url($methodid)->out(false)] = $selectorname;
  70          }
  71  
  72          $urlselect = new url_select($menu, $this->currenturl->out(false), null, 'allocationsetting');
  73  
  74          return [
  75              'urlselect' => $urlselect->export_for_template($output),
  76              'heading' => $menu[$this->currenturl->out(false)] ?? null
  77          ];
  78      }
  79  }