Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.
   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   * @package   theme_boost
  19   * @copyright 2016 Ryan Wyllie
  20   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  21   */
  22  
  23  defined('MOODLE_INTERNAL') || die();
  24  
  25  /**
  26   * @package   theme_boost
  27   * @copyright 2016 Ryan Wyllie
  28   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  29   */
  30  class theme_boost_admin_settingspage_tabs extends admin_settingpage {
  31  
  32      /** @var The tabs */
  33      protected $tabs = array();
  34  
  35      /**
  36       * Add a tab.
  37       *
  38       * @param admin_settingpage $tab A tab.
  39       */
  40      public function add_tab(admin_settingpage $tab) {
  41          foreach ($tab->settings as $setting) {
  42              $this->settings->{$setting->name} = $setting;
  43          }
  44          $this->tabs[] = $tab;
  45          return true;
  46      }
  47  
  48      public function add($tab) {
  49          return $this->add_tab($tab);
  50      }
  51  
  52      /**
  53       * Get tabs.
  54       *
  55       * @return array
  56       */
  57      public function get_tabs() {
  58          return $this->tabs;
  59      }
  60  
  61      /**
  62       * Generate the HTML output.
  63       *
  64       * @return string
  65       */
  66      public function output_html() {
  67          global $OUTPUT;
  68  
  69          $activetab = optional_param('activetab', '', PARAM_TEXT);
  70          $context = array('tabs' => array());
  71          $havesetactive = false;
  72  
  73          foreach ($this->get_tabs() as $tab) {
  74              $active = false;
  75  
  76              // Default to first tab it not told otherwise.
  77              if (empty($activetab) && !$havesetactive) {
  78                  $active = true;
  79                  $havesetactive = true;
  80              } else if ($activetab === $tab->name) {
  81                  $active = true;
  82              }
  83  
  84              $context['tabs'][] = array(
  85                  'name' => $tab->name,
  86                  'displayname' => $tab->visiblename,
  87                  'html' => $tab->output_html(),
  88                  'active' => $active,
  89              );
  90          }
  91  
  92          if (empty($context['tabs'])) {
  93              return '';
  94          }
  95  
  96          return $OUTPUT->render_from_template('theme_boost/admin_setting_tabs', $context);
  97      }
  98  
  99  }
 100