|
1
|
|
|
<?php declare(strict_types=1); defined('BASEPATH') OR exit('No direct script access allowed'); |
|
2
|
|
|
|
|
3
|
|
|
class History_Model extends CI_Model { |
|
4
|
94 |
|
public function __construct() { |
|
5
|
94 |
|
parent::__construct(); |
|
|
|
|
|
|
6
|
|
|
|
|
7
|
94 |
|
$this->load->database(); |
|
8
|
94 |
|
} |
|
9
|
|
|
|
|
10
|
|
|
/*** TITLE HISTORY ***/ |
|
11
|
|
|
public function updateTitleHistory(int $titleID, $oldChapter, string $newChapter, string $newChapterTimestamp) { |
|
12
|
|
|
$success = TRUE; |
|
13
|
|
|
if($oldChapter !== $newChapter) { |
|
14
|
|
|
$success = $this->db->insert('tracker_titles_history', [ |
|
15
|
|
|
'title_id' => $titleID, |
|
16
|
|
|
|
|
17
|
|
|
'old_chapter' => $oldChapter, |
|
18
|
|
|
'new_chapter' => $newChapter, |
|
19
|
|
|
|
|
20
|
|
|
'updated_at' => $newChapterTimestamp |
|
21
|
|
|
]); |
|
22
|
|
|
} |
|
23
|
|
|
return (bool) $success; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/*** USER HISTORY ***/ |
|
27
|
|
View Code Duplication |
public function userAddTitle(int $chapterID, string $chapter, string $category) : bool { |
|
|
|
|
|
|
28
|
|
|
$success = $this->db->insert('tracker_user_history', [ |
|
29
|
|
|
'chapter_id' => $chapterID, |
|
30
|
|
|
|
|
31
|
|
|
'type' => '1', |
|
32
|
|
|
'custom1' => $chapter, |
|
33
|
|
|
'custom2' => $category, |
|
34
|
|
|
|
|
35
|
|
|
'updated_at' => date('Y-m-d H:i:s') |
|
36
|
|
|
]); |
|
37
|
|
|
|
|
38
|
|
|
return $success; |
|
39
|
|
|
} |
|
40
|
|
View Code Duplication |
public function userUpdateTitle(int $chapterID, string $new_chapter) : bool { |
|
|
|
|
|
|
41
|
|
|
$success = $this->db->insert('tracker_user_history', [ |
|
42
|
|
|
'chapter_id' => $chapterID, |
|
43
|
|
|
|
|
44
|
|
|
'type' => '2', |
|
45
|
|
|
'custom1' => $new_chapter, |
|
46
|
|
|
|
|
47
|
|
|
'updated_at' => date('Y-m-d H:i:s') |
|
48
|
|
|
]); |
|
49
|
|
|
|
|
50
|
|
|
return $success; |
|
51
|
|
|
} |
|
52
|
|
|
public function userRemoveTitle(int $chapterID) : bool { |
|
53
|
|
|
$success = $this->db->insert('tracker_user_history', [ |
|
54
|
|
|
'chapter_id' => $chapterID, |
|
55
|
|
|
|
|
56
|
|
|
'type' => '3', |
|
57
|
|
|
|
|
58
|
|
|
'updated_at' => date('Y-m-d H:i:s') |
|
59
|
|
|
]); |
|
60
|
|
|
|
|
61
|
|
|
return $success; |
|
62
|
|
|
} |
|
63
|
|
View Code Duplication |
public function userUpdateTags(int $chapterID, string $new_tags) : bool { |
|
|
|
|
|
|
64
|
|
|
$success = $this->db->insert('tracker_user_history', [ |
|
65
|
|
|
'chapter_id' => $chapterID, |
|
66
|
|
|
|
|
67
|
|
|
'type' => '4', |
|
68
|
|
|
'custom1' => $new_tags, |
|
69
|
|
|
|
|
70
|
|
|
'updated_at' => date('Y-m-d H:i:s') |
|
71
|
|
|
]); |
|
72
|
|
|
|
|
73
|
|
|
return $success; |
|
74
|
|
|
} |
|
75
|
|
View Code Duplication |
public function userUpdateCategory(int $chapterID, string $new_category) : bool { |
|
|
|
|
|
|
76
|
|
|
$success = $this->db->insert('tracker_user_history', [ |
|
77
|
|
|
'chapter_id' => $chapterID, |
|
78
|
|
|
|
|
79
|
|
|
'type' => '5', |
|
80
|
|
|
'custom1' => $new_category, |
|
81
|
|
|
|
|
82
|
|
|
'updated_at' => date('Y-m-d H:i:s') |
|
83
|
|
|
]); |
|
84
|
|
|
|
|
85
|
|
|
return $success; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function userGetHistory(int $page) : array { |
|
89
|
|
|
$rowsPerPage = 50; |
|
90
|
|
|
$query = $this->db |
|
|
|
|
|
|
91
|
|
|
->select('SQL_CALC_FOUND_ROWS |
|
92
|
|
|
tt.title, tt.title_url, |
|
93
|
|
|
ts.site, ts.site_class, |
|
94
|
|
|
tuh.type, tuh.custom1, tuh.custom2, tuh.custom3, tuh.updated_at', FALSE) |
|
95
|
|
|
->from('tracker_user_history AS tuh') |
|
96
|
|
|
->join('tracker_chapters AS tc', 'tuh.chapter_id = tc.id', 'left') |
|
97
|
|
|
->join('tracker_titles AS tt', 'tc.title_id = tt.id', 'left') |
|
98
|
|
|
->join('tracker_sites AS ts', 'tt.site_id = ts.id', 'left') |
|
99
|
|
|
->where('tc.user_id', $this->User->id) |
|
100
|
|
|
->order_by('tuh.id DESC') |
|
101
|
|
|
->limit($rowsPerPage, ($rowsPerPage * ($page - 1))) |
|
102
|
|
|
->get(); |
|
103
|
|
|
|
|
104
|
|
|
$arr = ['rows' => [], 'totalCount' => 0]; |
|
105
|
|
|
if($query->num_rows() > 0) { |
|
106
|
|
|
foreach($query->result() as $row) { |
|
107
|
|
|
$arrRow = []; |
|
108
|
|
|
|
|
109
|
|
|
$arrRow['updated_at'] = $row->updated_at; |
|
110
|
|
|
$arrRow['title'] = $row->title; |
|
111
|
|
|
$arrRow['title_url'] = $this->Tracker->sites->{$row->site_class}->getFullTitleURL($row->title_url); |
|
112
|
|
|
|
|
113
|
|
|
$arrRow['site'] = $row->site; |
|
|
|
|
|
|
114
|
|
|
$arrRow['site_sprite'] = str_replace('.', '-', $row->site); |
|
115
|
|
|
|
|
116
|
|
|
switch($row->type) { |
|
117
|
|
View Code Duplication |
case 1: |
|
|
|
|
|
|
118
|
|
|
$chapterData = $this->Tracker->sites->{$row->site_class}->getChapterData($row->title_url, $row->custom1); |
|
|
|
|
|
|
119
|
|
|
$arrRow['status'] = "Series added at '<a href=\"{$chapterData['url']}\">{$chapterData['number']}</a>' to category '{$row->custom2}'"; |
|
120
|
|
|
break; |
|
121
|
|
|
|
|
122
|
|
View Code Duplication |
case 2: |
|
|
|
|
|
|
123
|
|
|
$chapterData = $this->Tracker->sites->{$row->site_class}->getChapterData($row->title_url, $row->custom1); |
|
|
|
|
|
|
124
|
|
|
$arrRow['status'] = "Chapter updated to '<a href=\"{$chapterData['url']}\">{$chapterData['number']}</a>'"; |
|
125
|
|
|
break; |
|
126
|
|
|
|
|
127
|
|
|
case 3: |
|
128
|
|
|
$arrRow['status'] = "Series removed"; |
|
129
|
|
|
break; |
|
130
|
|
|
|
|
131
|
|
|
case 4: |
|
132
|
|
|
$arrRow['status'] = "Tags set to '{$row->custom1}'"; |
|
133
|
|
|
break; |
|
134
|
|
|
|
|
135
|
|
|
case 5: |
|
136
|
|
|
$arrRow['status'] = "Category set to '{$row->custom1}'"; |
|
137
|
|
|
break; |
|
138
|
|
|
} |
|
139
|
|
|
$arr['rows'][] = $arrRow; |
|
140
|
|
|
} |
|
141
|
|
|
$arr['totalPages'] = ceil($this->db->query('SELECT FOUND_ROWS() count;')->row()->count / $rowsPerPage); |
|
142
|
|
|
} |
|
143
|
|
|
return $arr; |
|
144
|
|
|
} |
|
145
|
|
|
} |
|
146
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: