-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbatch.php
More file actions
131 lines (110 loc) · 4.62 KB
/
batch.php
File metadata and controls
131 lines (110 loc) · 4.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* View batch details.
*
* @package local_bbcomailing
* @copyright 2026 David Herney @ BambuCo
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use core\output\html_writer;
use core_table\output\html_table;
use core\url as moodle_url;
use core\context\system as context_system;
require_once('../../config.php');
require_login();
$context = context_system::instance();
require_capability('local/bbcomailing:manage', $context);
$batchcode = required_param('batchcode', PARAM_ALPHANUMEXT);
$PAGE->set_context($context);
$PAGE->set_url(new moodle_url('/local/bbcomailing/batch.php', ['batchcode' => $batchcode]));
$PAGE->set_title(get_string('batchdetails', 'local_bbcomailing'));
$PAGE->set_heading(get_string('batchdetails', 'local_bbcomailing'));
$PAGE->set_pagelayout('admin');
// Handle cancellation.
$cancel = optional_param('cancel', 0, PARAM_INT);
if ($cancel && confirm_sesskey()) {
\local_bbcomailing\manager::cancel_batch($batchcode);
\local_bbcomailing\event\batch_cancelled::create([
'context' => $context,
'other' => ['batchcode' => $batchcode],
])->trigger();
redirect($PAGE->url, get_string('batchcancelled', 'local_bbcomailing'));
}
echo $OUTPUT->header();
// Navigation tabs.
echo \local_bbcomailing\manager::render_tabs('manage');
$sends = \local_bbcomailing\manager::get_batch_sends($batchcode);
if (empty($sends)) {
echo html_writer::tag('p', get_string('nodata', 'local_bbcomailing'));
} else {
// Check if any pending to show cancel button.
$haspending = false;
foreach ($sends as $send) {
if ($send->status == \local_bbcomailing\manager::STATUS_PENDING) {
$haspending = true;
break;
}
}
if ($haspending) {
$cancelurl = new moodle_url(
'/local/bbcomailing/batch.php',
['batchcode' => $batchcode, 'cancel' => 1, 'sesskey' => sesskey()]
);
echo html_writer::div(
$OUTPUT->single_button($cancelurl, get_string('cancelbatch', 'local_bbcomailing')),
'mb-3'
);
}
$statusstrings = [
\local_bbcomailing\manager::STATUS_PENDING => get_string('status_pending', 'local_bbcomailing'),
\local_bbcomailing\manager::STATUS_SENT => get_string('status_sent', 'local_bbcomailing'),
\local_bbcomailing\manager::STATUS_FAILED => get_string('status_failed', 'local_bbcomailing'),
\local_bbcomailing\manager::STATUS_CANCELLED => get_string('status_cancelled', 'local_bbcomailing'),
\local_bbcomailing\manager::STATUS_UNSUBSCRIBED => get_string('status_unsubscribed', 'local_bbcomailing'),
\local_bbcomailing\manager::STATUS_SUPPRESSED => get_string('status_suppressed', 'local_bbcomailing'),
];
$table = new html_table();
$table->head = [
get_string('email', 'local_bbcomailing'),
get_string('fields', 'local_bbcomailing'),
get_string('status', 'local_bbcomailing'),
get_string('sendtime', 'local_bbcomailing'),
get_string('viewtime', 'local_bbcomailing'),
];
$table->attributes['class'] = 'generaltable';
foreach ($sends as $send) {
$fieldsdata = $send->fields ? json_decode($send->fields, true) : [];
$fieldstext = [];
foreach ($fieldsdata as $k => $v) {
$fieldstext[] = s($k) . ': ' . s($v);
}
$table->data[] = [
s($send->email),
implode(', ', $fieldstext),
$statusstrings[$send->status] ?? $send->status,
$send->sendtime ? userdate($send->sendtime) : get_string('notsent', 'local_bbcomailing'),
$send->viewtime ? userdate($send->viewtime) : get_string('notviewed', 'local_bbcomailing'),
];
}
echo html_writer::table($table);
}
$indexurl = new moodle_url('/local/bbcomailing/index.php');
echo html_writer::div(
html_writer::link($indexurl, get_string('back', 'local_bbcomailing'), ['class' => 'btn btn-secondary']),
'mt-3'
);
echo $OUTPUT->footer();