Campaigns.php
3 years ago
City_Statistics.php
3 years ago
Country_Statistics.php
3 years ago
Current_Traffic_Finder.php
3 years ago
Interval.php
3 years ago
Minute_Interval.php
3 years ago
Range_Query.php
3 years ago
Referrers.php
3 years ago
Reset_Database.php
3 years ago
Resources.php
3 years ago
Ten_Second_Interval.php
3 years ago
View.php
3 years ago
Views.php
3 years ago
Visitors_Over_Time_Finder.php
3 years ago
Country_Statistics.php
39 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP_SCOPED\IAWP\Queries; |
| 4 | |
| 5 | use IAWP_SCOPED\IAWP\Models\Geo; |
| 6 | use IAWP_SCOPED\IAWP\Query; |
| 7 | class Country_Statistics extends Range_Query |
| 8 | { |
| 9 | private $results; |
| 10 | public function __construct($options = []) |
| 11 | { |
| 12 | parent::__construct($options); |
| 13 | } |
| 14 | public function fetch() |
| 15 | { |
| 16 | if (\is_null($this->results)) { |
| 17 | $this->results = $this->query(); |
| 18 | } |
| 19 | return $this->results; |
| 20 | } |
| 21 | private function query() |
| 22 | { |
| 23 | $rows = Query::query('country_statistics', ['start' => $this->formatted_start(), 'end' => $this->formatted_end(), 'prev_start' => $this->prev_period_formatted_start(), 'prev_end' => $this->prev_period_formatted_end()])->rows(); |
| 24 | return self::rows_to_geos($rows); |
| 25 | } |
| 26 | private function rows_to_geos($rows) |
| 27 | { |
| 28 | return \array_map(function ($row) { |
| 29 | $row->views = \intval($row->views); |
| 30 | $row->visitors = \intval($row->visitors); |
| 31 | $row->sessions = \intval($row->sessions); |
| 32 | $row->visitor_ids = \array_map(function ($id) { |
| 33 | return $id; |
| 34 | }, \explode(',', $row->visitor_ids)); |
| 35 | return new Geo($row); |
| 36 | }, $rows); |
| 37 | } |
| 38 | } |
| 39 |