PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 2.0.6
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v2.0.6
3.1.13 3.1.12 3.1.11 3.1.10 3.1.9 3.1.8 3.1.7 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 All 122 releases
← All changes | Inc/Core/Admin/Analytics/Helpers/AnalyticsHelper.php +72 -42 1.0.22.0.6 View file →
@@ -1,12 +1,12 @@
1 1 <?php
2 2 /**
3 3 * @package FireBox
4 - * @version 1.0.2 Free
4 + * @version 2.0.6 Free
5 5 *
6 6 * @author FirePlugins <[email protected]>
7 7 * @link https://www.fireplugins.com
8 - * @copyright Copyright © 2021 FirePlugins All Rights Reserved
8 + * @copyright Copyright © 2023 FirePlugins All Rights Reserved
9 9 * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
10 10 */
11 11
12 12 namespace FireBox\Core\Admin\Analytics\Helpers;
@@ -17,20 +17,12 @@
17 17 }
18 18
19 19 use FPFramework\Libs\Registry;
20 20 use Firebox\Core\Admin\Analytics\Toolbar;
21 -use Firebox\Core\Admin\Analytics\MetricData;
22 21
23 22 class AnalyticsHelper
24 23 {
25 24 /**
26 - * Analytics Configuration data
27 - *
28 - * @var array
29 - */
30 - private static $configuration_data = [];
31 -
32 - /**
33 25 * Returns the data based on metrics, toolbar items and other data
34 26 *
35 27 * @param array $metrics
36 28 * @param array $toolbar_data
@@ -39,10 +31,9 @@
39 31 * @return array
40 32 */
41 33 public static function getData($metrics = [], $toolbar_data = [], $other_data = [])
42 34 {
43 - // ensure we were given metrics and toolbar data
44 - if (!$metrics || !$toolbar_data || !is_array($metrics) || !is_array($toolbar_data))
35 + if (!$metrics || !is_array($metrics))
45 36 {
46 37 return [];
47 38 }
48 39
@@ -47,32 +38,39 @@
47 38 }
48 39
49 40 $other_data = new Registry($other_data);
50 41
51 - // The metrics we were given may get data from db and other metrics.
52 - // We may only need to get data from a specific data source. i.e. db/metrics
53 - $allowed_data_sources = $other_data->get('data_source', []);
42 + $data = [];
54 43
55 - $data = [];
44 + // create a Toolbar and set the selected toolbar items
45 + $toolbar = new Toolbar(null, $toolbar_data);
56 46
57 - foreach ($metrics as $metric_key)
47 + $metricsObjects = new \FireBox\Core\Admin\Analytics\Metrics($toolbar);
48 + $metricsObjects = $metricsObjects->getMetricsData();
49 +
50 + foreach ($metrics as $metric)
58 51 {
59 - // initialize the metric to receive the data
60 - $class = '\FireBox\Core\Admin\Analytics\Metrics\\' . ucfirst(strtolower($metric_key));
52 + $metricInstance = $metricsObjects[$metric]['metric'];
61 53
62 - // create a Toolbar and set the selected toolbar items
63 - $toolbar = new Toolbar(self::$configuration_data);
64 - $toolbar->setSelectedToolbarItemsValue($toolbar_data);
65 - $toolbar->setUpAvailableToolbarItems();
66 -
67 - $metric = new $class($toolbar);
54 + // Metrics that require other metrics to generate data
55 + if ($metricInstance->getDataSource() === 'metrics')
56 + {
57 + $found_metrics = array_intersect_key($metricsObjects, array_flip($metricInstance->getDataSourceInput()));
68 58
69 - // If we were given which data sources to process, check that the current metric has a valid data source
70 - if ($allowed_data_sources)
71 - {
72 - if (!in_array($metric->getDataSource(), $allowed_data_sources))
59 + if ($found_metrics)
73 60 {
74 - continue;
61 + foreach ($found_metrics as &$_metric)
62 + {
63 + $_metric = $_metric['metric'];
64 + }
65 +
66 + // Skip fill dates
67 + $metric_opts = $metricInstance->getOptionsRaw();
68 + $metric_opts['skip_filling_dates'] = true;
69 + $metricInstance->setOptions($metric_opts);
70 +
71 + // Set custom metrics
72 + $metricInstance->setCustomMetrics($found_metrics);
75 73 }
76 74 }
77 75
78 76 // Check if we were given extra query data that modify the base query and apply them.
@@ -78,9 +76,9 @@
78 76 // Check if we were given extra query data that modify the base query and apply them.
79 77 $metric_modify_query_data = $other_data->get('modify_query_data', []);
80 78 if ($metric_modify_query_data)
81 79 {
82 - $metric->getMetricData()->setModifyQueryData($metric_modify_query_data);
80 + $metricInstance->getMetricData()->setModifyQueryData($metric_modify_query_data);
83 81 }
84 82
85 83 // Check if we have extra options to set for the Metric
86 84 $metric_options = $other_data->get('options', []);
@@ -85,34 +83,66 @@
85 83 // Check if we have extra options to set for the Metric
86 84 $metric_options = $other_data->get('options', []);
87 85 if ($metric_options)
88 86 {
89 - $metric->setOptions($metric_options);
87 + $metricInstance->setOptions($metric_options);
90 88 }
91 -
92 - // get the metric data
93 - $metric->setData();
94 89
90 + $metric_data = $metricInstance->update()->getData();
91 +
95 92 // store them
96 93 if (count($metrics) == 1)
97 94 {
98 - $data = $metric->getData();
95 + $data = $metric_data;
99 96 }
100 97 else
101 98 {
102 - $data[$metric->getType()] = $metric->getData();
99 + $data[$metricInstance->getType()] = $metric_data;
103 100 }
104 101 }
105 102
106 103 return $data;
107 104 }
105 +
106 + /**
107 + * Whether we can run an analytics page or not
108 + *
109 + * @param string $page
110 + *
111 + * @return boolean
112 + */
113 + public static function canRun($page = '')
114 + {
115 + if (!$page)
116 + {
117 + return false;
118 + }
119 +
120 + // we must be on admin panel
121 + if (!is_admin())
122 + {
123 + return false;
124 + }
108 125
109 - public static function setConfigurationData($data)
110 - {
111 - if (self::$configuration_data)
126 + // ensure we have correct priviledges
127 + if (!is_user_logged_in() || !current_user_can('manage_options'))
112 128 {
113 - return;
129 + return false;
114 130 }
131 +
132 + // we must be on admin.php page
133 + global $pagenow;
134 + if ($pagenow !== 'admin.php')
135 + {
136 + return false;
137 + }
138 +
139 + // ensure we are on firebox dashboard
140 + $page = fpframework()->getPluginPage();
141 + if (!$page || !in_array($page, [$page]))
142 + {
143 + return false;
144 + }
115 145
116 - self::$configuration_data = $data;
146 + return true;
117 147 }
118 148 }