PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.0.0
Independent Analytics – WordPress Analytics Plugin v2.0.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 / Report_Finder.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 2 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 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 3 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 3 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 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
Report_Finder.php
194 lines
1 <?php
2
3 namespace IAWP_SCOPED\IAWP;
4
5 class Report_Finder
6 {
7 public function __construct()
8 {
9 }
10 public function fetch_reports_by_type() : array
11 {
12 return [['name' => \__('Pages', 'independent-analytics'), 'reports' => $this->fetch_page_reports()], ['name' => \__('Referrers', 'independent-analytics'), 'reports' => $this->fetch_referrer_reports()], ['name' => \__('Geographic', 'independent-analytics'), 'reports' => $this->fetch_geographic_reports()], ['name' => \__('Devices', 'independent-analytics'), 'reports' => $this->fetch_device_reports()], ['name' => \__('Campaigns', 'independent-analytics'), 'reports' => $this->fetch_campaign_reports()]];
13 }
14 /**
15 * @return Report[]
16 */
17 public function fetch_page_reports() : array
18 {
19 return $this->by_type('views');
20 }
21 /**
22 * @return Report[]
23 */
24 public function fetch_referrer_reports() : array
25 {
26 return $this->by_type('referrers');
27 }
28 /**
29 * @return Report[]
30 */
31 public function fetch_geographic_reports() : array
32 {
33 return $this->by_type('geo');
34 }
35 /**
36 * @return Report[]
37 */
38 public function fetch_device_reports() : array
39 {
40 return $this->by_type('devices');
41 }
42 /**
43 * @return Report[]
44 */
45 public function fetch_campaign_reports() : array
46 {
47 return $this->by_type('campaigns');
48 }
49 public function is_real_time() : bool
50 {
51 return \IAWP_SCOPED\iawp()->get_current_tab() === 'real-time';
52 }
53 public function is_settings_page() : bool
54 {
55 return \IAWP_SCOPED\iawp()->get_current_tab() === 'settings';
56 }
57 public function is_campaign_builder_page() : bool
58 {
59 return \IAWP_SCOPED\iawp()->get_current_tab() === 'campaign-builder';
60 }
61 public function is_page_report() : bool
62 {
63 return \IAWP_SCOPED\iawp()->get_current_tab() === 'views';
64 }
65 public function is_referrer_report() : bool
66 {
67 return \IAWP_SCOPED\iawp()->get_current_tab() === 'referrers';
68 }
69 public function is_geographic_report() : bool
70 {
71 return \IAWP_SCOPED\iawp()->get_current_tab() === 'geo';
72 }
73 public function is_device_report() : bool
74 {
75 return \IAWP_SCOPED\iawp()->get_current_tab() === 'devices';
76 }
77 public function is_campaign_report() : bool
78 {
79 return \IAWP_SCOPED\iawp()->get_current_tab() === 'campaigns';
80 }
81 public function is_saved_report() : bool
82 {
83 $report = $this->current();
84 if (\is_null($report)) {
85 return \false;
86 }
87 return $report->is_saved_report();
88 }
89 public function current() : ?Report
90 {
91 $report_id = \array_key_exists('report', $_GET) ? \sanitize_text_field($_GET['report']) : null;
92 if (\is_null($report_id)) {
93 return self::get_base_report_for_current_tab();
94 }
95 $report = self::by_id($report_id);
96 if (\is_null($report)) {
97 return self::get_base_report_for_current_tab();
98 }
99 return $report;
100 }
101 /**
102 * @param array $ids
103 *
104 * @return array|Report[]|null
105 */
106 public function by_ids(array $ids) : ?array
107 {
108 $reports_table = Query::get_table_name(Query::REPORTS);
109 $rows = Illuminate_Builder::get_builder()->from($reports_table)->whereIn('report_id', $ids)->get()->toArray();
110 return \array_map(function ($row) {
111 return new Report($row);
112 }, $rows);
113 }
114 /**
115 * @param string $type
116 *
117 * @return Report[]
118 */
119 public function by_type(string $type) : array
120 {
121 $reports_table = Query::get_table_name(Query::REPORTS);
122 $builder = Illuminate_Builder::get_builder()->from($reports_table)->where('type', '=', $type)->orderByRaw('position IS NULL')->orderBy('position')->orderBy('report_id')->get()->escapeWhenCastingToString();
123 $rows = $builder->toArray();
124 return \array_map(function ($row) {
125 return new Report($row);
126 }, $rows);
127 }
128 public static function get_base_report_for_current_tab() : ?Report
129 {
130 return self::get_base_report_for_type(\IAWP_SCOPED\iawp()->get_current_tab());
131 }
132 public static function get_favorite() : ?Report
133 {
134 $raw_id = \get_user_meta(\get_current_user_id(), 'iawp_favorite_report_id', \true);
135 $id = \filter_var($raw_id, \FILTER_VALIDATE_INT);
136 if ($id !== \false) {
137 return self::by_id($id);
138 }
139 $raw_type = \get_user_meta(\get_current_user_id(), 'iawp_favorite_report_type', \true);
140 $type = \filter_var($raw_type, \FILTER_SANITIZE_FULL_SPECIAL_CHARS);
141 return self::get_base_report_for_type($type);
142 }
143 /**
144 * @param string|int $id
145 *
146 * @return Report|null
147 */
148 public static function by_id($id) : ?Report
149 {
150 $id = (string) $id;
151 $reports_table = Query::get_table_name(Query::REPORTS);
152 if (!\ctype_digit($id)) {
153 return null;
154 }
155 $row = Illuminate_Builder::get_builder()->from($reports_table)->where('report_id', '=', $id)->first();
156 if (\is_null($row)) {
157 return null;
158 }
159 return new Report($row);
160 }
161 public static function create_report(array $attributes) : Report
162 {
163 $reports_table = Query::get_table_name(Query::REPORTS);
164 if (\array_key_exists('columns', $attributes) && \is_array($attributes['columns'])) {
165 $attributes['columns'] = \json_encode($attributes['columns']);
166 }
167 if (\array_key_exists('filters', $attributes) && \is_array($attributes['filters'])) {
168 $attributes['filters'] = \json_encode($attributes['filters']);
169 }
170 if (\array_key_exists('visible_datasets', $attributes) && \is_array($attributes['visible_datasets'])) {
171 $attributes['visible_datasets'] = \json_encode($attributes['visible_datasets']);
172 }
173 $report_id = Illuminate_Builder::get_builder()->from($reports_table)->insertGetId($attributes);
174 return self::by_id($report_id);
175 }
176 private static function get_base_report_for_type(string $type) : ?Report
177 {
178 switch ($type) {
179 case 'views':
180 return new Report((object) ['name' => 'Pages', 'type' => 'views']);
181 case 'referrers':
182 return new Report((object) ['name' => 'Referrers', 'type' => 'referrers']);
183 case 'geo':
184 return new Report((object) ['name' => 'Geographic', 'type' => 'geo']);
185 case 'devices':
186 return new Report((object) ['name' => 'Devices', 'type' => 'devices']);
187 case 'campaigns':
188 return new Report((object) ['name' => 'Campaigns', 'type' => 'campaigns']);
189 default:
190 return null;
191 }
192 }
193 }
194