|
1
|
|
|
<?php |
|
2
|
|
|
namespace AL\Common\DAO; |
|
3
|
|
|
|
|
4
|
|
|
require_once __DIR__."/../../lib/Db.php" ; |
|
5
|
|
|
require_once __DIR__."/../Model/PubDev/PubDev.php" ; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* DAO for PubDev |
|
9
|
|
|
*/ |
|
10
|
|
|
class PubDevDAO { |
|
11
|
|
|
private $mysqli; |
|
12
|
|
|
|
|
13
|
|
|
public function __construct($mysqli) { |
|
14
|
|
|
$this->mysqli = $mysqli; |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
public function getAllPubDevs() { |
|
18
|
|
|
return $this->getPubDevsStartingWith("."); |
|
19
|
|
|
} |
|
20
|
|
|
/** |
|
21
|
|
|
* Get all publishers and developers |
|
22
|
|
|
* @return \AL\Common\Model\PubDev\PubDev[] A list of PubDevs |
|
23
|
|
|
*/ |
|
24
|
|
|
public function getPubDevsStartingWith($regexp) { |
|
25
|
|
|
$stmt = \AL\Db\execute_query( |
|
26
|
|
|
"PubDevDAO: getAllPubDev", |
|
27
|
|
|
$this->mysqli, |
|
28
|
|
|
"SELECT |
|
29
|
|
|
pub_dev.pub_dev_id, |
|
30
|
|
|
pub_dev.pub_dev_name, |
|
31
|
|
|
pub_dev_text.pub_dev_profile, |
|
32
|
|
|
pub_dev_text.pub_dev_imgext |
|
33
|
|
|
FROM |
|
34
|
|
|
pub_dev |
|
35
|
|
|
LEFT JOIN pub_dev_text ON pub_dev_text.pub_dev_id = pub_dev.pub_dev_id |
|
36
|
|
|
WHERE LOWER(pub_dev.pub_dev_name) REGEXP ? |
|
37
|
|
|
ORDER BY pub_dev.pub_dev_name ASC", |
|
38
|
|
|
"s", strtolower($regexp) |
|
39
|
|
|
); |
|
40
|
|
|
|
|
41
|
|
|
\AL\Db\bind_result( |
|
42
|
|
|
"PubDevDAO: getAllPubDev", |
|
43
|
|
|
$stmt, |
|
44
|
|
|
$id, $name, $profile, $imgext |
|
|
|
|
|
|
45
|
|
|
); |
|
46
|
|
|
|
|
47
|
|
|
$pubdevs = []; |
|
48
|
|
|
while ($stmt->fetch()) { |
|
49
|
|
|
$pubdevs[] = new \AL\Common\Model\PubDev\PubDev( |
|
50
|
|
|
$id, $name, $profile, $imgext |
|
51
|
|
|
); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
$stmt->close(); |
|
55
|
|
|
|
|
56
|
|
|
return $pubdevs; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Get a publisher or developer |
|
61
|
|
|
* @param number $id ID of the pubdev to retrieve |
|
62
|
|
|
* @return \AL\Common\Model\PubDev\PubDev PubDev, or NULL if not found |
|
63
|
|
|
*/ |
|
64
|
|
|
public function getPubDev($id) { |
|
65
|
|
|
$stmt = \AL\Db\execute_query( |
|
66
|
|
|
"PubDevDAO: getPubDev", |
|
67
|
|
|
$this->mysqli, |
|
68
|
|
|
"SELECT |
|
69
|
|
|
pub_dev.pub_dev_id, |
|
70
|
|
|
pub_dev.pub_dev_name, |
|
71
|
|
|
pub_dev_text.pub_dev_profile, |
|
72
|
|
|
pub_dev_text.pub_dev_imgext |
|
73
|
|
|
FROM |
|
74
|
|
|
pub_dev |
|
75
|
|
|
LEFT JOIN pub_dev_text ON pub_dev_text.pub_dev_id = pub_dev.pub_dev_id |
|
76
|
|
|
WHERE pub_dev.pub_dev_id = ? |
|
77
|
|
|
ORDER BY pub_dev.pub_dev_name ASC", |
|
78
|
|
|
"i", $id |
|
79
|
|
|
); |
|
80
|
|
|
|
|
81
|
|
|
\AL\Db\bind_result( |
|
82
|
|
|
"PubDevDAO: getPubDev", |
|
83
|
|
|
$stmt, |
|
84
|
|
|
$id, $name, $profile, $imgext |
|
|
|
|
|
|
85
|
|
|
); |
|
86
|
|
|
|
|
87
|
|
|
$pubdev = null; |
|
88
|
|
|
if ($stmt->fetch()) { |
|
89
|
|
|
$pubdev = new \AL\Common\Model\PubDev\PubDev( |
|
90
|
|
|
$id, $name, $profile, $imgext |
|
91
|
|
|
); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
$stmt->close(); |
|
95
|
|
|
|
|
96
|
|
|
return $pubdev; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Get list of distributors for a game_release |
|
102
|
|
|
* |
|
103
|
|
|
* @param integer release ID |
|
|
|
|
|
|
104
|
|
|
*/ |
|
105
|
|
|
public function getDistributorsForRelease($game_release_id) { |
|
106
|
|
|
$stmt = \AL\Db\execute_query( |
|
107
|
|
|
"PubDevDAO: getDistributorsForRelease", |
|
108
|
|
|
$this->mysqli, |
|
109
|
|
|
"SELECT |
|
110
|
|
|
pub_dev.pub_dev_id, |
|
111
|
|
|
pub_dev.pub_dev_name, |
|
112
|
|
|
pub_dev_text.pub_dev_profile, |
|
113
|
|
|
pub_dev_text.pub_dev_imgext |
|
114
|
|
|
FROM |
|
115
|
|
|
pub_dev |
|
116
|
|
|
LEFT JOIN pub_dev_text ON pub_dev_text.pub_dev_id = pub_dev.pub_dev_id |
|
117
|
|
|
LEFT JOIN game_release_distributor ON pub_dev.pub_dev_id = game_release_distributor.pub_dev_id |
|
118
|
|
|
WHERE game_release_distributor.game_release_id = ?", |
|
119
|
|
|
"i", $game_release_id |
|
120
|
|
|
); |
|
121
|
|
|
|
|
122
|
|
|
\AL\Db\bind_result( |
|
123
|
|
|
"PubDevDAO: getDistributorsForRelease", |
|
124
|
|
|
$stmt, |
|
125
|
|
|
$id, $name, $profile, $imgext |
|
|
|
|
|
|
126
|
|
|
); |
|
127
|
|
|
|
|
128
|
|
|
$distributors = []; |
|
129
|
|
|
while ($stmt->fetch()) { |
|
130
|
|
|
$distributors[] = new \AL\Common\Model\PubDev\PubDev( |
|
131
|
|
|
$id, $name, $profile, $imgext |
|
132
|
|
|
); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
$stmt->close(); |
|
136
|
|
|
|
|
137
|
|
|
return $distributors; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* add a distributor to a release |
|
142
|
|
|
* |
|
143
|
|
|
* @param integer release ID |
|
144
|
|
|
* @param integer pub_Dev ID |
|
|
|
|
|
|
145
|
|
|
*/ |
|
146
|
|
|
public function addDistributorToRelease($release_id, $pub_dev_id) { |
|
147
|
|
|
$stmt = \AL\Db\execute_query( |
|
148
|
|
|
"PubDevDAO: addDistributorToRelease", |
|
149
|
|
|
$this->mysqli, |
|
150
|
|
|
"INSERT INTO game_release_distributor (game_release_id, pub_dev_id) VALUES (?, ?)", |
|
151
|
|
|
"ii", $release_id, $pub_dev_id |
|
152
|
|
|
); |
|
153
|
|
|
|
|
154
|
|
|
$stmt->close(); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* delete a distributor from a release |
|
160
|
|
|
* |
|
161
|
|
|
* @param int release_id |
|
162
|
|
|
* @param int pub_dv_id |
|
|
|
|
|
|
163
|
|
|
*/ |
|
164
|
|
|
public function deleteDistributorFromRelease($release_id, $pub_dev_id) { |
|
165
|
|
|
$stmt = \AL\Db\execute_query( |
|
166
|
|
|
"PubDevDAO: deleteDistributorFromRelease", |
|
167
|
|
|
$this->mysqli, |
|
168
|
|
|
"DELETE FROM game_release_distributor WHERE game_release_id = ? and pub_dev_id = ?", |
|
169
|
|
|
"ii", $release_id, $pub_dev_id |
|
170
|
|
|
); |
|
171
|
|
|
|
|
172
|
|
|
$stmt->close(); |
|
173
|
|
|
} |
|
174
|
|
|
} |
|
175
|
|
|
|