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