Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://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 <http://www.gnu.org/licenses/>.
16
 
17
/**
18
 * Display information about all the mod_custommailing modules in the requested course.
19
 *
20
 * @package    mod_custommailing
21
 * @author     jeanfrancois@cblue.be,olivier@cblue.be
22
 * @copyright  2021 CBlue SPRL
23
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25
 
26
use mod_custommailing\event\course_module_instance_list_viewed;
27
 
28
require_once __DIR__ . '/../../config.php';
29
 
30
global $CFG, $DB, $PAGE, $OUTPUT;
31
 
32
require_once $CFG->dirroot . '/mod/custommailing/lib.php';
33
 
34
$id = required_param('id', PARAM_INT);
35
 
36
if (!empty($id)) {
37
    if (!$course = $DB->get_record('course', ['id' => $id])) {
38
        print_error('invalidcourseid');
39
    }
40
} else {
41
    print_error('missingparameter');
42
}
43
 
44
require_course_login($course);
45
 
46
$PAGE->set_url('/mod/custommailing/index.php', ['id' => $id]);
47
$PAGE->set_pagelayout('incourse');
48
 
49
// Add the page view to the Moodle log.
50
$event = course_module_instance_list_viewed::create(
51
    [
52
        'context' => context_course::instance($course->id)
53
    ]
54
);
55
$event->add_record_snapshot('course', $course);
56
$event->trigger();
57
 
58
// Print the header.
59
$PAGE->set_title(format_string(get_string('modulename', 'custommailing')));
60
$PAGE->set_heading(format_string($course->fullname));
61
echo $OUTPUT->header();
62
 
63
// Get all the appropriate data.
64
if (!$mailings = get_all_instances_in_course('custommailing', $course)) {
65
    notice('There are no instances of custommailing', "../../course/view.php?id=$course->id");
66
    die;
67
}
68
 
69
// Print the list of instances.
70
$table = new html_table();
71
$table->attributes['class'] = 'generaltable mod_index';
72
 
73
$usesections = course_format_uses_sections($course->format);
74
$modinfo = get_fast_modinfo($course);
75
$currentsection = '';
76
foreach ($mailings as $mailing) {
77
    $cm = $modinfo->cms[$mailing->coursemodule];
78
    if ($usesections) {
79
        $printsection = '';
80
        if ($mailing->section !== $currentsection) {
81
            if ($mailing->section) {
82
                $printsection = get_section_name($course, $mailing->section);
83
            }
84
            if ($currentsection !== '') {
85
                $table->data[] = 'hr';
86
            }
87
            $currentsection = $mailing->section;
88
        }
89
    } else {
90
        $printsection = userdate($mailing->timemodified);
91
    }
92
 
93
    $class = $mailing->visible ? '' : 'class="dimmed"'; // Hidden modules are dimmed.
94
 
95
    $table->data[] = [
96
        $printsection, html_writer::link('view.php?id=' . $cm->id, format_string($mailing->name))
97
    ];
98
}
99
 
100
echo html_writer::table($table);
101
 
102
echo $OUTPUT->footer();
103