MDL-86338 course_format: Resources overview page redirection

This commit is contained in:
Laurent David
2025-08-21 12:35:18 +02:00
parent c1311feeb1
commit f4b12bf936
6 changed files with 18 additions and 479 deletions
+3 -76
View File
@@ -21,81 +21,8 @@
* @copyright 2004-2011 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once("../../config.php");
require(__DIR__.'/../../config.php');
require_once(__DIR__.'/locallib.php');
$courseid = required_param('id', PARAM_INT);
$id = required_param('id', PARAM_INT); // Course ID.
$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
unset($id);
require_course_login($course, true);
$PAGE->set_pagelayout('incourse');
// Get all required strings
$strbooks = get_string('modulenameplural', 'mod_book');
$strbook = get_string('modulename', 'mod_book');
$strname = get_string('name');
$strintro = get_string('moduleintro');
$strlastmodified = get_string('lastmodified');
$PAGE->set_url('/mod/book/index.php', array('id' => $course->id));
$PAGE->set_title($course->shortname . \moodle_page::TITLE_SEPARATOR . $strbooks);
$PAGE->set_heading($course->fullname);
$PAGE->navbar->add($strbooks);
echo $OUTPUT->header();
\mod_book\event\course_module_instance_list_viewed::create_from_course($course)->trigger();
// Get all the appropriate data
if (!$books = get_all_instances_in_course('book', $course)) {
notice(get_string('thereareno', 'moodle', $strbooks), "$CFG->wwwroot/course/view.php?id=$course->id");
die;
}
$usesections = course_format_uses_sections($course->format);
$table = new html_table();
$table->attributes['class'] = 'table generaltable mod_index';
if ($usesections) {
$strsectionname = course_get_format($course)->get_generic_section_name();
$table->head = array ($strsectionname, $strname, $strintro);
$table->align = array ('center', 'left', 'left');
} else {
$table->head = array ($strlastmodified, $strname, $strintro);
$table->align = array ('left', 'left', 'left');
}
$modinfo = get_fast_modinfo($course);
$currentsection = '';
foreach ($books as $book) {
$cm = $modinfo->get_cm($book->coursemodule);
if ($usesections) {
$printsection = '';
if ($book->section !== $currentsection) {
if ($book->section) {
$printsection = get_section_name($course, $book->section);
}
if ($currentsection !== '') {
$table->data[] = 'hr';
}
$currentsection = $book->section;
}
} else {
$printsection = html_writer::tag('span', userdate($book->timemodified), array('class' => 'smallinfo'));
}
$class = $book->visible ? null : array('class' => 'dimmed'); // hidden modules are dimmed
$table->data[] = array (
$printsection,
html_writer::link(new moodle_url('view.php', array('id' => $cm->id)), format_string($book->name), $class),
format_module_intro('book', $book, $cm->id));
}
echo html_writer::table($table);
echo $OUTPUT->footer();
\core_courseformat\activityoverviewbase::redirect_to_overview_page($courseid, 'resource');
+3 -87
View File
@@ -1,5 +1,4 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -15,91 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* List of file folders in course
*
* @package mod_folder
* @copyright 2009 onwards Martin Dougiamas (http://dougiamas.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once("../../config.php");
require('../../config.php');
$courseid = required_param('id', PARAM_INT);
$id = required_param('id', PARAM_INT); // course id
$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
require_course_login($course, true);
$PAGE->set_pagelayout('incourse');
$params = array(
'context' => context_course::instance($course->id)
);
$event = \mod_folder\event\course_module_instance_list_viewed::create($params);
$event->add_record_snapshot('course', $course);
$event->trigger();
$strfolder = get_string('modulename', 'folder');
$strfolders = get_string('modulenameplural', 'folder');
$strname = get_string('name');
$strintro = get_string('moduleintro');
$strlastmodified = get_string('lastmodified');
$PAGE->set_url('/mod/folder/index.php', array('id' => $course->id));
$PAGE->set_title($course->shortname . \moodle_page::TITLE_SEPARATOR . $strfolders);
$PAGE->set_heading($course->fullname);
$PAGE->set_secondary_active_tab('coursehome');
$PAGE->navbar->add($strfolders);
echo $OUTPUT->header();
if (!$PAGE->has_secondary_navigation()) {
echo $OUTPUT->heading($strfolders);
}
if (!$folders = get_all_instances_in_course('folder', $course)) {
notice(get_string('thereareno', 'moodle', $strfolders), "$CFG->wwwroot/course/view.php?id=$course->id");
exit;
}
$usesections = course_format_uses_sections($course->format);
$table = new html_table();
$table->attributes['class'] = 'table generaltable mod_index';
if ($usesections) {
$strsectionname = course_get_format($course)->get_generic_section_name();
$table->head = array ($strsectionname, $strname, $strintro);
$table->align = array ('center', 'left', 'left');
} else {
$table->head = array ($strlastmodified, $strname, $strintro);
$table->align = array ('left', 'left', 'left');
}
$modinfo = get_fast_modinfo($course);
$currentsection = '';
foreach ($folders as $folder) {
$cm = $modinfo->cms[$folder->coursemodule];
if ($usesections) {
$printsection = '';
if ($folder->section !== $currentsection) {
if ($folder->section) {
$printsection = get_section_name($course, $folder->section);
}
if ($currentsection !== '') {
$table->data[] = 'hr';
}
$currentsection = $folder->section;
}
} else {
$printsection = '<span class="smallinfo">'.userdate($folder->timemodified)."</span>";
}
$class = $folder->visible ? '' : 'class="dimmed"'; // hidden modules are dimmed
$table->data[] = array (
$printsection,
"<a $class href=\"view.php?id=$cm->id\">".format_string($folder->name)."</a>",
format_module_intro('folder', $folder, $cm->id));
}
echo html_writer::table($table);
echo $OUTPUT->footer();
\core_courseformat\activityoverviewbase::redirect_to_overview_page($courseid, 'resource');
+3 -74
View File
@@ -22,79 +22,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require('../../config.php');
require_once("../../config.php");
$id = required_param('id', PARAM_INT); // Course id.
$courseid = required_param('id', PARAM_INT);
$course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST);
require_course_login($course, true);
$PAGE->set_pagelayout('incourse');
$params = array(
'context' => context_course::instance($course->id)
);
$event = \mod_imscp\event\course_module_instance_list_viewed::create($params);
$event->trigger();
$strimscp = get_string('modulename', 'imscp');
$strimscps = get_string('modulenameplural', 'imscp');
$strname = get_string('name');
$strintro = get_string('moduleintro');
$strlastmodified = get_string('lastmodified');
$PAGE->set_url('/mod/imscp/index.php', array('id' => $course->id));
$PAGE->set_title($course->shortname.': '.$strimscps);
$PAGE->set_heading($course->fullname);
$PAGE->navbar->add($strimscps);
echo $OUTPUT->header();
echo $OUTPUT->heading($strimscps);
if (!$imscps = get_all_instances_in_course('imscp', $course)) {
notice(get_string('thereareno', 'moodle', $strimscps), "$CFG->wwwroot/course/view.php?id=$course->id");
exit;
}
$usesections = course_format_uses_sections($course->format);
$table = new html_table();
$table->attributes['class'] = 'table generaltable mod_index';
if ($usesections) {
$strsectionname = course_get_format($course)->get_generic_section_name();
$table->head = array ($strsectionname, $strname, $strintro);
$table->align = array ('center', 'left', 'left');
} else {
$table->head = array ($strlastmodified, $strname, $strintro);
$table->align = array ('left', 'left', 'left');
}
$modinfo = get_fast_modinfo($course);
$currentsection = '';
foreach ($imscps as $imscp) {
$cm = $modinfo->cms[$imscp->coursemodule];
if ($usesections) {
$printsection = '';
if ($imscp->section !== $currentsection) {
if ($imscp->section) {
$printsection = get_section_name($course, $imscp->section);
}
if ($currentsection !== '') {
$table->data[] = 'hr';
}
$currentsection = $imscp->section;
}
} else {
$printsection = '<span class="smallinfo">'.userdate($imscp->timemodified)."</span>";
}
$class = $imscp->visible ? '' : 'class="dimmed"'; // Hidden modules are dimmed.
$table->data[] = array (
$printsection,
"<a $class href=\"view.php?id=$cm->id\">" . format_string($imscp->name)."</a>",
format_module_intro('imscp', $imscp, $cm->id));
}
echo html_writer::table($table);
echo $OUTPUT->footer();
\core_courseformat\activityoverviewbase::redirect_to_overview_page($courseid, 'resource');
+3 -73
View File
@@ -23,78 +23,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require('../../config.php');
require_once("../../config.php");
$id = required_param('id', PARAM_INT); // course id
$courseid = required_param('id', PARAM_INT);
$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
require_course_login($course, true);
$PAGE->set_pagelayout('incourse');
// Trigger instances list viewed event.
$event = \mod_page\event\course_module_instance_list_viewed::create(array('context' => context_course::instance($course->id)));
$event->add_record_snapshot('course', $course);
$event->trigger();
$strpage = get_string('modulename', 'page');
$strpages = get_string('modulenameplural', 'page');
$strname = get_string('name');
$strintro = get_string('moduleintro');
$strlastmodified = get_string('lastmodified');
$PAGE->set_url('/mod/page/index.php', array('id' => $course->id));
$PAGE->set_title($course->shortname.': '.$strpages);
$PAGE->set_heading($course->fullname);
$PAGE->navbar->add($strpages);
echo $OUTPUT->header();
echo $OUTPUT->heading($strpages);
if (!$pages = get_all_instances_in_course('page', $course)) {
notice(get_string('thereareno', 'moodle', $strpages), "$CFG->wwwroot/course/view.php?id=$course->id");
exit;
}
$usesections = course_format_uses_sections($course->format);
$table = new html_table();
$table->attributes['class'] = 'table generaltable mod_index';
if ($usesections) {
$strsectionname = course_get_format($course)->get_generic_section_name();
$table->head = array ($strsectionname, $strname, $strintro);
$table->align = array ('center', 'left', 'left');
} else {
$table->head = array ($strlastmodified, $strname, $strintro);
$table->align = array ('left', 'left', 'left');
}
$modinfo = get_fast_modinfo($course);
$currentsection = '';
foreach ($pages as $page) {
$cm = $modinfo->cms[$page->coursemodule];
if ($usesections) {
$printsection = '';
if ($page->section !== $currentsection) {
if ($page->section) {
$printsection = get_section_name($course, $page->section);
}
if ($currentsection !== '') {
$table->data[] = 'hr';
}
$currentsection = $page->section;
}
} else {
$printsection = '<span class="smallinfo">'.userdate($page->timemodified)."</span>";
}
$class = $page->visible ? '' : 'class="dimmed"'; // hidden modules are dimmed
$table->data[] = array (
$printsection,
"<a $class href=\"view.php?id=$cm->id\">".format_string($page->name)."</a>",
format_module_intro('page', $page, $cm->id));
}
echo html_writer::table($table);
echo $OUTPUT->footer();
\core_courseformat\activityoverviewbase::redirect_to_overview_page($courseid, 'resource');
+3 -84
View File
@@ -23,89 +23,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require('../../config.php');
require_once("../../config.php");
$id = required_param('id', PARAM_INT); // course id
$courseid = required_param('id', PARAM_INT);
$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
require_course_login($course, true);
$PAGE->set_pagelayout('incourse');
$params = array(
'context' => context_course::instance($course->id)
);
$event = \mod_resource\event\course_module_instance_list_viewed::create($params);
$event->add_record_snapshot('course', $course);
$event->trigger();
$strresource = get_string('modulename', 'resource');
$strresources = get_string('modulenameplural', 'resource');
$strsectionname = course_get_format($course)->get_generic_section_name();
$strname = get_string('name');
$strintro = get_string('moduleintro');
$strlastmodified = get_string('lastmodified');
$PAGE->set_url('/mod/resource/index.php', array('id' => $course->id));
$PAGE->set_title($course->shortname.': '.$strresources);
$PAGE->set_heading($course->fullname);
$PAGE->navbar->add($strresources);
echo $OUTPUT->header();
if (!$PAGE->has_secondary_navigation()) {
echo $OUTPUT->heading($strresources);
}
if (!$resources = get_all_instances_in_course('resource', $course)) {
notice(get_string('thereareno', 'moodle', $strresources), "$CFG->wwwroot/course/view.php?id=$course->id");
exit;
}
$usesections = course_format_uses_sections($course->format);
$table = new html_table();
$table->attributes['class'] = 'table generaltable mod_index';
if ($usesections) {
$table->head = array ($strsectionname, $strname, $strintro);
$table->align = array ('center', 'left', 'left');
} else {
$table->head = array ($strlastmodified, $strname, $strintro);
$table->align = array ('left', 'left', 'left');
}
$modinfo = get_fast_modinfo($course);
$currentsection = '';
foreach ($resources as $resource) {
$cm = $modinfo->cms[$resource->coursemodule];
if ($usesections) {
$printsection = '';
if ($resource->section !== $currentsection) {
if ($resource->section) {
$printsection = get_section_name($course, $resource->section);
}
if ($currentsection !== '') {
$table->data[] = 'hr';
}
$currentsection = $resource->section;
}
} else {
$printsection = '<span class="smallinfo">'.userdate($resource->timemodified)."</span>";
}
$extra = empty($cm->extra) ? '' : $cm->extra;
$icon = '';
if (!empty($cm->icon)) {
// each resource file has an icon in 2.0
$icon = $OUTPUT->pix_icon($cm->icon, get_string('modulename', $cm->modname));
}
$class = $resource->visible ? '' : 'class="dimmed"'; // hidden modules are dimmed
$table->data[] = array (
$printsection,
"<a $class $extra href=\"view.php?id=$cm->id\">".$icon.format_string($resource->name)."</a>",
format_module_intro('resource', $resource, $cm->id));
}
echo html_writer::table($table);
echo $OUTPUT->footer();
\core_courseformat\activityoverviewbase::redirect_to_overview_page($courseid, 'resource');
+3 -85
View File
@@ -22,90 +22,8 @@
* @copyright 2009 onwards Martin Dougiamas (http://dougiamas.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once("../../config.php");
require('../../config.php');
$courseid = required_param('id', PARAM_INT);
$id = required_param('id', PARAM_INT); // course id
$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
require_course_login($course, true);
$PAGE->set_pagelayout('incourse');
$params = array(
'context' => context_course::instance($course->id)
);
$event = \mod_url\event\course_module_instance_list_viewed::create($params);
$event->add_record_snapshot('course', $course);
$event->trigger();
$strurl = get_string('modulename', 'url');
$strurls = get_string('modulenameplural', 'url');
$strname = get_string('name');
$strintro = get_string('moduleintro');
$strlastmodified = get_string('lastmodified');
$PAGE->set_url('/mod/url/index.php', array('id' => $course->id));
$PAGE->set_title($course->shortname.': '.$strurls);
$PAGE->set_heading($course->fullname);
$PAGE->navbar->add($strurls);
echo $OUTPUT->header();
if (!$PAGE->has_secondary_navigation()) {
echo $OUTPUT->heading($strurls);
}
if (!$urls = get_all_instances_in_course('url', $course)) {
notice(get_string('thereareno', 'moodle', $strurls), "$CFG->wwwroot/course/view.php?id=$course->id");
exit;
}
$usesections = course_format_uses_sections($course->format);
$table = new html_table();
$table->attributes['class'] = 'table generaltable mod_index';
if ($usesections) {
$strsectionname = course_get_format($course)->get_generic_section_name();
$table->head = array ($strsectionname, $strname, $strintro);
$table->align = array ('center', 'left', 'left');
} else {
$table->head = array ($strlastmodified, $strname, $strintro);
$table->align = array ('left', 'left', 'left');
}
$modinfo = get_fast_modinfo($course);
$currentsection = '';
foreach ($urls as $url) {
$cm = $modinfo->cms[$url->coursemodule];
if ($usesections) {
$printsection = '';
if ($url->section !== $currentsection) {
if ($url->section) {
$printsection = get_section_name($course, $url->section);
}
if ($currentsection !== '') {
$table->data[] = 'hr';
}
$currentsection = $url->section;
}
} else {
$printsection = '<span class="smallinfo">'.userdate($url->timemodified)."</span>";
}
$extra = empty($cm->extra) ? '' : $cm->extra;
$icon = '';
if (!empty($cm->icon)) {
// each url has an icon in 2.0
$icon = $OUTPUT->pix_icon($cm->icon, get_string('modulename', $cm->modname)) . ' ';
}
$class = $url->visible ? '' : 'class="dimmed"'; // hidden modules are dimmed
$table->data[] = array (
$printsection,
"<a $class $extra href=\"view.php?id=$cm->id\">".$icon.format_string($url->name)."</a>",
format_module_intro('url', $url, $cm->id));
}
echo html_writer::table($table);
echo $OUTPUT->footer();
\core_courseformat\activityoverviewbase::redirect_to_overview_page($courseid, 'resource');