Migrations
3 years ago
ajax
3 years ago
models
3 years ago
queries
3 years ago
sql
3 years ago
tables
3 years ago
utils
3 years ago
campaign_builder.php
3 years ago
capability_manager.php
3 years ago
chart.php
3 years ago
chart_geo.php
3 years ago
chart_svg.php
3 years ago
current_resource.php
3 years ago
dashboard_options.php
3 years ago
dashboard_widget.php
3 years ago
email_reports.php
3 years ago
filters.php
3 years ago
freemius.php
3 years ago
geo_database.php
3 years ago
geo_database_download_job.php
3 years ago
health_check.php
3 years ago
independent_analytics.php
3 years ago
known_referrers.php
3 years ago
pdf.php
3 years ago
query.php
3 years ago
quick_stats.php
3 years ago
real_time.php
3 years ago
rest_api.php
3 years ago
settings.php
3 years ago
track_resource_changes.php
3 years ago
view_counter.php
3 years ago
quick_stats.php
88 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP; |
| 4 | |
| 5 | class Quick_Stats |
| 6 | { |
| 7 | private $views; |
| 8 | private $filtered_views; |
| 9 | |
| 10 | public function __construct(Views $views, Views $unfiltered_views = null) |
| 11 | { |
| 12 | if (is_null($unfiltered_views)) { |
| 13 | $this->views = $views; |
| 14 | } else { |
| 15 | $this->views = $unfiltered_views; |
| 16 | $this->filtered_views = $views; |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | public function get_html() |
| 21 | { |
| 22 | $is_filtered = !is_null($this->filtered_views); |
| 23 | $views = $is_filtered ? $this->filtered_views : $this->views; |
| 24 | |
| 25 | $stats = [[ |
| 26 | 'title' => __('Visitors', 'iawp'), |
| 27 | 'class' => 'visitors', |
| 28 | 'count' => number_format($views->visitors()), |
| 29 | 'growth' => $views->visitors_percentage_growth(), |
| 30 | ], [ |
| 31 | 'title' => __('Views', 'iawp'), |
| 32 | 'class' => 'views', |
| 33 | 'count' => number_format($views->views()), |
| 34 | 'growth' => $views->views_percentage_growth(), |
| 35 | ]]; |
| 36 | |
| 37 | if (Capability_Manager::is_using_woocommerce()) { |
| 38 | $stats[] = [ |
| 39 | 'title' => __('Orders', 'iawp'), |
| 40 | 'class' => 'orders', |
| 41 | 'count' => number_format($views->woocommerce_orders()), |
| 42 | 'growth' => $views->woocommerce_orders_percentage_growth(), |
| 43 | ]; |
| 44 | $stats[] = [ |
| 45 | 'title' => __('Net Sales', 'iawp'), |
| 46 | 'class' => 'net-sales', |
| 47 | 'count' => strip_tags(wc_price($views->woocommerce_net_sales())), |
| 48 | 'growth' => $views->woocommerce_net_sales_percentage_growth(), |
| 49 | ]; |
| 50 | } |
| 51 | |
| 52 | if ($is_filtered) { |
| 53 | $stats[] = [ |
| 54 | 'title' => __('Total Visitors', 'iawp'), |
| 55 | 'class' => 'visitors unfiltered', |
| 56 | 'count' => $this->views->visitors(), |
| 57 | 'growth' => $this->views->visitors_percentage_growth(), |
| 58 | ]; |
| 59 | $stats[] = [ |
| 60 | 'title' => __('Total Views', 'iawp'), |
| 61 | 'class' => 'views unfiltered', |
| 62 | 'count' => $this->views->views(), |
| 63 | 'growth' => $this->views->views_percentage_growth(), |
| 64 | ]; |
| 65 | } |
| 66 | |
| 67 | if ($is_filtered && Capability_Manager::is_using_woocommerce()) { |
| 68 | $stats[] = [ |
| 69 | 'title' => __('Total Orders', 'iawp'), |
| 70 | 'class' => 'orders unfiltered', |
| 71 | 'count' => number_format($this->views->woocommerce_orders()), |
| 72 | 'growth' => $this->views->woocommerce_orders_percentage_growth(), |
| 73 | ]; |
| 74 | $stats[] = [ |
| 75 | 'title' => __('Total Net Sales', 'iawp'), |
| 76 | 'class' => 'net-sales unfiltered', |
| 77 | 'count' => strip_tags(wc_price($this->views->woocommerce_net_sales())), |
| 78 | 'growth' => $this->views->woocommerce_net_sales_percentage_growth(), |
| 79 | ]; |
| 80 | } |
| 81 | |
| 82 | return IAWP()->templates()->render('quick_stats', [ |
| 83 | 'is_filtered' => $is_filtered, |
| 84 | 'stats' => $stats, |
| 85 | ]); |
| 86 | } |
| 87 | } |
| 88 |