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
City_Statistics.php
40 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 City_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 | $is_using_woocommerce = \IAWP_SCOPED\iawp_using_woocommerce(); |
| 24 | $query = $is_using_woocommerce ? 'city_statistics_with_woocommerce' : 'city_statistics'; |
| 25 | $rows = Query::query($query, ['start' => $this->formatted_start(), 'end' => $this->formatted_end(), 'prev_start' => $this->prev_period_formatted_start(), 'prev_end' => $this->prev_period_formatted_end()])->rows(); |
| 26 | return self::rows_to_geos($rows); |
| 27 | } |
| 28 | private function rows_to_geos($rows) |
| 29 | { |
| 30 | return \array_map(function ($row) { |
| 31 | $row->views = \intval($row->views); |
| 32 | $row->visitors = \intval($row->visitors); |
| 33 | $row->visitor_ids = \array_map(function ($id) { |
| 34 | return $id; |
| 35 | }, \explode(',', $row->visitor_ids)); |
| 36 | return new Geo($row); |
| 37 | }, $rows); |
| 38 | } |
| 39 | } |
| 40 |