AJAX
2 years ago
Admin_Page
2 years ago
Custom_WordPress_Columns
2 years ago
Date_Range
2 years ago
Filter_Lists
2 years ago
Form_Submissions
2 years ago
Interval
2 years ago
Menu_Bar_Stats
2 years ago
Migrations
2 years ago
Models
2 years ago
Public_API
2 years ago
Rows
2 years ago
Statistics
2 years ago
Tables
2 years ago
Utils
2 years ago
Campaign_Builder.php
2 years ago
Capability_Manager.php
2 years ago
Chart.php
2 years ago
Chart_Geo.php
2 years ago
Cron_Manager.php
2 years ago
Current_Traffic_Finder.php
2 years ago
Dashboard_Options.php
2 years ago
Dashboard_Widget.php
2 years ago
Database.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
2 years ago
Form.php
2 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
2 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
Plugin_Group.php
2 years ago
Plugin_Group_Option.php
2 years ago
Query.php
2 years ago
Quick_Stat.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
2 years ago
Settings.php
2 years ago
Sort_Configuration.php
2 years ago
Track_Resource_Changes.php
2 years ago
View.php
2 years ago
View_Counter.php
2 years ago
Visitors_Over_Time_Finder.php
2 years ago
WP_Option_Cache_Bust.php
2 years ago
WooCommerce_Order.php
2 years ago
WooCommerce_Referrer_Meta_Box.php
2 years ago
Quick_Stat.php
140 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP; |
| 4 | |
| 5 | use IAWP\Utils\Currency; |
| 6 | use IAWP\Utils\Number_Formatter; |
| 7 | /** @internal */ |
| 8 | class Quick_Stat implements \IAWP\Plugin_Group_Option |
| 9 | { |
| 10 | private $id; |
| 11 | private $name; |
| 12 | private $plugin_group; |
| 13 | private $plugin_group_header; |
| 14 | private $icon; |
| 15 | private $statistic; |
| 16 | private $unfiltered_statistic; |
| 17 | private $is_visible_in_dashboard_widget; |
| 18 | private $format; |
| 19 | private $is_growth_good; |
| 20 | private $is_plugin_active; |
| 21 | public function __construct(array $attributes) |
| 22 | { |
| 23 | $this->id = $attributes['id']; |
| 24 | $this->name = $attributes['name']; |
| 25 | $this->plugin_group = $attributes['plugin_group']; |
| 26 | $this->plugin_group_header = $attributes['plugin_group_header'] ?? null; |
| 27 | $this->icon = $attributes['icon'] ?? null; |
| 28 | $this->statistic = $attributes['statistic']; |
| 29 | $this->unfiltered_statistic = $attributes['unfiltered_statistic']; |
| 30 | $this->is_visible_in_dashboard_widget = $attributes['is_visible_in_dashboard_widget'] ?? \false; |
| 31 | $this->format = $attributes['format'] ?? null; |
| 32 | $this->is_growth_good = $attributes['is_growth_good'] ?? \true; |
| 33 | $this->is_plugin_active = $attributes['is_plugin_active'] ?? \true; |
| 34 | } |
| 35 | public function id() : string |
| 36 | { |
| 37 | return $this->id; |
| 38 | } |
| 39 | public function name() : string |
| 40 | { |
| 41 | return $this->name; |
| 42 | } |
| 43 | public function icon() : ?string |
| 44 | { |
| 45 | return $this->icon; |
| 46 | } |
| 47 | public function is_enabled() : bool |
| 48 | { |
| 49 | switch ($this->plugin_group) { |
| 50 | case "woocommerce": |
| 51 | return \IAWPSCOPED\iawp_using_woocommerce(); |
| 52 | case "forms": |
| 53 | return \IAWPSCOPED\iawp_using_a_form_plugin(); |
| 54 | default: |
| 55 | return \true; |
| 56 | } |
| 57 | } |
| 58 | public function is_plugin_active() : bool |
| 59 | { |
| 60 | return $this->is_plugin_active; |
| 61 | } |
| 62 | public function plugin_group_header() : ?string |
| 63 | { |
| 64 | return $this->plugin_group_header; |
| 65 | } |
| 66 | public function is_visible() : bool |
| 67 | { |
| 68 | $options = \IAWP\Dashboard_Options::getInstance(); |
| 69 | return \in_array($this->id(), $options->visible_quick_stats()); |
| 70 | } |
| 71 | public function total() : string |
| 72 | { |
| 73 | $total = $this->statistic->value(); |
| 74 | return $this->format($total); |
| 75 | } |
| 76 | public function unfiltered_total() : ?string |
| 77 | { |
| 78 | if (\is_null($this->unfiltered_statistic)) { |
| 79 | return null; |
| 80 | } |
| 81 | $total = $this->unfiltered_statistic->value(); |
| 82 | return $this->format($total); |
| 83 | } |
| 84 | /** |
| 85 | * Growth can be good or bad depending on the quick stat. This allows it to be calculated on a |
| 86 | * at the individual quick stat level. |
| 87 | * |
| 88 | * The default behavior is "up" and "good" so you can tweak either of those as needed |
| 89 | * |
| 90 | * @return string |
| 91 | */ |
| 92 | public function growth_html_class() : string |
| 93 | { |
| 94 | $html_classes = []; |
| 95 | $has_growth = $this->unformatted_growth() >= 0; |
| 96 | if (!$has_growth) { |
| 97 | $html_classes[] = 'down'; |
| 98 | } |
| 99 | if ($has_growth && !$this->is_growth_good || !$has_growth && $this->is_growth_good) { |
| 100 | $html_classes[] = 'bad'; |
| 101 | } |
| 102 | return \implode(' ', $html_classes); |
| 103 | } |
| 104 | public function growth() : string |
| 105 | { |
| 106 | $growth = $this->statistic->growth(); |
| 107 | return Number_Formatter::percent(\absint($growth)); |
| 108 | } |
| 109 | public function unformatted_growth() : int |
| 110 | { |
| 111 | return $this->statistic->growth(); |
| 112 | } |
| 113 | public function is_member_of_plugin_group(string $plugin_group) : bool |
| 114 | { |
| 115 | return $this->plugin_group === $plugin_group; |
| 116 | } |
| 117 | public function is_visible_in_dashboard_widget() : bool |
| 118 | { |
| 119 | return $this->is_visible_in_dashboard_widget; |
| 120 | } |
| 121 | private function format($total) |
| 122 | { |
| 123 | // TODO - Ray gettype($value) what are there |
| 124 | switch ($this->format) { |
| 125 | case 'time': |
| 126 | return Number_Formatter::second_to_minute_timestamp($total); |
| 127 | case 'percent': |
| 128 | return Number_Formatter::percent($total, 2); |
| 129 | case 'decimal': |
| 130 | return Number_Formatter::decimal($total, 2); |
| 131 | case 'currency': |
| 132 | return Currency::format($total, \false, \false); |
| 133 | case 'rounded-currency': |
| 134 | return Currency::format($total, \true, \false); |
| 135 | default: |
| 136 | return Number_Formatter::integer($total); |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 |