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 |
* Mailing logs output table
|
|
|
19 |
*
|
|
|
20 |
* @package mod_custommailing
|
|
|
21 |
* @author jeanfrancois@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\MailingLog;
|
|
|
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 |
[$course, $cm] = get_course_and_cm_from_cmid($id, 'custommailing');
|
|
|
37 |
$custommailing = $DB->get_record("custommailing", ['id' => $cm->instance]);
|
|
|
38 |
$context = context_module::instance($cm->id);
|
|
|
39 |
|
|
|
40 |
require_login($course, false, $cm);
|
|
|
41 |
require_capability('mod/custommailing:manage', $context);
|
|
|
42 |
|
|
|
43 |
$PAGE->set_url('/mod/custommailing/logs.php', ['id' => $id]);
|
|
|
44 |
$PAGE->set_pagelayout('incourse');
|
|
|
45 |
|
|
|
46 |
// Print the header.
|
|
|
47 |
$PAGE->set_title(format_string(get_string('modulename', 'custommailing')));
|
|
|
48 |
$PAGE->set_heading(format_string($course->fullname) . ' : ' . get_string('logtable', 'custommailing'));
|
|
|
49 |
echo $OUTPUT->header();
|
|
|
50 |
|
|
|
51 |
// Get all the appropriate data.
|
|
|
52 |
if (!$logs = MailingLog::getAllForTable($custommailing->id)) {
|
|
|
53 |
notice('There are no instances of custommailing', "../../course/view.php?id=$course->id");
|
|
|
54 |
die;
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
// Print the list of instances.
|
|
|
58 |
$table = new html_table();
|
|
|
59 |
$table->attributes['class'] = 'generaltable mod_index';
|
|
|
60 |
$table->head = [
|
|
|
61 |
get_string('mailingname', 'custommailing'),
|
|
|
62 |
get_string('user'),
|
|
|
63 |
get_string('date'),
|
|
|
64 |
get_string('status'),
|
|
|
65 |
];
|
|
|
66 |
$table->data = [];
|
|
|
67 |
|
|
|
68 |
$string_statuses = [
|
|
|
69 |
MAILING_LOG_FAILED => get_string('log_mailing_failed', 'custommailing'),
|
|
|
70 |
MAILING_LOG_SENT => get_string('log_mailing_sent', 'custommailing'),
|
|
|
71 |
MAILING_LOG_PROCESSING => get_string('log_mailing_processing', 'custommailing'),
|
|
|
72 |
MAILING_LOG_IDLE => get_string('log_mailing_idle', 'custommailing'),
|
|
|
73 |
];
|
|
|
74 |
$string_unknown_status = get_string('log_mailing_unknown', 'custommailing');
|
|
|
75 |
|
|
|
76 |
foreach ($logs as $log) {
|
|
|
77 |
$srow = new html_table_row();
|
|
|
78 |
|
|
|
79 |
$srow->cells = [
|
|
|
80 |
$log->mailingname,
|
|
|
81 |
$log->user,
|
|
|
82 |
userdate($log->timecreated),
|
|
|
83 |
];
|
|
|
84 |
if (isset($string_statuses[$log->emailstatus])) {
|
|
|
85 |
$srow->cells[] = $string_statuses[$log->emailstatus];
|
|
|
86 |
}
|
|
|
87 |
else {
|
|
|
88 |
$srow->cells[] = $string_unknown_status;
|
|
|
89 |
}
|
|
|
90 |
$table->data[] = $srow;
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
echo html_writer::table($table);
|
|
|
94 |
echo html_writer::link(new moodle_url('/mod/custommailing/view.php', ['id' => $cm->id]), get_string('back'), ['class' => 'btn btn-primary']);
|
|
|
95 |
|
|
|
96 |
echo $OUTPUT->footer();
|