PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.1.5
Independent Analytics – WordPress Analytics Plugin v2.1.5
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 2 years ago Date_Range 2 years ago Interval 2 years ago Menu_Bar_Stats 2 years ago Migrations 2 years ago Models 2 years ago Public_API 2 years ago Rows 2 years ago Statistics 2 years ago Tables 2 years ago Utils 2 years ago Campaign_Builder.php 2 years ago Capability_Manager.php 2 years ago Chart.php 2 years ago Chart_Geo.php 2 years 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_Manager.php 2 years ago Email_Chart.php 2 years ago Email_Reports.php 2 years ago Empty_Report_Option.php 2 years ago Env.php 2 years ago Filters.php 2 years ago Geo_Database_Background_Job.php 2 years ago Geo_Database_Manager.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 2 years ago Independent_Analytics.php 2 years ago Interrupt.php 2 years ago Known_Referrers.php 2 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 Report.php 2 years ago Report_Finder.php 2 years ago Report_Options_Parser.php 2 years ago Resource_Identifier.php 2 years ago Settings.php 2 years ago Sort_Configuration.php 2 years ago Track_Resource_Changes.php 2 years ago View.php 2 years ago View_Counter.php 2 years ago Visitors_Over_Time_Finder.php 2 years ago WP_Option_Cache_Bust.php 2 years ago WooCommerce_Order.php 2 years ago WooCommerce_Referrer_Meta_Box.php 2 years ago
Filters.php
234 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 /** @internal */
8 class Filters
9 {
10 private $label;
11 public function __construct(string $label)
12 {
13 $this->label = $label;
14 }
15 public function get_filters_html(array $columns) : string
16 {
17 $opts = new Dashboard_Options();
18 \ob_start();
19 ?>
20 <div class="modal-parent"
21 data-controller="filters"
22 data-filters-filters-value="<?php
23 \esc_html_e(\json_encode($opts->filters()));
24 ?>"
25 >
26 <button id="filters-button" class="iawp-button ghost-white toolbar-button"
27 data-action="filters#toggleModal"
28 data-filters-target="modalButton"
29 >
30 <span class="dashicons dashicons-filter"></span>
31 <span class="iawp-label"><?php
32 echo ' ' . \esc_html__('Filter', 'independent-analytics') . ' ';
33 ?><span data-filters-target="groupName"><?php
34 echo \esc_html($this->label);
35 ?></span></span>
36 <span class="count" data-filters-target="filterCount"></span>
37 </button>
38 <div id="modal-filters"
39 class="modal large"
40 data-filters-target="modal"
41 >
42 <div class="modal-inner">
43 <div class="title-small"><?php
44 \esc_html_e('Filters', 'independent-analytics');
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-button text"
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 private function get_inclusion_selects()
123 {
124 $html = '<select class="filters-include" data-filters-target="inclusion">';
125 $html .= '<option value="include">' . \esc_html__('Include', 'independent-analytics') . '</option>';
126 $html .= '<option value="exclude">' . \esc_html__('Exclude', 'independent-analytics') . '</option>';
127 $html .= '</select>';
128 return $html;
129 }
130 /**
131 * @param Column[] $columns
132 *
133 * @return void
134 */
135 private function get_column_select(array $columns)
136 {
137 ?>
138 <select class="filters-column" data-filters-target="column"
139 data-action="filters#columnSelect"
140 >
141 <option value="">
142 <?php
143 \esc_html_e('Choose a column', 'independent-analytics');
144 ?>
145 </option>
146 <?php
147 foreach ($columns as $column) {
148 ?>
149 <?php
150 if ($column->requires_woocommerce() && !\IAWP_SCOPED\iawp_using_woocommerce()) {
151 continue;
152 }
153 ?>
154 <option value="<?php
155 echo \esc_attr($column->id());
156 ?>"
157 data-type="<?php
158 echo \esc_attr($column->type());
159 ?>"
160 >
161 <?php
162 echo \esc_html($column->label());
163 ?>
164 </option>
165 <?php
166 }
167 ?>
168 </select>
169 <?php
170 }
171 private function get_all_operator_selects()
172 {
173 $html = '';
174 foreach (self::get_data_types() as $data_type) {
175 $html .= '<select data-filters-target="operator" data-type="' . \esc_attr($data_type) . '" data-testid="' . \esc_attr($data_type) . '-operator">';
176 foreach (self::get_operators($data_type) as $key => $value) {
177 $html .= '<option value="' . \esc_attr($key) . '">' . \esc_html($value) . '</option>';
178 }
179 $html .= '</select>';
180 }
181 return $html;
182 }
183 private function get_all_operand_fields(array $columns)
184 {
185 $html = '';
186 foreach ($columns as $column) {
187 switch ($column->type()) {
188 case 'string':
189 $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()) . '" />';
190 break;
191 case 'int':
192 $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()) . '" />';
193 break;
194 case 'date':
195 $html .= '<input type="text"
196 data-filters-target="operand"
197 data-action="keydown->filters#operandKeyDown filters#operandChange"
198 data-column="' . \esc_attr($column->id()) . '"
199 data-controller="easepick"
200 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)) . '"
201 data-format="' . \esc_attr(WordPress_Site_Date_Format_Pattern::for_javascript()) . '"
202 data-testid="' . \esc_attr($column->id()) . '-operand" />';
203 break;
204 case 'select':
205 $html .= '<select data-filters-target="operand" data-column="' . \esc_attr($column->id()) . '" data-testid="' . \esc_attr($column->id()) . '-operand">';
206 foreach ($column->options() as $option) {
207 $html .= '<option value="' . \esc_attr($option[0]) . '">' . \esc_html($option[1]) . '</option>';
208 }
209 $html .= '</select>';
210 break;
211 }
212 }
213 return $html;
214 }
215 private function get_data_types()
216 {
217 return ['string', 'int', 'date', 'select'];
218 }
219 private function get_operators(string $data_type)
220 {
221 if ($data_type == 'string') {
222 return ['contains' => \esc_html__('Contains', 'independent-analytics'), 'exact' => \esc_html__('Exactly matches', 'independent-analytics')];
223 } elseif ($data_type == 'int') {
224 return ['greater' => \esc_html__('Greater than', 'independent-analytics'), 'lesser' => \esc_html__('Less than', 'independent-analytics'), 'equal' => \esc_html__('Equal to', 'independent-analytics')];
225 } elseif ($data_type == 'select') {
226 return ['is' => \esc_html__('Is', 'independent-analytics'), 'isnt' => \esc_html__('Isn\'t', 'independent-analytics')];
227 } elseif ($data_type == 'date') {
228 return ['before' => \esc_html__('Before', 'independent-analytics'), 'after' => \esc_html__('After', 'independent-analytics'), 'on' => \esc_html__('On', 'independent-analytics')];
229 } else {
230 return null;
231 }
232 }
233 }
234