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   * User navigation class.
  19   *
  20   * @package    tool_lp
  21   * @copyright  2019 Damyon Wiese
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  namespace tool_lp\output;
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  use renderable;
  29  use renderer_base;
  30  use templatable;
  31  use context_course;
  32  use core_course\external\course_module_summary_exporter;
  33  use stdClass;
  34  
  35  /**
  36   * User course navigation class.
  37   *
  38   * @package    tool_lp
  39   * @copyright  2015 Damyon Wiese
  40   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  41   */
  42  class module_navigation implements renderable, templatable {
  43  
  44      /** @var courseid */
  45      protected $courseid;
  46  
  47      /** @var moduleid */
  48      protected $moduleid;
  49  
  50      /** @var baseurl */
  51      protected $baseurl;
  52  
  53      /**
  54       * Construct.
  55       *
  56       * @param int $courseid
  57       * @param int $moduleid
  58       * @param string $baseurl
  59       */
  60      public function __construct($courseid, $moduleid, $baseurl) {
  61          $this->courseid = $courseid;
  62          $this->moduleid = $moduleid;
  63          $this->baseurl = $baseurl;
  64      }
  65  
  66      /**
  67       * Export the data.
  68       *
  69       * @param renderer_base $output
  70       * @return stdClass
  71       */
  72      public function export_for_template(renderer_base $output) {
  73  
  74          $context = context_course::instance($this->courseid);
  75  
  76          $data = new stdClass();
  77          $data->courseid = $this->courseid;
  78          $data->moduleid = $this->moduleid;
  79          $data->baseurl = $this->baseurl;
  80          $data->hasmodules = false;
  81          $data->modules = array();
  82  
  83          $data->hasmodules = true;
  84          $data->modules = array();
  85          $empty = (object)['id' => 0, 'name' => get_string('nofiltersapplied')];
  86          $data->modules[] = $empty;
  87  
  88          $modinfo = get_fast_modinfo($this->courseid);
  89          foreach ($modinfo->get_cms() as $cm) {
  90              if ($cm->uservisible) {
  91                  $exporter = new course_module_summary_exporter(null, ['cm' => $cm]);
  92                  $module = $exporter->export($output);
  93                  if ($module->id == $this->moduleid) {
  94                      $module->selected = true;
  95                  }
  96                  $data->modules[] = $module;
  97                  $data->hasmodules = true;
  98              }
  99          }
 100  
 101          return $data;
 102      }
 103  }