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
Campaigns.php
32 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP_SCOPED\IAWP\Queries; |
| 4 | |
| 5 | use IAWP_SCOPED\IAWP\Models\Campaign; |
| 6 | use IAWP_SCOPED\IAWP\Query; |
| 7 | class Campaigns 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_campaigns_with_woocommerce' : 'get_campaigns'; |
| 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 $this->rows_to_campaigns($rows); |
| 23 | } |
| 24 | private function rows_to_campaigns($rows) |
| 25 | { |
| 26 | return \array_map(function ($row) { |
| 27 | $row->campaign_ids = \explode(',', $row->campaign_ids); |
| 28 | return new Campaign($row); |
| 29 | }, $rows); |
| 30 | } |
| 31 | } |
| 32 |