campaigns.php
3 years ago
city_statistics.php
3 years ago
country_statistics.php
3 years ago
current_traffic_finder.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
view.php
3 years ago
views.php
3 years ago
visitors_over_time_finder.php
3 years ago
country_statistics.php
48 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP; |
| 4 | |
| 5 | class Country_Statistics extends Range_Query |
| 6 | { |
| 7 | private $results; |
| 8 | |
| 9 | public function __construct($options = []) |
| 10 | { |
| 11 | parent::__construct($options); |
| 12 | } |
| 13 | |
| 14 | public function fetch() |
| 15 | { |
| 16 | if (is_null($this->results)) { |
| 17 | $this->results = $this->query(); |
| 18 | } |
| 19 | |
| 20 | return $this->results; |
| 21 | } |
| 22 | |
| 23 | private function query() |
| 24 | { |
| 25 | $rows = Query::query('country_statistics', [ |
| 26 | 'start' => $this->formatted_start(), |
| 27 | 'end' => $this->formatted_end(), |
| 28 | 'prev_start' => $this->prev_period_formatted_start(), |
| 29 | 'prev_end' => $this->prev_period_formatted_end(), |
| 30 | ])->rows(); |
| 31 | |
| 32 | return self::rows_to_geos($rows); |
| 33 | } |
| 34 | |
| 35 | private function rows_to_geos($rows) |
| 36 | { |
| 37 | return array_map(function ($row) { |
| 38 | $row->views = intval($row->views); |
| 39 | $row->visitors = intval($row->visitors); |
| 40 | $row->visitor_ids = array_map(function ($id) { |
| 41 | return $id; |
| 42 | }, explode(',', $row->visitor_ids)); |
| 43 | |
| 44 | return new Geo($row); |
| 45 | }, $rows); |
| 46 | } |
| 47 | } |
| 48 |