PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 1.30.0
Independent Analytics – WordPress Analytics Plugin v1.30.0
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 2 years ago Date_Range 2 years ago Interval 3 years ago Menu_Bar_Stats 2 years ago Migrations 2 years ago Models 2 years ago Queries 2 years ago Statistics 2 years ago Tables 2 years ago Utils 2 years ago Campaign_Builder.php 2 years ago Capability_Manager.php 3 years ago Chart.php 3 years ago Chart_Geo.php 2 years ago Chart_SVG.php 3 years ago City_To_Country_Converter.php 3 years ago Dashboard_Options.php 2 years ago Dashboard_Widget.php 3 years ago Email_Chart.php 2 years ago Email_Reports.php 2 years ago Env.php 2 years ago Filters.php 2 years ago Geo_Database_Background_Job.php 2 years ago Geo_Database_Downloader.php 2 years ago Geoposition.php 2 years ago Icon_Directory.php 2 years ago Icon_Directory_Factory.php 2 years ago Illuminate_Builder.php 3 years ago Independent_Analytics.php 2 years ago Interrupt.php 2 years ago Known_Referrers.php 3 years ago Plugin_Conflict_Detector.php 2 years ago Query.php 2 years ago Quick_Stats.php 2 years ago REST_API.php 2 years ago Real_Time.php 2 years ago Reset_Database.php 3 years ago Resource_Identifier.php 3 years ago Settings.php 2 years ago Sort_Configuration.php 3 years ago Track_Resource_Changes.php 3 years ago View.php 2 years ago View_Counter.php 2 years ago WP_Option_Cache_Bust.php 2 years ago WooCommerce_Order.php 2 years ago
Filters.php
233 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 private $label;
10 public function __construct(string $label)
11 {
12 $this->label = $label;
13 }
14 public function get_filters_html(array $columns) : string
15 {
16 $opts = new Dashboard_Options();
17 \ob_start();
18 ?>
19 <div class="modal-parent"
20 data-controller="filters"
21 data-filters-filters-value="<?php
22 \esc_html_e(\json_encode($opts->filters()));
23 ?>"
24 >
25 <button id="filters-button" class="iawp-button ghost-white toolbar-button"
26 data-action="filters#toggleModal"
27 data-filters-target="modalButton"
28 >
29 <span class="dashicons dashicons-filter"></span>
30 <span class="iawp-label"><?php
31 echo ' ' . \esc_html__('Filter', 'independent-analytics') . ' ';
32 ?><span data-filters-target="groupName"><?php
33 echo \esc_html($this->label);
34 ?></span></span>
35 <span class="count" data-filters-target="filterCount"></span>
36 </button>
37 <div id="modal-filters"
38 class="modal large"
39 data-filters-target="modal"
40 >
41 <div class="modal-inner">
42 <div class="title-small"><?php
43 \esc_html_e('Filters', 'independent-analytics');
44 ?></div>
45 <div id="filters" data-filters-target="filters" class="filters" data-filters="[]">
46 </div>
47 <template data-filters-target="blueprint">
48 <?php
49 echo $this->get_condition_html($columns);
50 ?>
51 </template>
52 <div>
53 <button id="add-condition" class="iawp-button text"
54 data-action="filters#addCondition"
55 >
56 <?php
57 \esc_html_e('+ Add another condition', 'independent-analytics');
58 ?>
59 </button>
60 </div>
61 <div class="actions">
62 <button id="filters-apply" class="iawp-button purple"
63 data-action="filters#apply"
64 >
65 <?php
66 \esc_html_e('Apply', 'independent-analytics');
67 ?>
68 </button>
69 <button id="filters-reset" class="iawp-button ghost-purple"
70 data-action="filters#reset"
71 data-filters-target="reset"
72 disabled
73 >
74 <?php
75 \esc_html_e('Reset', 'independent-analytics');
76 ?>
77 </button>
78 </div>
79 </div>
80 </div>
81 </div><?php
82 $html = \ob_get_contents();
83 \ob_end_clean();
84 return $html;
85 }
86 public function get_condition_html(array $columns)
87 {
88 \ob_start();
89 ?>
90 <div class="condition" data-filters-target="condition">
91 <div class="input-group">
92 <div>
93 <?php
94 echo self::get_inclusion_selects();
95 ?>
96 </div>
97 <div>
98 <?php
99 self::get_column_select($columns);
100 ?>
101 </div>
102 <div class="operator-select-container">
103 <?php
104 echo self::get_all_operator_selects();
105 ?>
106 </div>
107 <div class="operand-field-container">
108 <?php
109 echo self::get_all_operand_fields($columns);
110 ?>
111 </div>
112 </div>
113 <button class="delete-button" data-action="filters#removeCondition">
114 <span class="dashicons dashicons-no"></span></button>
115 </div>
116 <?php
117 $html = \ob_get_contents();
118 \ob_end_clean();
119 return $html;
120 }
121 private function get_inclusion_selects()
122 {
123 $html = '<select class="filters-include" data-filters-target="inclusion">';
124 $html .= '<option value="include">' . \esc_html__('Include', 'independent-analytics') . '</option>';
125 $html .= '<option value="exclude">' . \esc_html__('Exclude', 'independent-analytics') . '</option>';
126 $html .= '</select>';
127 return $html;
128 }
129 /**
130 * @param Column[] $columns
131 *
132 * @return void
133 */
134 private function get_column_select(array $columns)
135 {
136 ?>
137 <select class="filters-column" data-filters-target="column"
138 data-action="filters#columnSelect"
139 >
140 <option value="">
141 <?php
142 \esc_html_e('Choose a column', 'independent-analytics');
143 ?>
144 </option>
145 <?php
146 foreach ($columns as $column) {
147 ?>
148 <?php
149 if ($column->requires_woocommerce() && !\IAWP_SCOPED\iawp_using_woocommerce()) {
150 continue;
151 }
152 ?>
153 <option value="<?php
154 \esc_attr_e($column->id());
155 ?>"
156 data-type="<?php
157 \esc_attr_e($column->type());
158 ?>"
159 >
160 <?php
161 \esc_html_e($column->label());
162 ?>
163 </option>
164 <?php
165 }
166 ?>
167 </select>
168 <?php
169 }
170 private function get_all_operator_selects()
171 {
172 $html = '';
173 foreach (self::get_data_types() as $data_type) {
174 $html .= '<select data-filters-target="operator" data-type="' . \esc_attr($data_type) . '" data-testid="' . \esc_attr($data_type) . '-operator">';
175 foreach (self::get_operators($data_type) as $key => $value) {
176 $html .= '<option value="' . \esc_attr($key) . '">' . \esc_html($value) . '</option>';
177 }
178 $html .= '</select>';
179 }
180 return $html;
181 }
182 private function get_all_operand_fields(array $columns)
183 {
184 $html = '';
185 foreach ($columns as $column) {
186 switch ($column->type()) {
187 case 'string':
188 $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()) . '" />';
189 break;
190 case 'int':
191 $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()) . '" />';
192 break;
193 case 'date':
194 $html .= '<input type="text"
195 data-filters-target="operand"
196 data-action="keydown->filters#operandKeyDown filters#operandChange"
197 data-column="' . \esc_attr($column->id()) . '"
198 data-controller="easepick"
199 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)) . '"
200 data-format="' . \esc_attr(WordPress_Site_Date_Format_Pattern::for_javascript()) . '"
201 data-testid="' . \esc_attr($column->id()) . '-operand" />';
202 break;
203 case 'select':
204 $html .= '<select data-filters-target="operand" data-column="' . \esc_attr($column->id()) . '" data-testid="' . \esc_attr($column->id()) . '-operand">';
205 foreach ($column->options() as $option) {
206 $html .= '<option value="' . \esc_attr($option[0]) . '">' . \esc_html($option[1]) . '</option>';
207 }
208 $html .= '</select>';
209 break;
210 }
211 }
212 return $html;
213 }
214 private function get_data_types()
215 {
216 return ['string', 'int', 'date', 'select'];
217 }
218 private function get_operators(string $data_type)
219 {
220 if ($data_type == 'string') {
221 return ['contains' => \esc_html__('Contains', 'independent-analytics'), 'exact' => \esc_html__('Exactly matches', 'independent-analytics')];
222 } elseif ($data_type == 'int') {
223 return ['greater' => \esc_html__('Greater than', 'independent-analytics'), 'lesser' => \esc_html__('Less than', 'independent-analytics'), 'equal' => \esc_html__('Equal to', 'independent-analytics')];
224 } elseif ($data_type == 'select') {
225 return ['is' => \esc_html__('Is', 'independent-analytics'), 'isnt' => \esc_html__('Isn\'t', 'independent-analytics')];
226 } elseif ($data_type == 'date') {
227 return ['before' => \esc_html__('Before', 'independent-analytics'), 'after' => \esc_html__('After', 'independent-analytics'), 'on' => \esc_html__('On', 'independent-analytics')];
228 } else {
229 return null;
230 }
231 }
232 }
233