campaign.php
3 years ago
current_traffic.php
3 years ago
geo.php
3 years ago
page.php
3 years ago
page_author_archive.php
3 years ago
page_date_archive.php
3 years ago
page_home.php
3 years ago
page_not_found.php
3 years ago
page_post_type_archive.php
3 years ago
page_search.php
3 years ago
page_singular.php
3 years ago
page_term_archive.php
3 years ago
referrer.php
3 years ago
view_stats.php
3 years ago
visitor.php
3 years ago
campaign.php
105 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP; |
| 4 | |
| 5 | class Campaign |
| 6 | { |
| 7 | use View_Stats; |
| 8 | |
| 9 | private $campaign_ids; |
| 10 | private $title; |
| 11 | private $utm_source; |
| 12 | private $utm_medium; |
| 13 | private $utm_campaign; |
| 14 | private $utm_term; |
| 15 | private $utm_content; |
| 16 | |
| 17 | public function __construct($row) |
| 18 | { |
| 19 | $this->campaign_ids = $row->campaign_ids; |
| 20 | $this->title = $row->title; |
| 21 | $this->utm_source = $row->utm_source; |
| 22 | $this->utm_medium = $row->utm_medium; |
| 23 | $this->utm_campaign = $row->utm_campaign; |
| 24 | $this->utm_term = $row->utm_term; |
| 25 | $this->utm_content = $row->utm_content; |
| 26 | $this->set_view_stats($row); |
| 27 | } |
| 28 | |
| 29 | /* |
| 30 | * Column names have shared logic between tables. So "title" for resources has the same logic |
| 31 | * as "title" for campaigns. Adding is_deleted ensures that the method can be called even though |
| 32 | * campaigns can never be deleted. A better code base would allow this to be removed. |
| 33 | */ |
| 34 | public function is_deleted() |
| 35 | { |
| 36 | return false; |
| 37 | } |
| 38 | |
| 39 | protected function campaign_ids() |
| 40 | { |
| 41 | return $this->campaign_ids; |
| 42 | } |
| 43 | |
| 44 | public function title() |
| 45 | { |
| 46 | return $this->title; |
| 47 | } |
| 48 | |
| 49 | public function utm_source() |
| 50 | { |
| 51 | return $this->utm_source; |
| 52 | } |
| 53 | |
| 54 | public function utm_medium() |
| 55 | { |
| 56 | return $this->utm_medium; |
| 57 | } |
| 58 | |
| 59 | public function utm_campaign() |
| 60 | { |
| 61 | return $this->utm_campaign; |
| 62 | } |
| 63 | |
| 64 | public function utm_term() |
| 65 | { |
| 66 | return $this->utm_term; |
| 67 | } |
| 68 | |
| 69 | public function utm_content() |
| 70 | { |
| 71 | return $this->utm_content; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * This isn't building a URL param that's used in a URL. This is building a unique id that's |
| 76 | * used for uniqueness in real-times most popular campaign list. |
| 77 | * |
| 78 | * @return string |
| 79 | */ |
| 80 | public function params(): string |
| 81 | { |
| 82 | return http_build_query([ |
| 83 | 'title' => $this->title(), |
| 84 | 'utm_source' => $this->utm_source(), |
| 85 | 'utm_medium' => $this->utm_medium(), |
| 86 | 'utm_campaign' => $this->utm_campaign(), |
| 87 | 'utm_term' => $this->utm_term(), |
| 88 | 'utm_content' => $this->utm_content(), |
| 89 | ]); |
| 90 | } |
| 91 | |
| 92 | public static function campaigns_to_ids(array $campaigns): array |
| 93 | { |
| 94 | if (count($campaigns) === 0) { |
| 95 | return []; |
| 96 | } |
| 97 | |
| 98 | $array_of_arrays = array_map(function ($campaign) { |
| 99 | return $campaign->campaign_ids(); |
| 100 | }, $campaigns); |
| 101 | |
| 102 | return array_merge(...$array_of_arrays); |
| 103 | } |
| 104 | } |
| 105 |