Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]

   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  
  73  $output = $PAGE->get_renderer('mod_folder');
  74  
  75  echo $output->header();
  76  
  77  echo $output->heading(format_string($folder->name), 2);
  78  
  79  echo $output->display_folder($folder);
  80  
  81  echo $output->footer();