From daf2bd5b42228b498d64e8e60397cacd27632e0a Mon Sep 17 00:00:00 2001 From: Benjamin Walker Date: Fri, 29 Nov 2024 12:11:39 +1000 Subject: [PATCH] Add bootstrap warnings to bounces report #80 --- .../local/entities/email_bounce.php | 18 +++++++++++++++--- .../local/entities/notification_log.php | 14 +++++++++++++- .../local/systemreports/email_bounces.php | 1 + 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/classes/reportbuilder/local/entities/email_bounce.php b/classes/reportbuilder/local/entities/email_bounce.php index be394ff..044a2b6 100644 --- a/classes/reportbuilder/local/entities/email_bounce.php +++ b/classes/reportbuilder/local/entities/email_bounce.php @@ -17,10 +17,12 @@ namespace tool_emailutils\reportbuilder\local\entities; use lang_string; +use core\output\html_writer; use core_reportbuilder\local\entities\base; use core_reportbuilder\local\filters\number; use core_reportbuilder\local\report\column; use core_reportbuilder\local\report\filter; +use tool_emailutils\helper; /** * Email bounce entity class class implementation. @@ -102,7 +104,13 @@ protected function get_all_columns(): array { ->add_joins($this->get_joins()) ->set_type(column::TYPE_INTEGER) ->add_field($DB->sql_cast_char2int("{$tablealias}.value"), 'bounces') - ->set_is_sortable(true); + ->set_is_sortable(true) + ->add_callback(function(int $value): string { + if ($value >= helper::get_min_bounces()) { + return html_writer::span($value, 'alert alert-danger p-2'); + } + return $value; + }); // Emails send column. $columns[] = (new column( @@ -114,7 +122,6 @@ protected function get_all_columns(): array { ->set_type(column::TYPE_INTEGER) ->add_field($DB->sql_cast_char2int("{$sendalias}.value"), 'send') ->set_is_sortable(true); - // Bounce ratio column. $bouncesql = $DB->sql_cast_char2real("{$tablealias}.value"); $sendsql = $DB->sql_cast_char2real("{$sendalias}.value"); @@ -127,8 +134,13 @@ protected function get_all_columns(): array { ->set_type(column::TYPE_FLOAT) ->add_field("CASE WHEN $sendsql = 0 THEN NULL ELSE $bouncesql / $sendsql END", 'ratio') ->set_is_sortable(true) + ->set_is_available(helper::use_bounce_ratio()) ->add_callback(function(?float $value): string { - return format_float($value, 2); + $float = format_float($value, 2); + if ($value > helper::get_bounce_ratio()) { + return html_writer::span($float, 'alert alert-danger p-2'); + } + return $float; }); return $columns; diff --git a/classes/reportbuilder/local/entities/notification_log.php b/classes/reportbuilder/local/entities/notification_log.php index 1f2fc29..70929c2 100644 --- a/classes/reportbuilder/local/entities/notification_log.php +++ b/classes/reportbuilder/local/entities/notification_log.php @@ -17,12 +17,14 @@ namespace tool_emailutils\reportbuilder\local\entities; use lang_string; +use core\output\html_writer; use core_reportbuilder\local\entities\base; use core_reportbuilder\local\filters\date; use core_reportbuilder\local\filters\text; use core_reportbuilder\local\helpers\format; use core_reportbuilder\local\report\column; use core_reportbuilder\local\report\filter; +use tool_emailutils\sns_notification; /** * Notification log list entity class class implementation. @@ -116,7 +118,17 @@ protected function get_all_columns(): array { ->add_joins($this->get_joins()) ->set_type(column::TYPE_TEXT) ->add_fields("{$tablealias}.subtypes") - ->set_is_sortable(true); + ->set_is_sortable(true) + ->add_callback(function(?string $subtypes): string { + if (empty($subtypes)) { + return ''; + } else if (in_array($subtypes, sns_notification::BLOCK_IMMEDIATELY)) { + return html_writer::span($subtypes, 'alert alert-danger p-2'); + } else if (in_array($subtypes, sns_notification::BLOCK_IMMEDIATELY)) { + return html_writer::span($subtypes, 'alert alert-warning p-2'); + } + return $subtypes; + }); // Time column. $columns[] = (new column( diff --git a/classes/reportbuilder/local/systemreports/email_bounces.php b/classes/reportbuilder/local/systemreports/email_bounces.php index b5c3b0c..d19fbb5 100644 --- a/classes/reportbuilder/local/systemreports/email_bounces.php +++ b/classes/reportbuilder/local/systemreports/email_bounces.php @@ -132,6 +132,7 @@ protected function add_filters(): void { 'user:fullname', 'user:username', 'user:email', + 'notification_log:subtypes', ]; $this->add_filters_from_entities($filters);