|
| 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 | +namespace tool_emailutils\reportbuilder\local\entities; |
| 18 | + |
| 19 | +use lang_string; |
| 20 | +use core_reportbuilder\local\entities\base; |
| 21 | +use core_reportbuilder\local\filters\date; |
| 22 | +use core_reportbuilder\local\filters\text; |
| 23 | +use core_reportbuilder\local\helpers\format; |
| 24 | +use core_reportbuilder\local\report\column; |
| 25 | +use core_reportbuilder\local\report\filter; |
| 26 | + |
| 27 | +/** |
| 28 | + * SES account level suppression list entity class class implementation. |
| 29 | + * |
| 30 | + * Defines all the columns and filters that can be added to reports that use this entity. |
| 31 | + * |
| 32 | + * @package tool_emailutils |
| 33 | + * @author Benjamin Walker <[email protected]> |
| 34 | + * @copyright Catalyst IT 2024 |
| 35 | + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
| 36 | + * |
| 37 | + */ |
| 38 | +class suppressed_email extends base { |
| 39 | + |
| 40 | + /** |
| 41 | + * Database tables that this entity uses |
| 42 | + * |
| 43 | + * @return string[] |
| 44 | + */ |
| 45 | + protected function get_default_tables(): array { |
| 46 | + return [ |
| 47 | + 'tool_emailutils_suppression', |
| 48 | + ]; |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * The default title for this entity |
| 53 | + * |
| 54 | + * @return lang_string |
| 55 | + */ |
| 56 | + protected function get_default_entity_title(): lang_string { |
| 57 | + return new lang_string('aws_suppressionlist', 'tool_emailutils'); |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * Initialize the entity |
| 62 | + * |
| 63 | + * @return base |
| 64 | + */ |
| 65 | + public function initialise(): base { |
| 66 | + $columns = $this->get_all_columns(); |
| 67 | + foreach ($columns as $column) { |
| 68 | + $this->add_column($column); |
| 69 | + } |
| 70 | + |
| 71 | + $filters = $this->get_all_filters(); |
| 72 | + foreach ($filters as $filter) { |
| 73 | + $this->add_filter($filter); |
| 74 | + $this->add_condition($filter); |
| 75 | + } |
| 76 | + |
| 77 | + return $this; |
| 78 | + } |
| 79 | + |
| 80 | + /** |
| 81 | + * Returns list of all available columns |
| 82 | + * |
| 83 | + * @return column[] |
| 84 | + */ |
| 85 | + protected function get_all_columns(): array { |
| 86 | + $tablealias = $this->get_table_alias('tool_emailutils_suppression'); |
| 87 | + |
| 88 | + // Email column. |
| 89 | + $columns[] = (new column( |
| 90 | + 'email', |
| 91 | + new lang_string('email'), |
| 92 | + $this->get_entity_name() |
| 93 | + )) |
| 94 | + ->add_joins($this->get_joins()) |
| 95 | + ->set_type(column::TYPE_TEXT) |
| 96 | + ->add_fields("{$tablealias}.email") |
| 97 | + ->set_is_sortable(true); |
| 98 | + |
| 99 | + // Reason column. |
| 100 | + $columns[] = (new column( |
| 101 | + 'reason', |
| 102 | + new lang_string('suppressionreason', 'tool_emailutils'), |
| 103 | + $this->get_entity_name() |
| 104 | + )) |
| 105 | + ->add_joins($this->get_joins()) |
| 106 | + ->set_type(column::TYPE_TEXT) |
| 107 | + ->add_fields("{$tablealias}.reason") |
| 108 | + ->set_is_sortable(true); |
| 109 | + |
| 110 | + // Created at column. |
| 111 | + $columns[] = (new column( |
| 112 | + 'created', |
| 113 | + new lang_string('suppressioncreated', 'tool_emailutils'), |
| 114 | + $this->get_entity_name() |
| 115 | + )) |
| 116 | + ->add_joins($this->get_joins()) |
| 117 | + ->set_type(column::TYPE_TIMESTAMP) |
| 118 | + ->add_fields("{$tablealias}.created_at") |
| 119 | + ->set_is_sortable(true) |
| 120 | + ->add_callback([format::class, 'userdate'], get_string('strftimedatetimeshortaccurate', 'core_langconfig')); |
| 121 | + |
| 122 | + return $columns; |
| 123 | + } |
| 124 | + |
| 125 | + /** |
| 126 | + * Return list of all available filters |
| 127 | + * |
| 128 | + * @return filter[] |
| 129 | + */ |
| 130 | + protected function get_all_filters(): array { |
| 131 | + $tablealias = $this->get_table_alias('tool_emailutils_suppression'); |
| 132 | + |
| 133 | + // Email filter. |
| 134 | + $filters[] = (new filter( |
| 135 | + text::class, |
| 136 | + 'email', |
| 137 | + new lang_string('email'), |
| 138 | + $this->get_entity_name(), |
| 139 | + "{$tablealias}.email" |
| 140 | + )) |
| 141 | + ->add_joins($this->get_joins()); |
| 142 | + |
| 143 | + // Reason filter. |
| 144 | + $filters[] = (new filter( |
| 145 | + text::class, |
| 146 | + 'reason', |
| 147 | + new lang_string('suppressionreason', 'tool_emailutils'), |
| 148 | + $this->get_entity_name(), |
| 149 | + "{$tablealias}.reason" |
| 150 | + )) |
| 151 | + ->add_joins($this->get_joins()); |
| 152 | + |
| 153 | + // Created at filter. |
| 154 | + $filters[] = (new filter( |
| 155 | + date::class, |
| 156 | + 'created', |
| 157 | + new lang_string('suppressioncreated', 'tool_emailutils'), |
| 158 | + $this->get_entity_name(), |
| 159 | + "{$tablealias}.created" |
| 160 | + )) |
| 161 | + ->add_joins($this->get_joins()) |
| 162 | + ->set_limited_operators([ |
| 163 | + date::DATE_ANY, |
| 164 | + date::DATE_RANGE, |
| 165 | + date::DATE_PREVIOUS, |
| 166 | + date::DATE_CURRENT, |
| 167 | + ]); |
| 168 | + |
| 169 | + return $filters; |
| 170 | + } |
| 171 | +} |
0 commit comments