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
Chart.php
154 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP; |
| 4 | |
| 5 | use IAWP\Statistics\Intervals\Intervals; |
| 6 | use IAWP\Statistics\Statistics; |
| 7 | use IAWP\Utils\Security; |
| 8 | /** @internal */ |
| 9 | class Chart |
| 10 | { |
| 11 | private $statistics; |
| 12 | private $title; |
| 13 | private $preview; |
| 14 | public function __construct(Statistics $statistics, ?string $title, bool $preview = \false) |
| 15 | { |
| 16 | $this->preview = $preview; |
| 17 | $this->statistics = $statistics; |
| 18 | $this->title = $title; |
| 19 | } |
| 20 | /** |
| 21 | * @return false|string |
| 22 | */ |
| 23 | public function get_html() |
| 24 | { |
| 25 | $labels = \array_map(function ($data_point) { |
| 26 | return Security::json_encode($this->statistics->chart_interval()->get_label_for($data_point[0])); |
| 27 | }, $this->statistics->views()->daily_summary()); |
| 28 | $views_data = \array_map(function ($data_point) { |
| 29 | return $data_point[1]; |
| 30 | }, $this->statistics->views()->daily_summary()); |
| 31 | $visitors_data = \array_map(function ($data_point) { |
| 32 | return $data_point[1]; |
| 33 | }, $this->statistics->visitors()->daily_summary()); |
| 34 | $sessions_data = \array_map(function ($data_point) { |
| 35 | return $data_point[1]; |
| 36 | }, $this->statistics->sessions()->daily_summary()); |
| 37 | $woocommerce_orders_data = \array_map(function ($data_point) { |
| 38 | return $data_point[1]; |
| 39 | }, $this->statistics->wc_orders()->daily_summary()); |
| 40 | $woocommerce_net_sales_data = \array_map(function ($data_point) { |
| 41 | return $data_point[1]; |
| 42 | }, $this->statistics->wc_net_sales()->daily_summary()); |
| 43 | return $this->chart_html($labels, $views_data, $visitors_data, $sessions_data, $woocommerce_orders_data, $woocommerce_net_sales_data, \IAWP\Dashboard_Options::getInstance()->visible_datasets()); |
| 44 | } |
| 45 | private function chart_html(array $labels, array $views, array $visitors, array $sessions, array $woocommerce_orders_data, array $woocommerce_net_sales_data, array $visible_datasets) |
| 46 | { |
| 47 | \ob_start(); |
| 48 | ?> |
| 49 | <div class="chart-container"> |
| 50 | <div class="chart-inner"> |
| 51 | <div class="legend-container"> |
| 52 | <h2 class="legend-title"><?php |
| 53 | echo \esc_html($this->title); |
| 54 | ?></h2> |
| 55 | <div class="legend"></div> |
| 56 | <?php |
| 57 | if ($this->is_full_view()) { |
| 58 | ?> |
| 59 | <select id="chart-interval-select" class="chart-interval-select" data-controller="chart-interval" data-action="chart-interval#setChartInterval"> |
| 60 | <?php |
| 61 | foreach (Intervals::all() as $interval) { |
| 62 | ?> |
| 63 | <option |
| 64 | value="<?php |
| 65 | echo \esc_attr($interval->id()); |
| 66 | ?>" |
| 67 | <?php |
| 68 | \selected($interval->equals($this->statistics->chart_interval())); |
| 69 | ?> |
| 70 | ><?php |
| 71 | echo \esc_html($interval->label()); |
| 72 | ?></option> |
| 73 | <?php |
| 74 | } |
| 75 | ?> |
| 76 | </select> |
| 77 | <?php |
| 78 | } |
| 79 | ?> |
| 80 | </div> |
| 81 | <canvas id="myChart" |
| 82 | data-testid="chart" |
| 83 | width="800" |
| 84 | height="200" |
| 85 | data-controller="chart" |
| 86 | data-chart-locale-value="<?php |
| 87 | echo \get_bloginfo('language'); |
| 88 | ?>" |
| 89 | data-chart-preview-value='<?php |
| 90 | echo $this->is_preview() ? '1' : '0'; |
| 91 | ?>' |
| 92 | data-chart-using-woo-commerce-value='<?php |
| 93 | echo \IAWPSCOPED\iawp_using_woocommerce() ? '1' : '0'; |
| 94 | ?>' |
| 95 | data-chart-labels-value='<?php |
| 96 | echo Security::json_encode($labels); |
| 97 | ?>' |
| 98 | data-chart-views-value='<?php |
| 99 | echo Security::json_encode($views); |
| 100 | ?>' |
| 101 | data-chart-visitors-value='<?php |
| 102 | echo Security::json_encode($visitors); |
| 103 | ?>' |
| 104 | data-chart-visible-datasets-value='<?php |
| 105 | echo Security::json_encode($visible_datasets); |
| 106 | ?>' |
| 107 | <?php |
| 108 | if ($this->is_full_view()) { |
| 109 | ?> |
| 110 | data-chart-sessions-value='<?php |
| 111 | echo Security::json_encode($sessions); |
| 112 | ?>' |
| 113 | <?php |
| 114 | } |
| 115 | ?> |
| 116 | <?php |
| 117 | if ($this->is_full_view() && \IAWPSCOPED\iawp_using_woocommerce()) { |
| 118 | ?> |
| 119 | data-chart-currency-value="<?php |
| 120 | echo get_woocommerce_currency(); |
| 121 | ?>" |
| 122 | data-chart-woocommerce-orders-value='<?php |
| 123 | echo Security::json_encode($woocommerce_orders_data); |
| 124 | ?>' |
| 125 | data-chart-woocommerce-net-sales-value='<?php |
| 126 | echo Security::json_encode($woocommerce_net_sales_data); |
| 127 | ?>' |
| 128 | <?php |
| 129 | } |
| 130 | ?> |
| 131 | > |
| 132 | </canvas> |
| 133 | </div> |
| 134 | </div><?php |
| 135 | $html = \ob_get_contents(); |
| 136 | \ob_end_clean(); |
| 137 | return $html; |
| 138 | } |
| 139 | /** |
| 140 | * @return bool |
| 141 | */ |
| 142 | private function is_preview() : bool |
| 143 | { |
| 144 | return $this->preview; |
| 145 | } |
| 146 | /** |
| 147 | * @return bool |
| 148 | */ |
| 149 | private function is_full_view() : bool |
| 150 | { |
| 151 | return !$this->is_preview(); |
| 152 | } |
| 153 | } |
| 154 |