AJAX
1 year ago
Admin_Page
1 year ago
Custom_WordPress_Columns
2 years ago
Data_Pruning
1 year ago
Date_Picker
1 year ago
Date_Range
1 year ago
Ecommerce
1 year ago
Email_Reports
1 year ago
Filter_Lists
2 years ago
Form_Submissions
1 year ago
Interval
2 years ago
Menu_Bar_Stats
1 year ago
Migrations
1 year ago
Models
1 year ago
Public_API
2 years ago
Rows
1 year ago
Statistics
1 year ago
Tables
1 year ago
Utils
1 year ago
Campaign_Builder.php
2 years ago
Capability_Manager.php
1 year ago
Chart.php
1 year ago
Chart_Geo.php
1 year ago
Cron_Job.php
1 year ago
Cron_Job_Autoloader.php
1 year ago
Cron_Manager.php
2 years ago
Current_Traffic_Finder.php
2 years ago
Dashboard_Options.php
2 years ago
Dashboard_Widget.php
2 years ago
Database.php
2 years ago
Database_Manager.php
2 years ago
Empty_Report_Option.php
2 years ago
Env.php
1 year ago
Filters.php
1 year ago
Geo_Database_Background_Job.php
2 years ago
Geo_Database_Manager.php
1 year ago
Geoposition.php
2 years ago
Icon_Directory.php
2 years ago
Icon_Directory_Factory.php
2 years ago
Illuminate_Builder.php
1 year ago
Independent_Analytics.php
1 year ago
Interrupt.php
1 year ago
Known_Referrers.php
2 years ago
Patch.php
1 year ago
Plugin_Conflict_Detector.php
1 year ago
Plugin_Group.php
1 year ago
Plugin_Group_Option.php
2 years ago
Query.php
1 year ago
Query_Taps.php
1 year ago
Quick_Stats.php
2 years ago
REST_API.php
1 year ago
Real_Time.php
1 year ago
Report.php
2 years ago
Report_Finder.php
2 years ago
Report_Options_Parser.php
1 year ago
Resource_Identifier.php
1 year ago
Settings.php
1 year ago
Sort_Configuration.php
2 years ago
Track_Resource_Changes.php
2 years ago
View.php
2 years ago
View_Counter.php
1 year ago
Visitors_Over_Time_Finder.php
2 years ago
WP_Option_Cache_Bust.php
2 years ago
Filters.php
250 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP; |
| 4 | |
| 5 | use IAWP\Tables\Columns\Column; |
| 6 | use IAWP\Utils\WordPress_Site_Date_Format_Pattern; |
| 7 | /** @internal */ |
| 8 | class Filters |
| 9 | { |
| 10 | public function get_filters_html(array $columns) : string |
| 11 | { |
| 12 | $opts = \IAWP\Dashboard_Options::getInstance(); |
| 13 | \ob_start(); |
| 14 | ?> |
| 15 | <div class="modal-parent filters" |
| 16 | data-controller="filters" |
| 17 | data-filters-filters-value="<?php |
| 18 | echo \esc_attr(\json_encode($opts->filters())); |
| 19 | ?>" |
| 20 | > |
| 21 | <span class="dashicons dashicons-filter"></span> |
| 22 | <div id="filter-condition-buttons" data-filters-target="conditionButtons" class="filter-condition-buttons"> |
| 23 | <?php |
| 24 | echo $this->condition_buttons_html($opts->filters()); |
| 25 | ?> |
| 26 | </div> |
| 27 | <button id="filters-button" class="filters-button" |
| 28 | data-action="filters#toggleModal" |
| 29 | data-filters-target="modalButton" |
| 30 | > |
| 31 | <span class="iawp-label"><?php |
| 32 | \esc_html_e('+ Add Filter', 'independent-analytics'); |
| 33 | ?></span> |
| 34 | </button> |
| 35 | <div id="modal-filters" |
| 36 | class="iawp-modal large" |
| 37 | data-filters-target="modal" |
| 38 | > |
| 39 | <div class="modal-inner"> |
| 40 | <div class="title-small"> |
| 41 | <?php |
| 42 | \esc_html_e('Filters', 'independent-analytics'); |
| 43 | ?> |
| 44 | <span data-filters-target="spinner" class="dashicons dashicons-update spin hidden"></span> |
| 45 | </div> |
| 46 | <div id="filters" data-filters-target="filters" class="filters" data-filters="[]"> |
| 47 | </div> |
| 48 | <template data-filters-target="blueprint"> |
| 49 | <?php |
| 50 | echo $this->get_condition_html($columns); |
| 51 | ?> |
| 52 | </template> |
| 53 | <div> |
| 54 | <button id="add-condition" class="iawp-text-button" |
| 55 | data-action="filters#addCondition" |
| 56 | > |
| 57 | <?php |
| 58 | \esc_html_e('+ Add another condition', 'independent-analytics'); |
| 59 | ?> |
| 60 | </button> |
| 61 | </div> |
| 62 | <div class="actions"> |
| 63 | <button id="filters-apply" class="iawp-button purple" |
| 64 | data-action="filters#apply" |
| 65 | > |
| 66 | <?php |
| 67 | \esc_html_e('Apply', 'independent-analytics'); |
| 68 | ?> |
| 69 | </button> |
| 70 | <button id="filters-reset" class="iawp-button ghost-purple" |
| 71 | data-action="filters#reset" |
| 72 | data-filters-target="reset" |
| 73 | disabled |
| 74 | > |
| 75 | <?php |
| 76 | \esc_html_e('Reset', 'independent-analytics'); |
| 77 | ?> |
| 78 | </button> |
| 79 | </div> |
| 80 | </div> |
| 81 | </div> |
| 82 | </div><?php |
| 83 | $html = \ob_get_contents(); |
| 84 | \ob_end_clean(); |
| 85 | return $html; |
| 86 | } |
| 87 | public function get_condition_html(array $columns) |
| 88 | { |
| 89 | \ob_start(); |
| 90 | ?> |
| 91 | <div class="condition" data-filters-target="condition"> |
| 92 | <div class="input-group"> |
| 93 | <div> |
| 94 | <?php |
| 95 | echo self::get_inclusion_selects(); |
| 96 | ?> |
| 97 | </div> |
| 98 | <div> |
| 99 | <?php |
| 100 | self::get_column_select($columns); |
| 101 | ?> |
| 102 | </div> |
| 103 | <div class="operator-select-container"> |
| 104 | <?php |
| 105 | echo self::get_all_operator_selects(); |
| 106 | ?> |
| 107 | </div> |
| 108 | <div class="operand-field-container"> |
| 109 | <?php |
| 110 | echo self::get_all_operand_fields($columns); |
| 111 | ?> |
| 112 | </div> |
| 113 | </div> |
| 114 | <button class="delete-button" data-action="filters#removeCondition"> |
| 115 | <span class="dashicons dashicons-no"></span></button> |
| 116 | </div> |
| 117 | <?php |
| 118 | $html = \ob_get_contents(); |
| 119 | \ob_end_clean(); |
| 120 | return $html; |
| 121 | } |
| 122 | public function condition_buttons_html(array $filters) : string |
| 123 | { |
| 124 | \ob_start(); |
| 125 | for ($i = 0; $i < \count($filters); $i++) { |
| 126 | if ($i == 2) { |
| 127 | ?> |
| 128 | <button class="filters-condition-button" |
| 129 | data-action="filters#toggleModal" |
| 130 | data-filters-target="modalButton"><?php |
| 131 | \printf(\esc_html__('+%d More', 'independent-analytics'), \count($filters) - 2); |
| 132 | ?></button><?php |
| 133 | break; |
| 134 | } |
| 135 | ?> |
| 136 | <button class="filters-condition-button" |
| 137 | data-action="filters#toggleModal" |
| 138 | data-filters-target="modalButton"><?php |
| 139 | echo \wp_kses_post($filters[$i]->html_description()); |
| 140 | ?></button> |
| 141 | <?php |
| 142 | } |
| 143 | $html = \ob_get_contents(); |
| 144 | \ob_end_clean(); |
| 145 | return $html; |
| 146 | } |
| 147 | private function get_inclusion_selects() |
| 148 | { |
| 149 | $html = '<select class="filters-include" data-filters-target="inclusion">'; |
| 150 | $html .= '<option value="include">' . \esc_html__('Include', 'independent-analytics') . '</option>'; |
| 151 | $html .= '<option value="exclude">' . \esc_html__('Exclude', 'independent-analytics') . '</option>'; |
| 152 | $html .= '</select>'; |
| 153 | return $html; |
| 154 | } |
| 155 | /** |
| 156 | * @param Column[] $columns |
| 157 | * |
| 158 | * @return void |
| 159 | */ |
| 160 | private function get_column_select(array $columns) |
| 161 | { |
| 162 | $plugin_groups = \IAWP\Plugin_Group::get_plugin_groups(); |
| 163 | $column_sections = []; |
| 164 | foreach ($columns as $column) { |
| 165 | $plugin_group_id = $column->plugin_group(); |
| 166 | $section_name = ''; |
| 167 | $plugin_group = null; |
| 168 | foreach ($plugin_groups as $a_plugin_group) { |
| 169 | if ($a_plugin_group->id() === $plugin_group_id) { |
| 170 | $section_name = $a_plugin_group->name(); |
| 171 | $plugin_group = $a_plugin_group; |
| 172 | } |
| 173 | } |
| 174 | if (!$plugin_group->has_active_group_plugins()) { |
| 175 | continue; |
| 176 | } |
| 177 | if (!\is_null($column->plugin_group_header())) { |
| 178 | $section_name = $plugin_group->name() . ' - ' . $column->plugin_group_header(); |
| 179 | } |
| 180 | if (!\array_key_exists($section_name, $column_sections)) { |
| 181 | $column_sections[$section_name] = ['plugin_group' => $plugin_group, 'columns' => []]; |
| 182 | } |
| 183 | \array_push($column_sections[$section_name]['columns'], $column); |
| 184 | } |
| 185 | echo \IAWPSCOPED\iawp_blade()->run('partials.filter-column-select', ['column_sections' => $column_sections]); |
| 186 | } |
| 187 | private function get_all_operator_selects() |
| 188 | { |
| 189 | $html = ''; |
| 190 | foreach (self::get_data_types() as $data_type) { |
| 191 | $html .= '<select data-filters-target="operator" data-type="' . \esc_attr($data_type) . '" data-testid="' . \esc_attr($data_type) . '-operator">'; |
| 192 | foreach (self::get_operators($data_type) as $key => $value) { |
| 193 | $html .= '<option value="' . \esc_attr($key) . '">' . \esc_html($value) . '</option>'; |
| 194 | } |
| 195 | $html .= '</select>'; |
| 196 | } |
| 197 | return $html; |
| 198 | } |
| 199 | private function get_all_operand_fields(array $columns) |
| 200 | { |
| 201 | $html = ''; |
| 202 | foreach ($columns as $column) { |
| 203 | switch ($column->type()) { |
| 204 | case 'string': |
| 205 | $html .= '<input data-filters-target="operand" data-action="keydown->filters#operandKeyDown filters#operandChange" data-column="' . \esc_attr($column->id()) . '" type="text" data-testid="' . \esc_attr($column->id()) . '-operand" placeholder="' . \esc_attr($column->filter_placeholder()) . '" />'; |
| 206 | break; |
| 207 | case 'int': |
| 208 | $html .= '<input data-filters-target="operand" data-action="keydown->filters#operandKeyDown filters#operandChange" data-column="' . \esc_attr($column->id()) . '" type="number" data-testid="' . \esc_attr($column->id()) . '-operand" placeholder="' . \esc_attr($column->filter_placeholder()) . '" />'; |
| 209 | break; |
| 210 | case 'date': |
| 211 | $html .= '<input type="text" |
| 212 | data-filters-target="operand" |
| 213 | data-action="keydown->filters#operandKeyDown filters#operandChange" |
| 214 | data-column="' . \esc_attr($column->id()) . '" |
| 215 | data-controller="easepick" |
| 216 | data-css="' . \esc_url(\IAWPSCOPED\iawp_url_to('dist/styles/easepick/datepicker.css')) . '" data-dow="' . \absint(\IAWPSCOPED\iawp()->get_option('iawp_dow', 1)) . '" |
| 217 | data-format="' . \esc_attr(WordPress_Site_Date_Format_Pattern::for_javascript()) . '" |
| 218 | data-testid="' . \esc_attr($column->id()) . '-operand" />'; |
| 219 | break; |
| 220 | case 'select': |
| 221 | $html .= '<select data-filters-target="operand" data-column="' . \esc_attr($column->id()) . '" data-testid="' . \esc_attr($column->id()) . '-operand">'; |
| 222 | foreach ($column->options() as $option) { |
| 223 | $html .= '<option value="' . \esc_attr($option[0]) . '">' . \esc_html($option[1]) . '</option>'; |
| 224 | } |
| 225 | $html .= '</select>'; |
| 226 | break; |
| 227 | } |
| 228 | } |
| 229 | return $html; |
| 230 | } |
| 231 | private function get_data_types() |
| 232 | { |
| 233 | return ['string', 'int', 'date', 'select']; |
| 234 | } |
| 235 | private function get_operators(string $data_type) |
| 236 | { |
| 237 | if ($data_type == 'string') { |
| 238 | return ['contains' => \esc_html__('Contains', 'independent-analytics'), 'exact' => \esc_html__('Exactly matches', 'independent-analytics')]; |
| 239 | } elseif ($data_type == 'int') { |
| 240 | return ['greater' => \esc_html__('Greater than', 'independent-analytics'), 'lesser' => \esc_html__('Less than', 'independent-analytics'), 'equal' => \esc_html__('Equal to', 'independent-analytics')]; |
| 241 | } elseif ($data_type == 'select') { |
| 242 | return ['is' => \esc_html__('Is', 'independent-analytics'), 'isnt' => \esc_html__('Isn\'t', 'independent-analytics')]; |
| 243 | } elseif ($data_type == 'date') { |
| 244 | return ['before' => \esc_html__('Before', 'independent-analytics'), 'after' => \esc_html__('After', 'independent-analytics'), 'on' => \esc_html__('On', 'independent-analytics')]; |
| 245 | } else { |
| 246 | return null; |
| 247 | } |
| 248 | } |
| 249 | } |
| 250 |