Skip to content

Commit

Permalink
Add bootstrap warnings to bounces report #80
Browse files Browse the repository at this point in the history
  • Loading branch information
bwalkerl committed Nov 29, 2024
1 parent 7a1cad0 commit daf2bd5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
18 changes: 15 additions & 3 deletions classes/reportbuilder/local/entities/email_bounce.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(
Expand All @@ -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");
Expand All @@ -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;
Expand Down
14 changes: 13 additions & 1 deletion classes/reportbuilder/local/entities/notification_log.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ protected function add_filters(): void {
'user:fullname',
'user:username',
'user:email',
'notification_log:subtypes',
];

$this->add_filters_from_entities($filters);
Expand Down

0 comments on commit daf2bd5

Please sign in to comment.