MDL-83900 mod_wiki: Refactor the course index page

This commit is contained in:
Laurent David
2025-07-10 09:00:24 +02:00
parent 6a7963faad
commit c45ec3f2b2
3 changed files with 4 additions and 67 deletions
@@ -141,7 +141,7 @@ final class overviewfactory_test extends \advanced_testcase {
],
'wiki' => [
'resourcetype' => 'wiki',
'expected' => resourceoverview::class,
'expected' => \mod_wiki\courseformat\overview::class,
],
'workshop' => [
'resourcetype' => 'workshop',
@@ -83,7 +83,7 @@ final class missingoverviewnotice_test extends \advanced_testcase {
'resource' => ['modname' => 'resource', 'expectempty' => true],
'scorm' => ['modname' => 'scorm', 'expectempty' => false],
'url' => ['modname' => 'url', 'expectempty' => false],
'wiki' => ['modname' => 'wiki', 'expectempty' => false],
'wiki' => ['modname' => 'wiki', 'expectempty' => true],
'workshop' => ['modname' => 'workshop', 'expectempty' => true],
];
}
+2 -65
View File
@@ -32,70 +32,7 @@
*/
require_once('../../config.php');
require_once('lib.php');
$id = required_param('id', PARAM_INT); // course
$PAGE->set_url('/mod/wiki/index.php', array('id' => $id));
$courseid = required_param('id', PARAM_INT);
if (!$course = $DB->get_record('course', array('id' => $id))) {
throw new \moodle_exception('invalidcourseid');
}
require_login($course, true);
$PAGE->set_pagelayout('incourse');
$context = context_course::instance($course->id);
$event = \mod_wiki\event\course_module_instance_list_viewed::create(array('context' => $context));
$event->add_record_snapshot('course', $course);
$event->trigger();
/// Get all required stringswiki
$strwikis = get_string("modulenameplural", "wiki");
$strwiki = get_string("modulename", "wiki");
/// Print the header
$PAGE->navbar->add($strwikis, "index.php?id=$course->id");
$PAGE->set_title($strwikis);
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();
echo $OUTPUT->heading($strwikis);
/// Get all the appropriate data
if (!$wikis = get_all_instances_in_course("wiki", $course)) {
notice("There are no wikis", "../../course/view.php?id=$course->id");
die;
}
$usesections = course_format_uses_sections($course->format);
/// Print the list of instances (your module will probably extend this)
$timenow = time();
$strname = get_string("name");
$table = new html_table();
if ($usesections) {
$strsectionname = course_get_format($course)->get_generic_section_name();
$table->head = array($strsectionname, $strname);
} else {
$table->head = array($strname);
}
foreach ($wikis as $wiki) {
$linkcss = null;
if (!$wiki->visible) {
$linkcss = array('class' => 'dimmed');
}
$link = html_writer::link(new moodle_url('/mod/wiki/view.php', array('id' => $wiki->coursemodule)), $wiki->name, $linkcss);
if ($usesections) {
$table->data[] = array(get_section_name($course, $wiki->section), $link);
} else {
$table->data[] = array($link);
}
}
echo html_writer::table($table);
/// Finish the page
echo $OUTPUT->footer();
\core_courseformat\activityoverviewbase::redirect_to_overview_page($courseid, 'wiki');