PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 2.1.14
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v2.1.14
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
firebox / Inc / Core / Analytics / Data.php

Data.php in FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment 2.1.14, at Inc/Core/Analytics/Data.php

126 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package FireBox
4 * @version 2.1.14 Free
5 *
6 * @author FirePlugins <info@fireplugins.com>
7 * @link https://www.fireplugins.com
8 * @copyright Copyright © 2024 FirePlugins All Rights Reserved
9 * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
10 */
11
12 namespace FireBox\Core\Analytics;
13
14 if (!defined('ABSPATH'))
15 {
16 exit; // Exit if accessed directly.
17 }
18
19 class Data
20 {
21 private $start_date = null;
22
23 private $end_date = null;
24
25 private $metrics = [];
26
27 private $filters = [];
28
29 private $offset = null;
30
31 private $limit = null;
32
33 protected $options = [];
34
35 public function __construct($start_date = '', $end_date = '', $options = [])
36 {
37 $utcTimeZone = new \DateTimeZone('UTC');
38 $tz = new \DateTimeZone(wp_timezone()->getName());
39
40 // Make start in UTC
41 if ($start_date_obj = \DateTime::createFromFormat('Y/m/d H:i:s', $start_date, $tz))
42 {
43 $start_date_obj->setTimezone($utcTimeZone);
44 $start_date = $start_date_obj->format('Y/m/d H:i:s');
45 }
46
47 // Make end_date in UTC
48 if ($end_date_obj = \DateTime::createFromFormat('Y/m/d H:i:s', $end_date, $tz))
49 {
50 $end_date_obj->setTimezone($utcTimeZone);
51 $end_date = $end_date_obj->format('Y/m/d H:i:s');
52 }
53
54 $this->start_date = $start_date;
55 $this->end_date = $end_date;
56 $this->options = $options;
57 }
58
59 /**
60 * Allowed metrics:
61 *
62 * [
63 * 'impressions',
64 * 'submissions',
65 * 'conversionrate'
66 * ]
67 */
68 public function setMetrics($metrics = [])
69 {
70 $this->metrics = $metrics;
71 }
72
73 public function setFilters($filters = [])
74 {
75 $this->filters = $filters;
76 }
77
78 public function setOffset($offset = null)
79 {
80 $this->offset = (int) $offset;
81 }
82
83 public function setLimit($limit = null)
84 {
85 $this->limit = (int) $limit;
86 }
87
88 public function getData($type = 'list')
89 {
90 $data = array_fill_keys($this->metrics, []);
91
92 foreach ($data as $metric_slug => &$metric_data)
93 {
94 // Validate the given metric name and abort if unknown
95 if (!$class_name = \FireBox\Core\Analytics\Helpers\Metrics::getClassFromSlug($metric_slug))
96 {
97 unset($data[$metric_slug]);
98 continue;
99 }
100
101 $class = '\FireBox\Core\Analytics\Metrics\\' . $class_name;
102 $class = new $class($this->start_date, $this->end_date, $type, $this->options);
103
104 if ($this->filters)
105 {
106 $class->setFilters($this->filters);
107 }
108
109 if ($this->offset)
110 {
111 $class->setOffset($this->offset);
112 }
113
114 if ($this->limit)
115 {
116 $class->setLimit($this->limit);
117 }
118
119 $metric_data = $class->getData();
120
121 $class->onAfterGetData($metric_data);
122 }
123
124 return $data;
125 }
126 }