1
|
|
|
<?php |
2
|
|
|
namespace AL\Common\DAO; |
3
|
|
|
|
4
|
|
|
require_once __DIR__."/../../lib/Db.php"; |
5
|
|
|
require_once __DIR__."/../Model/Database/ChangeLog.php"; |
6
|
|
|
require_once __DIR__."/../Model/User/User.php"; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* DAO for DB Change Log |
10
|
|
|
*/ |
11
|
|
|
class ChangeLogDAO { |
12
|
|
|
private $mysqli; |
13
|
|
|
|
14
|
|
|
public function __construct($mysqli) { |
15
|
|
|
$this->mysqli = $mysqli; |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Insert a new change log entry |
20
|
|
|
* |
21
|
|
|
* @param \AL\Common\Model\Database\Changelog Change log to insert |
22
|
|
|
* @return integer ID of the inserted change log |
23
|
|
|
*/ |
24
|
|
|
public function insertChangeLog($change_log) { |
25
|
|
|
$stmt = \AL\Db\execute_query( |
26
|
|
|
"ChangeLogDAO: insertChangeLog", |
27
|
|
|
$this->mysqli, |
28
|
|
|
"INSERT INTO change_log ( |
29
|
|
|
section, |
30
|
|
|
section_id, |
31
|
|
|
section_name, |
32
|
|
|
sub_section, |
33
|
|
|
sub_section_id, |
34
|
|
|
sub_section_name, |
35
|
|
|
user_id, |
36
|
|
|
action, |
37
|
|
|
timestamp |
38
|
|
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", |
39
|
|
|
"sissisisi", |
40
|
|
|
$change_log->getSection(), |
41
|
|
|
$change_log->getSectionId(), |
42
|
|
|
$change_log->getSectionValue(), |
43
|
|
|
$change_log->getSubSection(), |
44
|
|
|
$change_log->getSubSectionId(), |
45
|
|
|
$change_log->getSubSectionValue(), |
46
|
|
|
$change_log->getUserId(), |
47
|
|
|
$change_log->getAction(), |
48
|
|
|
$change_log->getTimestamp() |
49
|
|
|
); |
50
|
|
|
|
51
|
|
|
$id = $stmt->insert_id; |
52
|
|
|
|
53
|
|
|
$stmt->close(); |
54
|
|
|
|
55
|
|
|
return $id; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Get changelog entries for a specific section |
60
|
|
|
* |
61
|
|
|
* @param integer $limit How many entries to return |
62
|
|
|
* @return integer ID of the inserted change log |
63
|
|
|
*/ |
64
|
|
|
public function getChangeLogForSection($section, $limit = 10) { |
65
|
|
|
$stmt = \AL\Db\execute_query( |
66
|
|
|
"ChangeLogDAO: getChangeLogForSection", |
67
|
|
|
$this->mysqli, |
68
|
|
|
"SELECT |
69
|
|
|
change_log_id, |
70
|
|
|
section, |
71
|
|
|
section_id, |
72
|
|
|
section_name, |
73
|
|
|
sub_section, |
74
|
|
|
sub_section_id, |
75
|
|
|
sub_section_name, |
76
|
|
|
change_log.user_id, |
77
|
|
|
users.userid, |
78
|
|
|
users.email, |
79
|
|
|
users.join_date, |
80
|
|
|
users.karma, |
81
|
|
|
users.show_email, |
82
|
|
|
users.avatar_ext, |
83
|
|
|
action, |
84
|
|
|
timestamp |
85
|
|
|
FROM change_log |
86
|
|
|
LEFT JOIN users ON (change_log.user_id = users.user_id) |
87
|
|
|
WHERE change_log.section = ? |
88
|
|
|
ORDER BY timestamp DESC LIMIT ?", |
89
|
|
|
"si", $section, $limit |
90
|
|
|
); |
91
|
|
|
|
92
|
|
|
\AL\Db\bind_result( |
93
|
|
|
"ChangeLogDAO: getChangeLogForSection", |
94
|
|
|
$stmt, |
95
|
|
|
$change_log_id, |
96
|
|
|
$section, |
97
|
|
|
$section_id, |
98
|
|
|
$section_name, |
99
|
|
|
$sub_section, |
100
|
|
|
$sub_section_id, |
101
|
|
|
$sub_section_name, |
102
|
|
|
$user_id, |
103
|
|
|
$user_name, |
104
|
|
|
$user_email, |
105
|
|
|
$user_join_date, |
106
|
|
|
$user_karma, |
107
|
|
|
$user_show_email, |
108
|
|
|
$user_avatar_ext, |
109
|
|
|
$action, |
110
|
|
|
$timestamp |
111
|
|
|
); |
112
|
|
|
|
113
|
|
|
$changelogs = []; |
114
|
|
|
|
115
|
|
|
while ($stmt->fetch()) { |
116
|
|
|
$changelog = new \AL\Common\Model\Database\ChangeLog( |
117
|
|
|
$change_log_id, |
118
|
|
|
$section, |
119
|
|
|
$section_id, |
120
|
|
|
$section_name, |
121
|
|
|
$sub_section, |
122
|
|
|
$sub_section_id, |
123
|
|
|
$sub_section_name, |
124
|
|
|
$user_id, |
125
|
|
|
$action, |
126
|
|
|
$timestamp |
127
|
|
|
); |
128
|
|
|
$changelog->setUser(new \AL\Common\Model\User\User( |
129
|
|
|
$user_id, |
130
|
|
|
$user_name, |
131
|
|
|
$user_email, |
132
|
|
|
$user_join_date, |
133
|
|
|
$user_karma, |
134
|
|
|
$user_show_email, |
135
|
|
|
$user_avatar_ext |
136
|
|
|
)); |
137
|
|
|
|
138
|
|
|
$changelogs[] = $changelog; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
$stmt->close(); |
142
|
|
|
|
143
|
|
|
return $changelogs; |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|