Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 1
<?php
2
// This file is part of Moodle - https://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <https://www.gnu.org/licenses/>.
16
 
17
/**
18
 * Display information about all the mod_subsection modules in the requested course.
19
 *
20
 * @package     mod_subsection
21
 * @copyright   2023 Amaia Anabitarte <amaia@moodle.com>
22
 * @license     https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
require(__DIR__.'/../../config.php');
26
 
27
require_once(__DIR__.'/lib.php');
28
 
29
$id = required_param('id', PARAM_INT);
30
 
31
$course = $DB->get_record('course', ['id' => $id], '*', MUST_EXIST);
32
require_course_login($course);
33
 
34
$coursecontext = context_course::instance($course->id);
35
$event = \mod_subsection\event\course_module_instance_list_viewed::create(['context' => $coursecontext]);
36
$event->add_record_snapshot('course', $course);
37
$event->trigger();
38
 
39
$PAGE->set_url('/mod/subsection/index.php', ['id' => $id]);
40
$PAGE->set_title(format_string($course->fullname));
41
$PAGE->set_heading(format_string($course->fullname));
42
$PAGE->set_context($coursecontext);
43
 
44
echo $OUTPUT->header();
45
 
46
$modulenameplural = get_string('modulenameplural', 'mod_subsection');
47
echo $OUTPUT->heading($modulenameplural);
48
 
49
$subsections = get_all_instances_in_course('subsection', $course);
50
 
51
if (empty($subsections)) {
52
    notice(get_string('thereareno', 'moodle', $modulenameplural), "$CFG->wwwroot/course/view.php?id=$course->id");
53
}
54
 
55
$table = new html_table();
56
$table->attributes['class'] = 'generaltable mod_index';
57
 
58
if ($course->format == 'weeks') {
59
    $table->head  = [get_string('week'), get_string('name')];
60
    $table->align = ['center', 'left'];
61
} else if ($course->format == 'topics') {
62
    $table->head  = [get_string('topic'), get_string('name')];
63
    $table->align = ['center', 'left', 'left', 'left'];
64
} else {
65
    $table->head  = [get_string('name')];
66
    $table->align = ['left', 'left', 'left'];
67
}
68
 
69
foreach ($subsections as $subsection) {
70
    if (!$subsection->visible) {
71
        $link = html_writer::link(
72
            new moodle_url('/mod/subsection/view.php', ['id' => $subsection->coursemodule]),
73
            format_string($subsection->name, true),
74
            ['class' => 'dimmed']);
75
    } else {
76
        $link = html_writer::link(
77
            new moodle_url('/mod/subsection/view.php', ['id' => $subsection->coursemodule]),
78
            format_string($subsection->name, true));
79
    }
80
 
81
    if ($course->format == 'weeks' || $course->format == 'topics') {
82
        $table->data[] = [$subsection->section, $link];
83
    } else {
84
        $table->data[] = [$link];
85
    }
86
}
87
 
88
echo html_writer::table($table);
89
echo $OUTPUT->footer();