AJAX
1 year ago
Admin_Page
1 year ago
Custom_WordPress_Columns
2 years ago
Data_Pruning
1 year ago
Date_Picker
1 year ago
Date_Range
1 year ago
Ecommerce
1 year ago
Email_Reports
1 year ago
Filter_Lists
2 years ago
Form_Submissions
1 year ago
Interval
2 years ago
Menu_Bar_Stats
1 year ago
Migrations
1 year ago
Models
1 year ago
Public_API
2 years ago
Rows
1 year ago
Statistics
1 year ago
Tables
1 year ago
Utils
1 year ago
Campaign_Builder.php
2 years ago
Capability_Manager.php
1 year ago
Chart.php
1 year ago
Chart_Geo.php
1 year ago
Cron_Job.php
1 year ago
Cron_Job_Autoloader.php
1 year 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
Empty_Report_Option.php
2 years ago
Env.php
1 year ago
Filters.php
1 year ago
Geo_Database_Background_Job.php
2 years ago
Geo_Database_Manager.php
1 year ago
Geoposition.php
2 years ago
Icon_Directory.php
2 years ago
Icon_Directory_Factory.php
2 years ago
Illuminate_Builder.php
1 year ago
Independent_Analytics.php
1 year ago
Interrupt.php
1 year ago
Known_Referrers.php
2 years ago
Patch.php
1 year ago
Plugin_Conflict_Detector.php
1 year ago
Plugin_Group.php
1 year ago
Plugin_Group_Option.php
2 years ago
Query.php
1 year ago
Query_Taps.php
1 year ago
Quick_Stats.php
2 years ago
REST_API.php
1 year ago
Real_Time.php
1 year ago
Report.php
2 years ago
Report_Finder.php
2 years ago
Report_Options_Parser.php
1 year ago
Resource_Identifier.php
1 year ago
Settings.php
1 year ago
Sort_Configuration.php
2 years ago
Track_Resource_Changes.php
2 years ago
View.php
2 years ago
View_Counter.php
1 year ago
Visitors_Over_Time_Finder.php
2 years ago
WP_Option_Cache_Bust.php
2 years ago
Chart.php
54 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP; |
| 4 | |
| 5 | use IAWP\Ecommerce\SureCart_Store; |
| 6 | use IAWP\Statistics\Intervals\Intervals; |
| 7 | use IAWP\Statistics\Statistics; |
| 8 | use IAWP\Utils\Security; |
| 9 | /** @internal */ |
| 10 | class Chart |
| 11 | { |
| 12 | private $statistics; |
| 13 | private $is_preview; |
| 14 | public function __construct(Statistics $statistics, bool $is_preview = \false) |
| 15 | { |
| 16 | $this->statistics = $statistics; |
| 17 | $this->is_preview = $is_preview; |
| 18 | } |
| 19 | public function get_html() : string |
| 20 | { |
| 21 | $labels = \array_map(function ($data_point) { |
| 22 | return Security::json_encode($this->statistics->chart_interval()->get_label_for($data_point[0])); |
| 23 | }, $this->statistics->get_statistic('views')->statistic_over_time()); |
| 24 | $data = []; |
| 25 | foreach ($this->statistics->get_statistics() as $statistic) { |
| 26 | $data[$statistic->id()] = \array_map(function ($data_point) { |
| 27 | return $data_point[1]; |
| 28 | }, $statistic->statistic_over_time()); |
| 29 | } |
| 30 | $options = \IAWP\Dashboard_Options::getInstance(); |
| 31 | $primary_statistic = $this->statistics->get_statistic($options->primary_chart_metric_id()) ?? $this->statistics->get_statistic('visitors'); |
| 32 | $secondary_statistic = \is_string($options->secondary_chart_metric_id()) ? $this->statistics->get_statistic($options->secondary_chart_metric_id()) : null; |
| 33 | return \IAWPSCOPED\iawp_blade()->run('chart', ['chart' => $this, 'intervals' => Intervals::all(), 'current_interval' => $this->statistics->chart_interval(), 'available_datasets' => $this->statistics->get_grouped_statistics(), 'primary_chart_metric_id' => $primary_statistic->id(), 'secondary_chart_metric_id' => \is_null($secondary_statistic) ? null : $secondary_statistic->id(), 'stimulus_values' => ['locale' => \get_bloginfo('language'), 'currency' => $this->get_currency_code(), 'is-preview' => $this->is_preview() ? '1' : '0', 'primary-chart-metric-id' => $primary_statistic->id(), 'primary-chart-metric-name' => $primary_statistic->name(), 'secondary-chart-metric-id' => \is_null($secondary_statistic) ? null : $secondary_statistic->id(), 'secondary-chart-metric-name' => \is_null($secondary_statistic) ? null : $secondary_statistic->name(), 'labels' => $labels, 'data' => $data]]); |
| 34 | } |
| 35 | public function is_preview() : bool |
| 36 | { |
| 37 | return $this->is_preview; |
| 38 | } |
| 39 | public function encode_json(array $array) : string |
| 40 | { |
| 41 | return Security::json_encode($array); |
| 42 | } |
| 43 | private function get_currency_code() : ?string |
| 44 | { |
| 45 | if (\IAWPSCOPED\iawp()->is_woocommerce_support_enabled()) { |
| 46 | return get_woocommerce_currency(); |
| 47 | } |
| 48 | if (\IAWPSCOPED\iawp()->is_surecart_support_enabled()) { |
| 49 | return SureCart_Store::get_currency_code(); |
| 50 | } |
| 51 | return null; |
| 52 | } |
| 53 | } |
| 54 |