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 310 and 401] [Versions 311 and 401] [Versions 39 and 401]

   1  <?php
   2  
   3  // This file is part of Moodle - http://moodle.org/
   4  //
   5  // Moodle is free software: you can redistribute it and/or modify
   6  // it under the terms of the GNU General Public License as published by
   7  // the Free Software Foundation, either version 3 of the License, or
   8  // (at your option) any later version.
   9  //
  10  // Moodle is distributed in the hope that it will be useful,
  11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13  // GNU General Public License for more details.
  14  //
  15  // You should have received a copy of the GNU General Public License
  16  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  17  
  18  /**
  19   * Folder module main user interface
  20   *
  21   * @package   mod_folder
  22   * @copyright 2009 Petr Skoda  {@link http://skodak.org}
  23   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  require('../../config.php');
  27  require_once("$CFG->dirroot/mod/folder/locallib.php");
  28  require_once("$CFG->dirroot/repository/lib.php");
  29  require_once($CFG->libdir . '/completionlib.php');
  30  
  31  $id = optional_param('id', 0, PARAM_INT);  // Course module ID
  32  $f  = optional_param('f', 0, PARAM_INT);   // Folder instance id
  33  
  34  if ($f) {  // Two ways to specify the module
  35      $folder = $DB->get_record('folder', array('id'=>$f), '*', MUST_EXIST);
  36      $cm = get_coursemodule_from_instance('folder', $folder->id, $folder->course, true, MUST_EXIST);
  37  
  38  } else {
  39      $cm = get_coursemodule_from_id('folder', $id, 0, true, MUST_EXIST);
  40      $folder = $DB->get_record('folder', array('id'=>$cm->instance), '*', MUST_EXIST);
  41  }
  42  
  43  $course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
  44  
  45  require_course_login($course, true, $cm);
  46  $context = context_module::instance($cm->id);
  47  require_capability('mod/folder:view', $context);
  48  if ($folder->display == FOLDER_DISPLAY_INLINE) {
  49      redirect(course_get_url($folder->course, $cm->sectionnum));
  50  }
  51  
  52  $params = array(
  53      'context' => $context,
  54      'objectid' => $folder->id
  55  );
  56  $event = \mod_folder\event\course_module_viewed::create($params);
  57  $event->add_record_snapshot('course_modules', $cm);
  58  $event->add_record_snapshot('course', $course);
  59  $event->add_record_snapshot('folder', $folder);
  60  $event->trigger();
  61  
  62  // Update 'viewed' state if required by completion system
  63  $completion = new completion_info($course);
  64  $completion->set_module_viewed($cm);
  65  
  66  $PAGE->set_url('/mod/folder/view.php', array('id' => $cm->id));
  67  
  68  $PAGE->set_title($course->shortname.': '.$folder->name);
  69  $PAGE->set_heading($course->fullname);
  70  $PAGE->set_activity_record($folder);
  71  
  72  $PAGE->add_body_class('limitedwidth');
  73  
  74  $output = $PAGE->get_renderer('mod_folder');
  75  
  76  echo $output->header();
  77  
  78  echo $output->display_folder($folder);
  79  
  80  echo $output->footer();