Completed
Push — master ( 020e9d...a8d26b )
by Angus
02:50
created

AdminPanel::_list_complete_titles()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 23
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 17
nc 2
nop 0
dl 0
loc 23
rs 9.0856
c 0
b 0
f 0
1
<?php declare(strict_types=1); defined('BASEPATH') OR exit('No direct script access allowed');
2
3
class AdminPanel extends Admin_Controller {
4
	public function __construct() {
5
		parent::__construct();
6
7
		$this->load->library('table');
8
9
		$this->load->helper('form');
10
		$this->load->library('form_validation');
11
	}
12
13
	public function index() {
14
		$this->header_data['title'] = "Admin Panel";
15
		$this->header_data['page']  = "admin-panel";
16
17
		$this->body_data['complete_list'] = $this->_list_complete_titles();
18
19
		$template = array(
20
			'table_open' => '<table class="table table-striped">'
21
		);
22
23
		$this->table->set_template($template);
24
		$this->_render_page('AdminPanel');
25
	}
26
27
	public function update_normal() {
28
		set_time_limit(0);
29
		$this->Tracker->admin->updateLatestChapters();
30
	}
31
	public function update_custom() {
32
		set_time_limit(0);
33
		$this->Tracker->admin->updateCustom();
34
	}
35
	public function update_titles() {
36
		set_time_limit(0);
37
		$this->Tracker->admin->updateTitles();
38
	}
39
40
	private function _list_complete_titles() {
41
		$query = $this->db->select('tracker_titles.id, tracker_sites.site_class, tracker_titles.title, tracker_titles.title_url')
42
		                  ->from('tracker_chapters')
43
		                  ->join('tracker_titles', 'tracker_chapters.title_id = tracker_titles.id', 'left')
44
		                  ->join('tracker_sites', 'tracker_sites.id = tracker_titles.site_id', 'left')
45
		                  ->like('tracker_chapters.tags', 'complete')
46
		                  ->where('tracker_titles.status', 0)
47
		                  ->get();
48
49
		$completeList = [['id', 'site_class', 'url']];
50
		if($query->num_rows() > 0) {
51
			foreach($query->result() as $row) {
52
				$data = [
53
					'id'         => $row->id,
54
					'site_class' => $row->site_class,
55
					'url'        => "<a href='".$this->Tracker->sites->{$row->site_class}->getFullTitleURL($row->title_url)."'>{$row->title}</a>"
56
				];
57
				$completeList[] = $data;
58
			}
59
		}
60
61
		return $completeList;
62
	}
63
}
64