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.
   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_feedback\navigation\views;
  18  
  19  use core\navigation\views\secondary as core_secondary;
  20  use settings_navigation;
  21  use navigation_node;
  22  
  23  /**
  24   * Custom secondary navigation class
  25   *
  26   * A custom construct of secondary nav for feedback. This rearranges the nodes for the secondary
  27   *
  28   * @package     mod_feedback
  29   * @category    navigation
  30   * @copyright   2021 onwards Peter Dias
  31   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  32   */
  33  class secondary extends core_secondary {
  34      protected function get_default_module_mapping(): array {
  35          $basenodes = parent::get_default_module_mapping();
  36          $basenodes[self::TYPE_CUSTOM] += [
  37              'templatenode' => 12,
  38              'mapcourse' => 13,
  39              'feedbackanalysis' => 14,
  40              'responses' => 15,
  41              'nonrespondents' => 15.1
  42          ];
  43  
  44          return $basenodes;
  45      }
  46  
  47      /**
  48       * Custom module construct for feedback
  49       *
  50       * @param settings_navigation $settingsnav The settings navigation object related to the module page
  51       * @param navigation_node|null $rootnode The node where the module navigation nodes should be added into as children.
  52       *                                       If not explicitly defined, the nodes will be added to the secondary root
  53       *                                       node by default.
  54       */
  55      protected function load_module_navigation(settings_navigation $settingsnav, ?navigation_node $rootnode = null): void {
  56          $rootnode = $rootnode ?? $this;
  57          $mainnode = $settingsnav->find('modulesettings', self::TYPE_SETTING);
  58          $nodes = $this->get_default_module_mapping();
  59  
  60          if ($mainnode) {
  61              $url = new \moodle_url('/mod/' . $this->page->activityname . '/view.php', ['id' => $this->page->cm->id]);
  62              $setactive = $url->compare($this->page->url, URL_MATCH_BASE);
  63              $node = $rootnode->add(get_string('modulename', 'feedback'), $url, null, null, 'modulepage');
  64              if ($setactive) {
  65                  $node->make_active();
  66              }
  67  
  68              // Add the initial nodes.
  69              $nodesordered = $this->get_leaf_nodes($mainnode, $nodes);
  70              $this->add_ordered_nodes($nodesordered, $rootnode);
  71  
  72              // Reorder the existing nodes in settings so the active node scan can pick it up.
  73              $existingnode = $settingsnav->find('questionnode', self::TYPE_CUSTOM);
  74              if ($existingnode) {
  75                  $node->add_node($existingnode);
  76                  $nodes[self::TYPE_CUSTOM] += ['questionnode' => 3];
  77              }
  78              // We have finished inserting the initial structure.
  79              // Populate the menu with the rest of the nodes available.
  80              $this->load_remaining_nodes($mainnode, $nodes, $rootnode);
  81          }
  82      }
  83  }