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
Resources.php
64 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP\Queries; |
| 4 | |
| 5 | use IAWP\Models\Page_Author_Archive; |
| 6 | use IAWP\Models\Page_Date_Archive; |
| 7 | use IAWP\Models\Page_Home; |
| 8 | use IAWP\Models\Page_Not_Found; |
| 9 | use IAWP\Models\Page_Post_Type_Archive; |
| 10 | use IAWP\Models\Page_Search; |
| 11 | use IAWP\Models\Page_Singular; |
| 12 | use IAWP\Models\Page_Term_Archive; |
| 13 | use IAWP\Query; |
| 14 | |
| 15 | class Resources extends Range_Query |
| 16 | { |
| 17 | private $results; |
| 18 | |
| 19 | public function fetch() |
| 20 | { |
| 21 | if (is_null($this->results)) { |
| 22 | $this->results = $this->query(); |
| 23 | } |
| 24 | |
| 25 | return $this->results; |
| 26 | } |
| 27 | |
| 28 | private function query() |
| 29 | { |
| 30 | $rows = Query::query('get_resources', [ |
| 31 | 'start' => $this->formatted_start(), |
| 32 | 'end' => $this->formatted_end(), |
| 33 | 'prev_start' => $this->prev_period_formatted_start(), |
| 34 | 'prev_end' => $this->prev_period_formatted_end(), |
| 35 | ])->rows(); |
| 36 | |
| 37 | return $this->rows_to_pages($rows); |
| 38 | } |
| 39 | |
| 40 | private function rows_to_pages($rows) |
| 41 | { |
| 42 | return array_map(function ($row) { |
| 43 | switch ($row->resource) { |
| 44 | case 'singular': |
| 45 | return new Page_Singular($row); |
| 46 | case 'author_archive': |
| 47 | return new Page_Author_Archive($row); |
| 48 | case 'date_archive': |
| 49 | return new Page_Date_Archive($row); |
| 50 | case 'post_type_archive': |
| 51 | return new Page_Post_Type_Archive($row); |
| 52 | case 'term_archive': |
| 53 | return new Page_Term_Archive($row); |
| 54 | case 'search': |
| 55 | return new Page_Search($row); |
| 56 | case 'home': |
| 57 | return new Page_Home($row); |
| 58 | case '404': |
| 59 | return new Page_Not_Found($row); |
| 60 | } |
| 61 | }, $rows); |
| 62 | } |
| 63 | } |
| 64 |