PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 1.25.0
Independent Analytics – WordPress Analytics Plugin v1.25.0
2.15.5 2.15.4 2.15.3 2.15.2 2.15.1 2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 1.19.1 1.2 1.20.0 1.21.0 1.22.0 1.22.1 1.23.0 1.23.1 1.24.0 1.24.1 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.28.1 1.28.2 1.28.3 1.29.0 1.3 1.30.0 1.30.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0.0 2.0.1 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.10 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.11.9 2.12.0 2.12.1 2.12.2 2.13.1 2.13.2 2.13.5 2.13.6 2.14.0 2.14.1 2.14.2 2.14.4 2.14.6 2.14.7 2.14.8 2.14.9 2.2.0 2.2.1 2.3.1 2.3.2 2.4.2 2.4.3 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.1 2.7.2 2.7.3 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7
independent-analytics / IAWP / Filters.php
independent-analytics / IAWP Last commit date
AJAX 3 years ago Date_Range 3 years ago Interval 3 years ago Menu_Bar_Stats 3 years ago Migrations 3 years ago Models 3 years ago Queries 3 years ago Statistics 3 years ago Tables 3 years ago Utils 3 years ago Campaign_Builder.php 3 years ago Capability_Manager.php 3 years ago Chart.php 3 years ago Chart_Geo.php 3 years ago Chart_SVG.php 3 years ago Dashboard_Options.php 3 years ago Dashboard_Widget.php 3 years ago Email_Reports.php 3 years ago Filters.php 3 years ago Geo_Database.php 3 years ago Geo_Database_Download_Job.php 3 years ago Health_Check.php 3 years ago Illuminate_Builder.php 3 years ago Independent_Analytics.php 3 years ago Known_Referrers.php 3 years ago PDF.php 3 years ago Query.php 3 years ago Quick_Stats.php 3 years ago REST_API.php 3 years ago Real_Time.php 3 years ago Reset_Database.php 3 years ago Resource_Identifier.php 3 years ago Settings.php 3 years ago Sort_Configuration.php 3 years ago Track_Resource_Changes.php 3 years ago View.php 3 years ago View_Counter.php 3 years ago WP_Option_Cache_Bust.php 3 years ago WooCommerce_Order.php 3 years ago
Filters.php
226 lines
1 <?php
2
3 namespace IAWP_SCOPED\IAWP;
4
5 use IAWP_SCOPED\IAWP\Tables\Columns\Column;
6 use IAWP_SCOPED\IAWP\Utils\WordPress_Site_Date_Format_Pattern;
7 class Filters
8 {
9 public function get_filters_html(array $columns) : string
10 {
11 $opts = new Dashboard_Options();
12 \ob_start();
13 ?>
14 <div class="modal-parent"
15 data-controller="filters"
16 data-filters-filters-value="<?php
17 \esc_html_e(\json_encode($opts->filters()));
18 ?>"
19 >
20 <button id="filters-button" class="iawp-button ghost-white toolbar-button"
21 data-action="filters#toggleModal"
22 data-filters-target="modalButton"
23 >
24 <span class="dashicons dashicons-filter"></span>
25 <span class="iawp-label"><?php
26 echo ' ' . \esc_html__('Filter Rows', 'independent-analytics') . ' ';
27 ?></span>
28 <span class="count" data-filters-target="filterCount"></span>
29 </button>
30 <div id="modal-filters"
31 class="modal large"
32 data-filters-target="modal"
33 >
34 <div class="modal-inner">
35 <div class="title-small"><?php
36 \esc_html_e('Filters', 'independent-analytics');
37 ?></div>
38 <div id="filters" data-filters-target="filters" class="filters" data-filters="[]">
39 </div>
40 <template data-filters-target="blueprint">
41 <?php
42 echo $this->get_condition_html($columns);
43 ?>
44 </template>
45 <div>
46 <button id="add-condition" class="iawp-button text"
47 data-action="filters#addCondition"
48 >
49 <?php
50 \esc_html_e('+ Add another condition', 'independent-analytics');
51 ?>
52 </button>
53 </div>
54 <div class="actions">
55 <button id="filters-apply" class="iawp-button purple"
56 data-action="filters#apply"
57 >
58 <?php
59 \esc_html_e('Apply', 'independent-analytics');
60 ?>
61 </button>
62 <button id="filters-reset" class="iawp-button ghost-purple"
63 data-action="filters#reset"
64 data-filters-target="reset"
65 disabled
66 >
67 <?php
68 \esc_html_e('Reset', 'independent-analytics');
69 ?>
70 </button>
71 </div>
72 </div>
73 </div>
74 </div><?php
75 $html = \ob_get_contents();
76 \ob_end_clean();
77 return $html;
78 }
79 public function get_condition_html(array $columns)
80 {
81 \ob_start();
82 ?>
83 <div class="condition" data-filters-target="condition">
84 <div class="input-group">
85 <div>
86 <?php
87 echo self::get_inclusion_selects();
88 ?>
89 </div>
90 <div>
91 <?php
92 self::get_column_select($columns);
93 ?>
94 </div>
95 <div class="operator-select-container">
96 <?php
97 echo self::get_all_operator_selects();
98 ?>
99 </div>
100 <div class="operand-field-container">
101 <?php
102 echo self::get_all_operand_fields($columns);
103 ?>
104 </div>
105 </div>
106 <button class="delete-button" data-action="filters#removeCondition">
107 <span class="dashicons dashicons-no"></span></button>
108 </div>
109 <?php
110 $html = \ob_get_contents();
111 \ob_end_clean();
112 return $html;
113 }
114 private function get_inclusion_selects()
115 {
116 $html = '<select class="filters-include" data-filters-target="inclusion">';
117 $html .= '<option value="include">' . \esc_html__('Include', 'independent-analytics') . '</option>';
118 $html .= '<option value="exclude">' . \esc_html__('Exclude', 'independent-analytics') . '</option>';
119 $html .= '</select>';
120 return $html;
121 }
122 /**
123 * @param Column[] $columns
124 *
125 * @return void
126 */
127 private function get_column_select(array $columns)
128 {
129 ?>
130 <select class="filters-column" data-filters-target="column"
131 data-action="filters#columnSelect"
132 >
133 <option value="">
134 <?php
135 \esc_html_e('Choose a column', 'independent-analytics');
136 ?>
137 </option>
138 <?php
139 foreach ($columns as $column) {
140 ?>
141 <?php
142 if ($column->requires_woocommerce() && !\IAWP_SCOPED\iawp_using_woocommerce()) {
143 continue;
144 }
145 ?>
146 <option value="<?php
147 \esc_attr_e($column->id());
148 ?>"
149 data-type="<?php
150 \esc_attr_e($column->type());
151 ?>"
152 >
153 <?php
154 \esc_html_e($column->label());
155 ?>
156 </option>
157 <?php
158 }
159 ?>
160 </select>
161 <?php
162 }
163 private function get_all_operator_selects()
164 {
165 $html = '';
166 foreach (self::get_data_types() as $data_type) {
167 $html .= '<select data-filters-target="operator" data-type="' . \esc_attr($data_type) . '" data-testid="' . \esc_attr($data_type) . '-operator">';
168 foreach (self::get_operators($data_type) as $key => $value) {
169 $html .= '<option value="' . \esc_attr($key) . '">' . \esc_html($value) . '</option>';
170 }
171 $html .= '</select>';
172 }
173 return $html;
174 }
175 private function get_all_operand_fields(array $columns)
176 {
177 $html = '';
178 foreach ($columns as $column) {
179 switch ($column->type()) {
180 case 'string':
181 $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()) . '" />';
182 break;
183 case 'int':
184 $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()) . '" />';
185 break;
186 case 'date':
187 $html .= '<input type="text"
188 data-filters-target="operand"
189 data-action="keydown->filters#operandKeyDown filters#operandChange"
190 data-column="' . \esc_attr($column->id()) . '"
191 data-controller="easepick"
192 data-css="' . \esc_url(\IAWP_SCOPED\iawp_url_to('dist/styles/easepick/datepicker.css')) . '" data-dow="' . \absint(\IAWP_SCOPED\iawp()->get_option('iawp_dow', 1)) . '"
193 data-format="' . \esc_attr(WordPress_Site_Date_Format_Pattern::for_javascript()) . '"
194 data-testid="' . \esc_attr($column->id()) . '-operand" />';
195 break;
196 case 'select':
197 $html .= '<select data-filters-target="operand" data-column="' . \esc_attr($column->id()) . '" data-testid="' . \esc_attr($column->id()) . '-operand">';
198 foreach ($column->options() as $option) {
199 $html .= '<option value="' . \esc_attr($option[0]) . '">' . \esc_html($option[1]) . '</option>';
200 }
201 $html .= '</select>';
202 break;
203 }
204 }
205 return $html;
206 }
207 private function get_data_types()
208 {
209 return ['string', 'int', 'date', 'select'];
210 }
211 private function get_operators(string $data_type)
212 {
213 if ($data_type == 'string') {
214 return ['contains' => \esc_html__('Contains', 'independent-analytics'), 'exact' => \esc_html__('Exactly matches', 'independent-analytics')];
215 } elseif ($data_type == 'int') {
216 return ['greater' => \esc_html__('Greater than', 'independent-analytics'), 'lesser' => \esc_html__('Less than', 'independent-analytics'), 'equal' => \esc_html__('Equal to', 'independent-analytics')];
217 } elseif ($data_type == 'select') {
218 return ['is' => \esc_html__('Is', 'independent-analytics'), 'isnt' => \esc_html__('Isn\'t', 'independent-analytics')];
219 } elseif ($data_type == 'date') {
220 return ['before' => \esc_html__('Before', 'independent-analytics'), 'after' => \esc_html__('After', 'independent-analytics'), 'on' => \esc_html__('On', 'independent-analytics')];
221 } else {
222 return null;
223 }
224 }
225 }
226