Completed
Push — master ( 58f85f...ef5fb6 )
by Angus
03:07
created
application/models/Tracker_Model.php 1 patch
Indentation   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -155,9 +155,9 @@  discard block
 block discarded – undo
155 155
 
156 156
 	public function getSiteDataFromURL(string $site_url) {
157 157
 		$query = $this->db->select('id, site_class')
158
-		                  ->from('tracker_sites')
159
-		                  ->where('site', $site_url)
160
-		                  ->get();
158
+						  ->from('tracker_sites')
159
+						  ->where('site', $site_url)
160
+						  ->get();
161 161
 
162 162
 		if($query->num_rows() > 0) {
163 163
 			$siteData = $query->row();
@@ -168,11 +168,11 @@  discard block
 block discarded – undo
168 168
 
169 169
 	public function getTitleID(string $titleURL, int $siteID) {
170 170
 		$query = $this->db->select('tracker_titles.id, tracker_titles.title, tracker_titles.title_url, tracker_titles.complete, tracker_sites.site_class, (tracker_titles.last_checked > DATE_SUB(NOW(), INTERVAL 3 DAY)) AS active', FALSE)
171
-		                  ->from('tracker_titles')
172
-		                  ->join('tracker_sites', 'tracker_sites.id = tracker_titles.site_id', 'left')
173
-		                  ->where('tracker_titles.title_url', $titleURL)
174
-		                  ->where('tracker_titles.site_id', $siteID)
175
-		                  ->get();
171
+						  ->from('tracker_titles')
172
+						  ->join('tracker_sites', 'tracker_sites.id = tracker_titles.site_id', 'left')
173
+						  ->where('tracker_titles.title_url', $titleURL)
174
+						  ->where('tracker_titles.site_id', $siteID)
175
+						  ->get();
176 176
 
177 177
 		if($query->num_rows() > 0) {
178 178
 			$id = (int) $query->row('id');
@@ -185,8 +185,8 @@  discard block
 block discarded – undo
185 185
 						//Make sure last_checked is always updated on successful run.
186 186
 						//CHECK: Is there a reason we aren't just doing this in updateTitleById?
187 187
 						$this->db->set('last_checked', 'CURRENT_TIMESTAMP', FALSE)
188
-						         ->where('id', $id)
189
-						         ->update('tracker_titles');
188
+								 ->where('id', $id)
189
+								 ->update('tracker_titles');
190 190
 					}
191 191
 				} else {
192 192
 					log_message('error', "{$query->row('title')} failed to update successfully");
@@ -224,14 +224,14 @@  discard block
 block discarded – undo
224 224
 			}
225 225
 
226 226
 			$idQuery = $this->db->select('id')
227
-			                    ->where('user_id', $userID)
228
-			                    ->where('title_id', $titleID)
229
-			                    ->get('tracker_chapters');
227
+								->where('user_id', $userID)
228
+								->where('title_id', $titleID)
229
+								->get('tracker_chapters');
230 230
 			if($idQuery->num_rows() > 0) {
231 231
 				$success = (bool) $this->db->set(['current_chapter' => $chapter, 'active' => 'Y', 'last_updated' => NULL])
232
-				                    ->where('user_id', $userID)
233
-				                    ->where('title_id', $titleID)
234
-				                    ->update('tracker_chapters');
232
+									->where('user_id', $userID)
233
+									->where('title_id', $titleID)
234
+									->update('tracker_chapters');
235 235
 
236 236
 				if($success) {
237 237
 					$idQueryRow = $idQuery->row();
@@ -256,9 +256,9 @@  discard block
 block discarded – undo
256 256
 
257 257
 	public function updateTrackerByID(int $userID, int $chapterID, string $chapter) : bool {
258 258
 		$success = (bool) $this->db->set(['current_chapter' => $chapter, 'active' => 'Y', 'last_updated' => NULL])
259
-		                    ->where('user_id', $userID)
260
-		                    ->where('id', $chapterID)
261
-		                    ->update('tracker_chapters');
259
+							->where('user_id', $userID)
260
+							->where('id', $chapterID)
261
+							->update('tracker_chapters');
262 262
 
263 263
 		if($success) {
264 264
 			$this->History->userUpdateTitle($chapterID, $chapter);
@@ -271,23 +271,23 @@  discard block
 block discarded – undo
271 271
 		//This is to allow user history to function properly.
272 272
 
273 273
 		$success = $this->db->set(['active' => 'N', 'last_updated' => NULL])
274
-		                    ->where('user_id', $userID)
275
-		                    ->where('id', $chapterID)
276
-		                    ->update('tracker_chapters');
274
+							->where('user_id', $userID)
275
+							->where('id', $chapterID)
276
+							->update('tracker_chapters');
277 277
 
278 278
 		return (bool) $success;
279 279
 	}
280 280
 	private function updateTitleById(int $id, string $latestChapter) {
281 281
 		//FIXME: Really not too happy with how we're doing history stuff here, it just feels messy.
282 282
 		$query = $this->db->select('latest_chapter AS current_chapter')
283
-		                  ->from('tracker_titles')
284
-		                  ->where('id', $id)
285
-		                  ->get();
283
+						  ->from('tracker_titles')
284
+						  ->where('id', $id)
285
+						  ->get();
286 286
 		$row = $query->row();
287 287
 
288 288
 		$success = $this->db->set(['latest_chapter' => $latestChapter]) //last_updated gets updated via a trigger if something changes
289
-		                    ->where('id', $id)
290
-		                    ->update('tracker_titles');
289
+							->where('id', $id)
290
+							->update('tracker_titles');
291 291
 
292 292
 		//Update History
293 293
 		//NOTE: To avoid doing another query to grab the last_updated time, we just use time() which <should> get the same thing.
@@ -298,16 +298,16 @@  discard block
 block discarded – undo
298 298
 	}
299 299
 	private function updateTitleDataById(int $id, array $titleData) {
300 300
 		$success = $this->db->set($titleData)
301
-		                    ->where('id', $id)
302
-		                    ->update('tracker_titles');
301
+							->where('id', $id)
302
+							->update('tracker_titles');
303 303
 
304 304
 		return (bool) $success;
305 305
 	}
306 306
 	private function addTitle(string $titleURL, int $siteID) {
307 307
 		$query = $this->db->select('site, site_class')
308
-		                  ->from('tracker_sites')
309
-		                  ->where('id', $siteID)
310
-		                  ->get();
308
+						  ->from('tracker_sites')
309
+						  ->where('id', $siteID)
310
+						  ->get();
311 311
 
312 312
 		$titleData = $this->sites->{$query->row()->site_class}->getTitleData($titleURL);
313 313
 		$this->db->insert('tracker_titles', array_merge($titleData, ['title_url' => $titleURL, 'site_id' => $siteID]));
@@ -358,8 +358,8 @@  discard block
 block discarded – undo
358 358
 						//Make sure last_checked is always updated on successful run.
359 359
 						//CHECK: Is there a reason we aren't just doing this in updateTitleById?
360 360
 						$this->db->set('last_checked', 'CURRENT_TIMESTAMP', FALSE)
361
-						         ->where('id', $row->id)
362
-						         ->update('tracker_titles');
361
+								 ->where('id', $row->id)
362
+								 ->update('tracker_titles');
363 363
 
364 364
 						print " - ({$titleData['latest_chapter']})\n";
365 365
 					}
@@ -476,9 +476,9 @@  discard block
 block discarded – undo
476 476
 	}
477 477
 	public function setCategoryTrackerByID(int $userID, int $chapterID, string $category) : bool {
478 478
 		$success = $this->db->set(['category' => $category, 'active' => 'Y', 'last_updated' => NULL])
479
-		                    ->where('user_id', $userID)
480
-		                    ->where('id', $chapterID)
481
-		                    ->update('tracker_chapters');
479
+							->where('user_id', $userID)
480
+							->where('id', $chapterID)
481
+							->update('tracker_chapters');
482 482
 
483 483
 		return (bool) $success;
484 484
 	}
@@ -488,9 +488,9 @@  discard block
 block discarded – undo
488 488
 		$success = FALSE;
489 489
 		if(preg_match("/^[a-z0-9-_,]{0,255}$/", $tag_string)) {
490 490
 			$success = (bool) $this->db->set(['tags' => $tag_string, 'active' => 'Y', 'last_updated' => NULL])
491
-			                           ->where('user_id', $userID)
492
-			                           ->where('id', $chapterID)
493
-			                           ->update('tracker_chapters');
491
+									   ->where('user_id', $userID)
492
+									   ->where('id', $chapterID)
493
+									   ->update('tracker_chapters');
494 494
 		}
495 495
 
496 496
 		if($success) {
@@ -528,23 +528,23 @@  discard block
 block discarded – undo
528 528
 
529 529
 			//We need the series to be tracked
530 530
 			$idCQuery = $this->db->select('id')
531
-			                    ->where('user_id', $userID)
532
-			                    ->where('title_id', $titleID)
533
-			                    ->get('tracker_chapters');
531
+								->where('user_id', $userID)
532
+								->where('title_id', $titleID)
533
+								->get('tracker_chapters');
534 534
 			if($idCQuery->num_rows() > 0) {
535 535
 				$idCQueryRow = $idCQuery->row();
536 536
 
537 537
 				//Check if it is already favourited
538 538
 				$idFQuery = $this->db->select('id')
539
-				                    ->where('chapter_id', $idCQueryRow->id)
540
-				                    ->where('chapter', $chapter)
541
-				                    ->get('tracker_favourites');
539
+									->where('chapter_id', $idCQueryRow->id)
540
+									->where('chapter', $chapter)
541
+									->get('tracker_favourites');
542 542
 				if($idFQuery->num_rows() > 0) {
543 543
 					//Chapter is already favourited, so remove it from DB
544 544
 					$idFQueryRow = $idFQuery->row();
545 545
 
546 546
 					$isSuccess = (bool) $this->db->where('id', $idFQueryRow->id)
547
-					                           ->delete('tracker_favourites');
547
+											   ->delete('tracker_favourites');
548 548
 
549 549
 					if($isSuccess) {
550 550
 						$success = array(
@@ -615,11 +615,11 @@  discard block
 block discarded – undo
615 615
 
616 616
 	public function getUsedCategories(int $userID) : array {
617 617
 		$query = $this->db->distinct()
618
-		                  ->select('category')
619
-		                  ->from('tracker_chapters')
620
-		                  ->where('tracker_chapters.active', 'Y')
621
-		                  ->where('user_id', $userID)
622
-		                  ->get();
618
+						  ->select('category')
619
+						  ->from('tracker_chapters')
620
+						  ->where('tracker_chapters.active', 'Y')
621
+						  ->where('user_id', $userID)
622
+						  ->get();
623 623
 
624 624
 		return array_column($query->result_array(), 'category');
625 625
 	}
@@ -631,51 +631,51 @@  discard block
 block discarded – undo
631 631
 
632 632
 		//$this->db->cache_on();
633 633
 		$queryUsers = $this->db->select([
634
-		                      'COUNT(*) AS total_users',
635
-		                      'SUM(CASE WHEN api_key IS NOT NULL THEN 1 ELSE 0 END) AS validated_users',
636
-		                      'SUM(CASE WHEN (api_key IS NOT NULL AND from_unixtime(last_login) > DATE_SUB(NOW(), INTERVAL 7 DAY)) THEN 1 ELSE 0 END) AS active_users'
637
-		                  ], FALSE)
638
-		                  ->from('auth_users')
639
-		                  ->get();
634
+							  'COUNT(*) AS total_users',
635
+							  'SUM(CASE WHEN api_key IS NOT NULL THEN 1 ELSE 0 END) AS validated_users',
636
+							  'SUM(CASE WHEN (api_key IS NOT NULL AND from_unixtime(last_login) > DATE_SUB(NOW(), INTERVAL 7 DAY)) THEN 1 ELSE 0 END) AS active_users'
637
+						  ], FALSE)
638
+						  ->from('auth_users')
639
+						  ->get();
640 640
 		$stats = array_merge($stats, $queryUsers->result_array()[0]);
641 641
 
642 642
 		$queryCounts = $this->db->select([
643
-		                      'tracker_titles.title',
644
-		                      'COUNT(tracker_chapters.title_id) AS count'
645
-		                  ], FALSE)
646
-		                  ->from('tracker_chapters')
647
-		                  ->join('tracker_titles', 'tracker_titles.id = tracker_chapters.title_id', 'left')
648
-		                  ->group_by('tracker_chapters.title_id')
649
-		                  ->having('count > 1')
650
-		                  ->order_by('count DESC')
651
-		                  ->get();
643
+							  'tracker_titles.title',
644
+							  'COUNT(tracker_chapters.title_id) AS count'
645
+						  ], FALSE)
646
+						  ->from('tracker_chapters')
647
+						  ->join('tracker_titles', 'tracker_titles.id = tracker_chapters.title_id', 'left')
648
+						  ->group_by('tracker_chapters.title_id')
649
+						  ->having('count > 1')
650
+						  ->order_by('count DESC')
651
+						  ->get();
652 652
 		$stats['titles_tracked_more'] = count($queryCounts->result_array());
653 653
 		$stats['top_title_name']  = $queryCounts->result_array()[0]['title'] ?? 'N/A';
654 654
 		$stats['top_title_count'] = $queryCounts->result_array()[0]['count'] ?? 'N/A';
655 655
 
656 656
 		$queryTitles = $this->db->select([
657
-		                      'COUNT(DISTINCT tracker_titles.id) AS total_titles',
658
-		                      'COUNT(DISTINCT tracker_titles.site_id) AS total_sites',
659
-		                      'SUM(CASE WHEN from_unixtime(auth_users.last_login) > DATE_SUB(NOW(), INTERVAL 120 HOUR) IS NOT NULL THEN 0 ELSE 1 END) AS inactive_titles',
660
-		                      'SUM(CASE WHEN (tracker_titles.last_updated > DATE_SUB(NOW(), INTERVAL 24 HOUR)) THEN 1 ELSE 0 END) AS updated_titles'
661
-		                  ], FALSE)
662
-		                  ->from('tracker_titles')
663
-		                  ->join('tracker_sites', 'tracker_sites.id = tracker_titles.site_id', 'left')
664
-		                  ->join('tracker_chapters', 'tracker_titles.id = tracker_chapters.title_id', 'left')
665
-		                  ->join('auth_users', 'tracker_chapters.user_id = auth_users.id', 'left')
666
-		                  ->get();
657
+							  'COUNT(DISTINCT tracker_titles.id) AS total_titles',
658
+							  'COUNT(DISTINCT tracker_titles.site_id) AS total_sites',
659
+							  'SUM(CASE WHEN from_unixtime(auth_users.last_login) > DATE_SUB(NOW(), INTERVAL 120 HOUR) IS NOT NULL THEN 0 ELSE 1 END) AS inactive_titles',
660
+							  'SUM(CASE WHEN (tracker_titles.last_updated > DATE_SUB(NOW(), INTERVAL 24 HOUR)) THEN 1 ELSE 0 END) AS updated_titles'
661
+						  ], FALSE)
662
+						  ->from('tracker_titles')
663
+						  ->join('tracker_sites', 'tracker_sites.id = tracker_titles.site_id', 'left')
664
+						  ->join('tracker_chapters', 'tracker_titles.id = tracker_chapters.title_id', 'left')
665
+						  ->join('auth_users', 'tracker_chapters.user_id = auth_users.id', 'left')
666
+						  ->get();
667 667
 		$stats = array_merge($stats, $queryTitles->result_array()[0]);
668 668
 
669 669
 		$querySites = $this->db->select([
670
-		                      'tracker_sites.site',
671
-		                      'COUNT(*) AS count'
672
-		                  ], FALSE)
673
-		                  ->from('tracker_titles')
674
-		                  ->join('tracker_sites', 'tracker_sites.id = tracker_titles.site_id', 'left')
675
-		                  ->group_by('tracker_titles.site_id')
676
-		                  ->order_by('count DESC')
677
-		                  ->limit(3)
678
-		                  ->get();
670
+							  'tracker_sites.site',
671
+							  'COUNT(*) AS count'
672
+						  ], FALSE)
673
+						  ->from('tracker_titles')
674
+						  ->join('tracker_sites', 'tracker_sites.id = tracker_titles.site_id', 'left')
675
+						  ->group_by('tracker_titles.site_id')
676
+						  ->order_by('count DESC')
677
+						  ->limit(3)
678
+						  ->get();
679 679
 		$querySitesResult = $querySites->result_array();
680 680
 		$stats['rank1_site']       = $querySitesResult[0]['site'];
681 681
 		$stats['rank1_site_count'] = $querySitesResult[0]['count'];
@@ -685,17 +685,17 @@  discard block
 block discarded – undo
685 685
 		$stats['rank3_site_count'] = $querySitesResult[2]['count'];
686 686
 
687 687
 		$queryTitlesU = $this->db->select([
688
-		                      'COUNT(*) AS title_updated_count'
689
-		                  ], FALSE)
690
-		                  ->from('tracker_titles_history')
691
-		                  ->get();
688
+							  'COUNT(*) AS title_updated_count'
689
+						  ], FALSE)
690
+						  ->from('tracker_titles_history')
691
+						  ->get();
692 692
 		$stats = array_merge($stats, $queryTitlesU->result_array()[0]);
693 693
 
694 694
 		$queryUsersU = $this->db->select([
695
-		                      'COUNT(*) AS user_updated_count'
696
-		                  ], FALSE)
697
-		                  ->from('tracker_user_history')
698
-		                  ->get();
695
+							  'COUNT(*) AS user_updated_count'
696
+						  ], FALSE)
697
+						  ->from('tracker_user_history')
698
+						  ->get();
699 699
 		$stats = array_merge($stats, $queryUsersU->result_array()[0]);
700 700
 
701 701
 		$stats['live_time'] = timespan(/*2016-09-10T03:17:19*/ 1473477439, time(), 2);
Please login to merge, or discard this patch.