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
WooCommerce_Stats.php
3 years ago
View_Stats.php
90 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP\Models; |
| 4 | |
| 5 | trait View_Stats |
| 6 | { |
| 7 | protected $views; |
| 8 | protected $prev_period_views; |
| 9 | protected $visitors; |
| 10 | protected $prev_period_visitors; |
| 11 | protected $sessions; |
| 12 | protected $prev_period_sessions; |
| 13 | |
| 14 | final protected function set_view_stats($row) |
| 15 | { |
| 16 | $this->views = isset($row->views) ? intval($row->views) : null; |
| 17 | $this->prev_period_views = isset($row->prev_period_views) ? intval($row->prev_period_views) : null; |
| 18 | $this->visitors = isset($row->visitors) ? intval($row->visitors) : null; |
| 19 | $this->prev_period_visitors = isset($row->prev_period_visitors) ? intval($row->prev_period_visitors) : null; |
| 20 | $this->sessions = isset($row->sessions) ? intval($row->sessions) : null; |
| 21 | $this->prev_period_sessions = isset($row->prev_period_sessions) ? intval($row->prev_period_sessions) : null; |
| 22 | } |
| 23 | |
| 24 | final public function views() |
| 25 | { |
| 26 | return $this->views; |
| 27 | } |
| 28 | |
| 29 | final public function prev_period_views() |
| 30 | { |
| 31 | return $this->prev_period_views; |
| 32 | } |
| 33 | |
| 34 | final public function views_growth() |
| 35 | { |
| 36 | $current = $this->views(); |
| 37 | $previous = $this->prev_period_views(); |
| 38 | |
| 39 | if ($current == 0 || $previous == 0) { |
| 40 | return 0; |
| 41 | } else { |
| 42 | return (($current - $previous) / $previous) * 100; |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | final public function visitors() |
| 47 | { |
| 48 | return $this->visitors; |
| 49 | } |
| 50 | |
| 51 | final public function prev_period_visitors() |
| 52 | { |
| 53 | return $this->prev_period_visitors; |
| 54 | } |
| 55 | |
| 56 | final public function visitors_growth() |
| 57 | { |
| 58 | $current = $this->visitors(); |
| 59 | $previous = $this->prev_period_visitors(); |
| 60 | |
| 61 | if ($current == 0 || $previous == 0) { |
| 62 | return 0; |
| 63 | } else { |
| 64 | return (($current - $previous) / $previous) * 100; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | final public function sessions() |
| 69 | { |
| 70 | return $this->sessions; |
| 71 | } |
| 72 | |
| 73 | final public function prev_period_sessions() |
| 74 | { |
| 75 | return $this->prev_period_sessions; |
| 76 | } |
| 77 | |
| 78 | final public function sessions_growth() |
| 79 | { |
| 80 | $current = $this->sessions(); |
| 81 | $previous = $this->prev_period_sessions(); |
| 82 | |
| 83 | if ($current == 0 || $previous == 0) { |
| 84 | return 0; |
| 85 | } else { |
| 86 | return (($current - $previous) / $previous) * 100; |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 |