|
1
|
|
|
<?php declare(strict_types=1); defined('BASEPATH') OR exit('No direct script access allowed'); |
|
2
|
|
|
|
|
3
|
|
|
class Tracker_Category_Model extends Tracker_Base_Model { |
|
4
|
96 |
|
public function __construct() { |
|
5
|
96 |
|
parent::__construct(); |
|
6
|
96 |
|
} |
|
7
|
|
|
|
|
8
|
|
|
public function setByID(int $userID, int $chapterID, string $category) : bool { |
|
9
|
|
|
$success = $this->db->set(['category' => $category, 'active' => 'Y', 'last_updated' => NULL]) |
|
10
|
|
|
->where('user_id', $userID) |
|
11
|
|
|
->where('id', $chapterID) |
|
12
|
|
|
->update('tracker_chapters'); |
|
13
|
|
|
|
|
14
|
|
|
return (bool) $success; |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
public function setByIDList(array $idList, string $category) : array { |
|
18
|
|
|
/* |
|
19
|
|
|
* 0 = Success |
|
20
|
|
|
* 1 = Invalid IDs |
|
21
|
|
|
* 2 = Invalid category |
|
22
|
|
|
*/ |
|
23
|
|
|
$status = ['code' => 0]; |
|
24
|
|
|
|
|
25
|
|
|
if(in_array($category, array_keys($this->enabledCategories))) { |
|
26
|
|
|
foreach($idList as $id) { |
|
27
|
|
|
if(!(ctype_digit($id) && $this->setByID($this->User->id, (int) $id, $category))) { |
|
28
|
|
|
$status['code'] = 1; |
|
29
|
|
|
} else { |
|
30
|
|
|
//Category update was successful, update history too. |
|
31
|
|
|
$this->History->userUpdateCategory((int) $id, $category); |
|
32
|
|
|
} |
|
33
|
|
|
} |
|
34
|
|
|
} else { |
|
35
|
|
|
$status['code'] = 2; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
return $status; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function getUsed(int $userID) : array { |
|
42
|
|
|
$query = $this->db->distinct() |
|
43
|
|
|
->select('category') |
|
44
|
|
|
->from('tracker_chapters') |
|
45
|
|
|
->where('tracker_chapters.active', 'Y') |
|
46
|
|
|
->where('user_id', $userID) |
|
47
|
|
|
->get(); |
|
48
|
|
|
|
|
49
|
|
|
return array_column($query->result_array(), 'category'); |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|