PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.12.2
Independent Analytics – WordPress Analytics Plugin v2.12.2
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 / Statistics / Statistic.php
independent-analytics / IAWP / Statistics Last commit date
Intervals 1 year ago Campaign_Statistics.php 2 years ago City_Statistics.php 2 years ago Click_Statistics.php 1 year ago Country_Statistics.php 2 years ago Device_Browser_Statistics.php 2 years ago Device_OS_Statistics.php 2 years ago Device_Type_Statistics.php 2 years ago Page_Statistics.php 2 years ago Referrer_Statistics.php 2 years ago Statistic.php 1 year ago Statistics.php 11 months ago
Statistic.php
170 lines
1 <?php
2
3 namespace IAWP\Statistics;
4
5 use IAWP\Dashboard_Options;
6 use IAWP\Plugin_Group_Option;
7 use IAWP\Utils\Currency;
8 use IAWP\Utils\Number_Formatter;
9 /** @internal */
10 class Statistic implements Plugin_Group_Option
11 {
12 private $id;
13 private $name;
14 private $plugin_group;
15 private $plugin_group_header;
16 private $icon;
17 private $statistic;
18 private $previous_period_statistic;
19 private $unfiltered_statistic;
20 private $statistic_over_time;
21 private $is_visible_in_dashboard_widget;
22 private $format;
23 private $is_growth_good;
24 private $is_subgroup_plugin_enabled;
25 private $requires_pro;
26 public function __construct(array $attributes)
27 {
28 $this->id = $attributes['id'];
29 $this->name = $attributes['name'];
30 $this->plugin_group = $attributes['plugin_group'];
31 $this->plugin_group_header = $attributes['plugin_group_header'] ?? null;
32 $this->icon = $attributes['icon'] ?? null;
33 $this->statistic = $attributes['statistic'] ?? 0;
34 $this->previous_period_statistic = $attributes['previous_period_statistic'] ?? 0;
35 $this->unfiltered_statistic = $attributes['unfiltered_statistic'] ?? null;
36 $this->statistic_over_time = $attributes['statistic_over_time'] ?? [];
37 $this->is_visible_in_dashboard_widget = $attributes['is_visible_in_dashboard_widget'] ?? \false;
38 $this->format = $attributes['format'] ?? null;
39 $this->is_growth_good = $attributes['is_growth_good'] ?? \true;
40 $this->is_subgroup_plugin_enabled = $attributes['is_subgroup_plugin_active'] ?? \true;
41 $this->requires_pro = $attributes['requires_pro'] ?? \false;
42 }
43 public function is_enabled() : bool
44 {
45 if ($this->requires_pro === \true && \IAWPSCOPED\iawp_is_free()) {
46 return \false;
47 }
48 return \true;
49 }
50 public function id() : string
51 {
52 return $this->id;
53 }
54 public function name() : string
55 {
56 return $this->name;
57 }
58 public function icon() : ?string
59 {
60 return $this->icon;
61 }
62 public function plugin_group() : string
63 {
64 return $this->plugin_group;
65 }
66 public function plugin_group_header() : ?string
67 {
68 return $this->plugin_group_header;
69 }
70 public function is_visible_in_dashboard_widget() : bool
71 {
72 return $this->is_visible_in_dashboard_widget;
73 }
74 public function statistic_over_time() : array
75 {
76 return $this->statistic_over_time;
77 }
78 public function is_group_plugin_enabled() : bool
79 {
80 switch ($this->plugin_group) {
81 case "ecommerce":
82 return \IAWPSCOPED\iawp()->is_ecommerce_support_enabled();
83 case "forms":
84 return \IAWPSCOPED\iawp()->is_form_submission_support_enabled();
85 default:
86 return \true;
87 }
88 }
89 public function is_subgroup_plugin_enabled() : bool
90 {
91 return $this->is_subgroup_plugin_enabled;
92 }
93 public function is_visible() : bool
94 {
95 $options = Dashboard_Options::getInstance();
96 return \in_array($this->id(), $options->visible_quick_stats());
97 }
98 public function is_member_of_plugin_group(string $plugin_group) : bool
99 {
100 return $this->plugin_group === $plugin_group;
101 }
102 public function formatted_value() : string
103 {
104 return $this->format_value($this->statistic);
105 }
106 public function value()
107 {
108 return $this->statistic;
109 }
110 public function formatted_unfiltered_value() : ?string
111 {
112 if (\is_null($this->unfiltered_statistic)) {
113 return null;
114 }
115 return $this->format_value($this->unfiltered_statistic);
116 }
117 /**
118 * Growth can be good or bad depending on the quick stat. This allows it to be calculated on a
119 * at the individual quick stat level.
120 *
121 * The default behavior is "up" and "good" so you can tweak either of those as needed
122 *
123 * @return string
124 */
125 public function growth_html_class() : string
126 {
127 $html_classes = [];
128 $has_growth = $this->growth() >= 0;
129 if (!$has_growth) {
130 $html_classes[] = 'down';
131 }
132 if ($has_growth && !$this->is_growth_good || !$has_growth && $this->is_growth_good) {
133 $html_classes[] = 'bad';
134 }
135 return \implode(' ', $html_classes);
136 }
137 public function formatted_growth() : string
138 {
139 $growth = $this->growth();
140 return Number_Formatter::percent(\absint($growth));
141 }
142 public function growth()
143 {
144 if ($this->statistic == 0 && $this->previous_period_statistic != 0) {
145 return -100;
146 } elseif ($this->statistic == 0 || $this->previous_period_statistic == 0) {
147 return 0;
148 }
149 $percent_growth = ($this->statistic / $this->previous_period_statistic - 1) * 100;
150 return \round($percent_growth, 0);
151 }
152 public function format_value($value) : string
153 {
154 switch ($this->format) {
155 case 'time':
156 return Number_Formatter::second_to_minute_timestamp($value);
157 case 'percent':
158 return Number_Formatter::percent($value, 2);
159 case 'decimal':
160 return Number_Formatter::decimal($value, 2);
161 case 'currency':
162 return Currency::format($value, \false);
163 case 'rounded-currency':
164 return Currency::format($value, \true);
165 default:
166 return Number_Formatter::integer($value);
167 }
168 }
169 }
170