AJAX
2 years ago
Admin_Page
2 years ago
Date_Range
2 years ago
Filter_Lists
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
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
Query.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
Visitors_Over_Time_Finder.php
57 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP; |
| 4 | |
| 5 | use IAWP\Date_Range\Date_Range; |
| 6 | use IAWP\Interval\Interval; |
| 7 | /** @internal */ |
| 8 | class Visitors_Over_Time_Finder |
| 9 | { |
| 10 | /** |
| 11 | * @var Date_Range |
| 12 | */ |
| 13 | private $date_range; |
| 14 | private $interval; |
| 15 | /** |
| 16 | * @param Date_Range $date_range Range to fetch referrers for |
| 17 | */ |
| 18 | public function __construct(Date_Range $date_range, Interval $interval) |
| 19 | { |
| 20 | $this->date_range = $date_range; |
| 21 | $this->interval = $interval; |
| 22 | } |
| 23 | public function fetch() |
| 24 | { |
| 25 | $rows = $this->interval->fetch($this->date_range); |
| 26 | return $this->rows_to_class($rows); |
| 27 | } |
| 28 | private function rows_to_class(array $rows) : object |
| 29 | { |
| 30 | $date_interval = $this->interval->get_date_interval(); |
| 31 | $date_period = new \DatePeriod($this->date_range->start(), $date_interval, $this->date_range->end()); |
| 32 | $interval_data = []; |
| 33 | $visitors_data = []; |
| 34 | $views_data = []; |
| 35 | foreach ($date_period as $index => $date) { |
| 36 | $current_interval = $index; |
| 37 | $current_visitors = 0; |
| 38 | $current_views = 0; |
| 39 | foreach ($rows as $row) { |
| 40 | $row_interval = \intval($row->interval_ago); |
| 41 | $row_visitors = \intval($row->visitors); |
| 42 | $row_views = \intval($row->views); |
| 43 | if ($row_interval === $index) { |
| 44 | $current_interval = $row_interval; |
| 45 | $current_visitors = $row_visitors; |
| 46 | $current_views = $row_views; |
| 47 | break; |
| 48 | } |
| 49 | } |
| 50 | $interval_data[] = $current_interval; |
| 51 | $visitors_data[] = $current_visitors; |
| 52 | $views_data[] = $current_views; |
| 53 | } |
| 54 | return (object) ['visitors' => $visitors_data, 'views' => $views_data, 'interval_labels_short' => $this->interval->get_short_labels($interval_data), 'interval_labels_full' => $this->interval->get_full_labels($interval_data)]; |
| 55 | } |
| 56 | } |
| 57 |