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
campaigns.php
42 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP; |
| 4 | |
| 5 | class Campaigns extends Range_Query |
| 6 | { |
| 7 | private $results; |
| 8 | |
| 9 | public function fetch() |
| 10 | { |
| 11 | if (is_null($this->results)) { |
| 12 | $this->results = $this->query(); |
| 13 | } |
| 14 | |
| 15 | return $this->results; |
| 16 | } |
| 17 | |
| 18 | private function query() |
| 19 | { |
| 20 | $is_using_woocommerce = Capability_Manager::is_using_woocommerce(); |
| 21 | $query = $is_using_woocommerce ? 'get_campaigns_with_woocommerce' : 'get_campaigns'; |
| 22 | |
| 23 | $rows = Query::query($query, [ |
| 24 | 'start' => $this->formatted_start(), |
| 25 | 'end' => $this->formatted_end(), |
| 26 | 'prev_start' => $this->prev_period_formatted_start(), |
| 27 | 'prev_end' => $this->prev_period_formatted_end(), |
| 28 | ])->rows(); |
| 29 | |
| 30 | return $this->rows_to_campaigns($rows); |
| 31 | } |
| 32 | |
| 33 | private function rows_to_campaigns($rows) |
| 34 | { |
| 35 | return array_map(function ($row) { |
| 36 | $row->campaign_ids = explode(',', $row->campaign_ids); |
| 37 | |
| 38 | return new Campaign($row); |
| 39 | }, $rows); |
| 40 | } |
| 41 | } |
| 42 |