| Conditions | 3 |
| Paths | 2 |
| Total Lines | 64 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php declare(strict_types=1); defined('BASEPATH') OR exit('No direct script access allowed'); |
||
| 24 | private function _get_updates() { |
||
| 25 | $update_time = $this->Tracker->admin->getNextUpdateTime("%H:%i"); |
||
| 26 | $this->body_data['update_time'] = explode(':', $update_time); |
||
| 27 | //FIXME: This is just a copy/paste of the query in the admin model. Maybe we should just have a way to grab this normally? |
||
| 28 | // @formatter:off |
||
| 29 | $query = $this->db |
||
| 30 | ->select(' |
||
| 31 | tracker_titles.title, |
||
| 32 | tracker_titles.title_url, |
||
| 33 | tracker_sites.site_class, |
||
| 34 | from_unixtime(MAX(auth_users.last_login)) AS timestamp |
||
| 35 | ') |
||
| 36 | ->from('tracker_titles') |
||
| 37 | ->join('tracker_sites', 'tracker_sites.id = tracker_titles.site_id', 'left') |
||
| 38 | ->join('tracker_chapters', 'tracker_titles.id = tracker_chapters.title_id', 'left') |
||
| 39 | ->join('auth_users', 'tracker_chapters.user_id = auth_users.id', 'left') |
||
| 40 | ->where('tracker_sites.status', 'enabled') |
||
| 41 | ->group_start() |
||
| 42 | //Check if title is marked as on-going... |
||
| 43 | ->where('tracker_titles.status', 0) //TODO: Each title should have specific interval time? |
||
| 44 | //AND matches one of where queries below |
||
| 45 | ->group_start() |
||
| 46 | //Then check if it's NULL (only occurs for new series) |
||
| 47 | ->where('latest_chapter', NULL) |
||
| 48 | //OR if it hasn't updated within the past 12 hours AND isn't a custom update site |
||
| 49 | ->or_group_start() |
||
| 50 | ->where('tracker_sites.use_custom', 'N') |
||
| 51 | ->where("last_checked < DATE_SUB(DATE_ADD(NOW(), INTERVAL '{$update_time}' HOUR_MINUTE), INTERVAL 12 HOUR)") |
||
| 52 | ->group_end() |
||
| 53 | //OR it is a custom update site and hasn't updated within the past 36 hours |
||
| 54 | ->or_where("last_checked < DATE_SUB(DATE_ADD(NOW(), INTERVAL '{$update_time}' HOUR_MINUTE), INTERVAL 36 HOUR)") |
||
| 55 | ->group_end() |
||
| 56 | ->group_end() |
||
| 57 | ->or_group_start() |
||
| 58 | //Check if title is marked as complete... |
||
| 59 | ->where('tracker_titles.status', 1) |
||
| 60 | //Then check if it hasn't updated within the past week |
||
| 61 | ->where("last_checked < DATE_SUB(DATE_ADD(NOW(), INTERVAL '{$update_time}' HOUR_MINUTE), INTERVAL 1 WEEK)") |
||
| 62 | ->group_end() |
||
| 63 | //Status 2 (One-shot) & 255 (Ignore) are both not updated intentionally. |
||
| 64 | |||
| 65 | ->group_by('tracker_titles.id, tracker_chapters.active') |
||
| 66 | //Check if the series is actually being tracked by someone |
||
| 67 | ->having('timestamp IS NOT NULL') |
||
| 68 | //AND if it's currently marked as active by the user |
||
| 69 | ->having('tracker_chapters.active', 'Y') |
||
| 70 | //AND if they have been active in the last 120 hours (5 days) |
||
| 71 | ->having("timestamp > DATE_SUB(DATE_ADD(NOW(), INTERVAL '{$update_time}' HOUR_MINUTE), INTERVAL 120 HOUR)") |
||
| 72 | ->order_by('tracker_titles.title', 'ASC') |
||
| 73 | ->get(); |
||
| 74 | // @formatter:on |
||
| 75 | |||
| 76 | $resultArr = []; |
||
| 77 | if($query->num_rows() > 0) { |
||
| 78 | foreach($query->result() as $row) { |
||
| 79 | $resultArr[] = [ |
||
| 80 | 'site' => $row->site_class, |
||
| 81 | 'full_title_url' => "<a href='".$this->Tracker->sites->{$row->site_class}->getFullTitleURL($row->title_url)."'>{$row->title}</a>" |
||
| 82 | ]; |
||
| 83 | } |
||
| 84 | } |
||
| 85 | |||
| 86 | return $resultArr; |
||
| 87 | } |
||
| 88 | } |
||
| 89 |