Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 400 and 401] [Versions 401 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   * A drawer based layout for the boost theme.
  19   *
  20   * @package   theme_boost
  21   * @copyright 2021 Bas Brands
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  require_once($CFG->libdir . '/behat/lib.php');
  28  require_once($CFG->dirroot . '/course/lib.php');
  29  
  30  // Add block button in editing mode.
  31  $addblockbutton = $OUTPUT->addblockbutton();
  32  
  33  user_preference_allow_ajax_update('drawer-open-index', PARAM_BOOL);
  34  user_preference_allow_ajax_update('drawer-open-block', PARAM_BOOL);
  35  
  36  if (isloggedin()) {
  37      $courseindexopen = (get_user_preferences('drawer-open-index', true) == true);
  38      $blockdraweropen = (get_user_preferences('drawer-open-block') == true);
  39  } else {
  40      $courseindexopen = false;
  41      $blockdraweropen = false;
  42  }
  43  
  44  if (defined('BEHAT_SITE_RUNNING')) {
  45      $blockdraweropen = true;
  46  }
  47  
  48  $extraclasses = ['uses-drawers'];
  49  if ($courseindexopen) {
  50      $extraclasses[] = 'drawer-open-index';
  51  }
  52  
  53  $blockshtml = $OUTPUT->blocks('side-pre');
  54  $hasblocks = (strpos($blockshtml, 'data-block=') !== false || !empty($addblockbutton));
  55  if (!$hasblocks) {
  56      $blockdraweropen = false;
  57  }
  58  $courseindex = core_course_drawer();
  59  if (!$courseindex) {
  60      $courseindexopen = false;
  61  }
  62  
  63  $bodyattributes = $OUTPUT->body_attributes($extraclasses);
  64  $forceblockdraweropen = $OUTPUT->firstview_fakeblocks();
  65  
  66  $secondarynavigation = false;
  67  $overflow = '';
  68  if ($PAGE->has_secondary_navigation()) {
  69      $tablistnav = $PAGE->has_tablist_secondary_navigation();
  70      $moremenu = new \core\navigation\output\more_menu($PAGE->secondarynav, 'nav-tabs', true, $tablistnav);
  71      $secondarynavigation = $moremenu->export_for_template($OUTPUT);
  72      $overflowdata = $PAGE->secondarynav->get_overflow_menu_data();
  73      if (!is_null($overflowdata)) {
  74          $overflow = $overflowdata->export_for_template($OUTPUT);
  75      }
  76  }
  77  
  78  $primary = new core\navigation\output\primary($PAGE);
  79  $renderer = $PAGE->get_renderer('core');
  80  $primarymenu = $primary->export_for_template($renderer);
  81  $buildregionmainsettings = !$PAGE->include_region_main_settings_in_header_actions() && !$PAGE->has_secondary_navigation();
  82  // If the settings menu will be included in the header then don't add it here.
  83  $regionmainsettingsmenu = $buildregionmainsettings ? $OUTPUT->region_main_settings_menu() : false;
  84  
  85  $header = $PAGE->activityheader;
  86  $headercontent = $header->export_for_template($renderer);
  87  
  88  $templatecontext = [
  89      'sitename' => format_string($SITE->shortname, true, ['context' => context_course::instance(SITEID), "escape" => false]),
  90      'output' => $OUTPUT,
  91      'sidepreblocks' => $blockshtml,
  92      'hasblocks' => $hasblocks,
  93      'bodyattributes' => $bodyattributes,
  94      'courseindexopen' => $courseindexopen,
  95      'blockdraweropen' => $blockdraweropen,
  96      'courseindex' => $courseindex,
  97      'primarymoremenu' => $primarymenu['moremenu'],
  98      'secondarymoremenu' => $secondarynavigation ?: false,
  99      'mobileprimarynav' => $primarymenu['mobileprimarynav'],
 100      'usermenu' => $primarymenu['user'],
 101      'langmenu' => $primarymenu['lang'],
 102      'forceblockdraweropen' => $forceblockdraweropen,
 103      'regionmainsettingsmenu' => $regionmainsettingsmenu,
 104      'hasregionmainsettingsmenu' => !empty($regionmainsettingsmenu),
 105      'overflow' => $overflow,
 106      'headercontent' => $headercontent,
 107      'addblockbutton' => $addblockbutton
 108  ];
 109  
 110  echo $OUTPUT->render_from_template('theme_boost/drawers', $templatecontext);