Skip to content

Commit daf2bd5

Browse files
committed
Add bootstrap warnings to bounces report #80
1 parent 7a1cad0 commit daf2bd5

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

classes/reportbuilder/local/entities/email_bounce.php

+15-3
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
namespace tool_emailutils\reportbuilder\local\entities;
1818

1919
use lang_string;
20+
use core\output\html_writer;
2021
use core_reportbuilder\local\entities\base;
2122
use core_reportbuilder\local\filters\number;
2223
use core_reportbuilder\local\report\column;
2324
use core_reportbuilder\local\report\filter;
25+
use tool_emailutils\helper;
2426

2527
/**
2628
* Email bounce entity class class implementation.
@@ -102,7 +104,13 @@ protected function get_all_columns(): array {
102104
->add_joins($this->get_joins())
103105
->set_type(column::TYPE_INTEGER)
104106
->add_field($DB->sql_cast_char2int("{$tablealias}.value"), 'bounces')
105-
->set_is_sortable(true);
107+
->set_is_sortable(true)
108+
->add_callback(function(int $value): string {
109+
if ($value >= helper::get_min_bounces()) {
110+
return html_writer::span($value, 'alert alert-danger p-2');
111+
}
112+
return $value;
113+
});
106114

107115
// Emails send column.
108116
$columns[] = (new column(
@@ -114,7 +122,6 @@ protected function get_all_columns(): array {
114122
->set_type(column::TYPE_INTEGER)
115123
->add_field($DB->sql_cast_char2int("{$sendalias}.value"), 'send')
116124
->set_is_sortable(true);
117-
118125
// Bounce ratio column.
119126
$bouncesql = $DB->sql_cast_char2real("{$tablealias}.value");
120127
$sendsql = $DB->sql_cast_char2real("{$sendalias}.value");
@@ -127,8 +134,13 @@ protected function get_all_columns(): array {
127134
->set_type(column::TYPE_FLOAT)
128135
->add_field("CASE WHEN $sendsql = 0 THEN NULL ELSE $bouncesql / $sendsql END", 'ratio')
129136
->set_is_sortable(true)
137+
->set_is_available(helper::use_bounce_ratio())
130138
->add_callback(function(?float $value): string {
131-
return format_float($value, 2);
139+
$float = format_float($value, 2);
140+
if ($value > helper::get_bounce_ratio()) {
141+
return html_writer::span($float, 'alert alert-danger p-2');
142+
}
143+
return $float;
132144
});
133145

134146
return $columns;

classes/reportbuilder/local/entities/notification_log.php

+13-1
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717
namespace tool_emailutils\reportbuilder\local\entities;
1818

1919
use lang_string;
20+
use core\output\html_writer;
2021
use core_reportbuilder\local\entities\base;
2122
use core_reportbuilder\local\filters\date;
2223
use core_reportbuilder\local\filters\text;
2324
use core_reportbuilder\local\helpers\format;
2425
use core_reportbuilder\local\report\column;
2526
use core_reportbuilder\local\report\filter;
27+
use tool_emailutils\sns_notification;
2628

2729
/**
2830
* Notification log list entity class class implementation.
@@ -116,7 +118,17 @@ protected function get_all_columns(): array {
116118
->add_joins($this->get_joins())
117119
->set_type(column::TYPE_TEXT)
118120
->add_fields("{$tablealias}.subtypes")
119-
->set_is_sortable(true);
121+
->set_is_sortable(true)
122+
->add_callback(function(?string $subtypes): string {
123+
if (empty($subtypes)) {
124+
return '';
125+
} else if (in_array($subtypes, sns_notification::BLOCK_IMMEDIATELY)) {
126+
return html_writer::span($subtypes, 'alert alert-danger p-2');
127+
} else if (in_array($subtypes, sns_notification::BLOCK_IMMEDIATELY)) {
128+
return html_writer::span($subtypes, 'alert alert-warning p-2');
129+
}
130+
return $subtypes;
131+
});
120132

121133
// Time column.
122134
$columns[] = (new column(

classes/reportbuilder/local/systemreports/email_bounces.php

+1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ protected function add_filters(): void {
132132
'user:fullname',
133133
'user:username',
134134
'user:email',
135+
'notification_log:subtypes',
135136
];
136137

137138
$this->add_filters_from_entities($filters);

0 commit comments

Comments
 (0)