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
Referrers.php
35 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP_SCOPED\IAWP\Queries; |
| 4 | |
| 5 | use IAWP_SCOPED\IAWP\Models\Referrer; |
| 6 | use IAWP_SCOPED\IAWP\Query; |
| 7 | class Referrers extends Range_Query |
| 8 | { |
| 9 | private $results; |
| 10 | public function fetch() |
| 11 | { |
| 12 | if (\is_null($this->results)) { |
| 13 | $this->results = $this->query(); |
| 14 | } |
| 15 | return $this->results; |
| 16 | } |
| 17 | private function query() |
| 18 | { |
| 19 | $is_using_woocommerce = \IAWP_SCOPED\iawp_using_woocommerce(); |
| 20 | $query = $is_using_woocommerce ? 'get_referrers_with_woocommerce' : 'get_referrers'; |
| 21 | $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(); |
| 22 | return self::rows_to_referrers($rows); |
| 23 | } |
| 24 | private function rows_to_referrers($rows) |
| 25 | { |
| 26 | return \array_map(function ($row) { |
| 27 | $has_referrers = !\is_null($row->referrer_ids); |
| 28 | if ($has_referrers) { |
| 29 | $row->referrer_ids = \explode(',', $row->referrer_ids); |
| 30 | } |
| 31 | return new Referrer($row); |
| 32 | }, $rows); |
| 33 | } |
| 34 | } |
| 35 |