3 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
19 * Folder module main user interface
22 * @copyright 2009 Petr Skoda {@link http://skodak.org}
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
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');
31 $id = optional_param('id', 0, PARAM_INT
); // Course module ID
32 $f = optional_param('f', 0, PARAM_INT
); // Folder instance id
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
);
39 $cm = get_coursemodule_from_id('folder', $id, 0, true, MUST_EXIST
);
40 $folder = $DB->get_record('folder', array('id'=>$cm->instance
), '*', MUST_EXIST
);
43 $course = $DB->get_record('course', array('id'=>$cm->course
), '*', MUST_EXIST
);
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
));
53 'context' => $context,
54 'objectid' => $folder->id
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);
62 // Update 'viewed' state if required by completion system
63 $completion = new completion_info($course);
64 $completion->set_module_viewed($cm);
66 $PAGE->set_url('/mod/folder/view.php', array('id' => $cm->id
));
68 $PAGE->set_title($course->shortname
.': '.$folder->name
);
69 $PAGE->set_heading($course->fullname
);
70 $PAGE->set_activity_record($folder);
72 $PAGE->add_body_class('limitedwidth');
74 $output = $PAGE->get_renderer('mod_folder');
76 echo $output->header();
78 echo $output->display_folder($folder);
80 echo $output->footer();