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