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
resources.php
83 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP; |
| 4 | |
| 5 | class Resources 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 | public function get_resources_as_csv() |
| 19 | { |
| 20 | $resources = $this->fetch(); |
| 21 | $arr = [['Title', 'Views', 'Visitors', 'URL', 'Author', 'Page Type', 'Publish Date', 'Post Category']]; |
| 22 | |
| 23 | foreach ($resources as $resource) { |
| 24 | $arr[] = [ |
| 25 | $resource->title(), |
| 26 | $resource->views(), |
| 27 | $resource->visitors(), |
| 28 | $resource->url(), |
| 29 | $resource->author(), |
| 30 | $resource->type(), |
| 31 | Security::string(date(Date_Format::php(), $resource->date())), |
| 32 | $resource->category(), |
| 33 | ]; |
| 34 | } |
| 35 | |
| 36 | return Array_To_CSV::array2csv($arr); |
| 37 | } |
| 38 | |
| 39 | private function query() |
| 40 | { |
| 41 | $rows = (new DB('get_resources', [ |
| 42 | 'start' => $this->formatted_start(), |
| 43 | 'end' => $this->formatted_end(), |
| 44 | 'prev_start' => $this->prev_period_formatted_start(), |
| 45 | 'prev_end' => $this->prev_period_formatted_end(), |
| 46 | ]))->execute(); |
| 47 | |
| 48 | return $this->rows_to_pages($rows); |
| 49 | } |
| 50 | |
| 51 | private function rows_to_pages($rows) |
| 52 | { |
| 53 | return array_map(function ($row) { |
| 54 | switch ($row->resource) { |
| 55 | case 'singular': |
| 56 | return new Page_Singular($row); |
| 57 | break; |
| 58 | case 'author_archive': |
| 59 | return new Page_Author_Archive($row); |
| 60 | break; |
| 61 | case 'date_archive': |
| 62 | return new Page_Date_Archive($row); |
| 63 | break; |
| 64 | case 'post_type_archive': |
| 65 | return new Page_Post_Type_Archive($row); |
| 66 | break; |
| 67 | case 'term_archive': |
| 68 | return new Page_Term_Archive($row); |
| 69 | break; |
| 70 | case 'search': |
| 71 | return new Page_Search($row); |
| 72 | break; |
| 73 | case 'home': |
| 74 | return new Page_Home($row); |
| 75 | break; |
| 76 | case '404': |
| 77 | return new Page_Not_Found($row); |
| 78 | break; |
| 79 | } |
| 80 | }, $rows); |
| 81 | } |
| 82 | } |
| 83 |