PluginProbe
User Access Manager / 2.1.7
User Access Manager v2.1.7
2.3.20 2.3.19 2.3.18 2.3.17 2.3.16 2.3.15 2.3.14 2.3.13 trunk 0.6 0.6.1 0.6.2 0.7 0.7 Beta 0.7.0.1 0.8 0.8.0.1 0.8.0.2 0.9 0.9.1 0.9.1.1 0.9.1.2 0.9.1.3 0.9.1.4 1.0 All 136 releases
user-access-manager / src / Database / Database.php

Database.php in User Access Manager 2.1.7, at src/Database/Database.php

357 lines 7.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Database.php
4 *
5 * The Database class file.
6 *
7 * PHP versions 5
8 *
9 * @author Alexander Schneider <alexanderschneider85@gmail.com>
10 * @copyright 2008-2017 Alexander Schneider
11 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2
12 * @version SVN: $id$
13 * @link http://wordpress.org/extend/plugins/user-access-manager/
14 */
15
16 namespace UserAccessManager\Database;
17
18 use UserAccessManager\Wrapper\Wordpress;
19
20 /**
21 * Class Database
22 *
23 * @package UserAccessManager\Database
24 */
25 class Database
26 {
27 const USER_GROUP_TABLE_NAME = 'uam_accessgroups';
28 const USER_GROUP_TO_OBJECT_TABLE_NAME = 'uam_accessgroup_to_object';
29
30 /**
31 * @var Wordpress
32 */
33 private $wordpress;
34
35 /**
36 * @var \wpdb
37 */
38 private $wpDatabase;
39
40 /**
41 * Database constructor.
42 *
43 * @param Wordpress $wordpress
44 */
45 public function __construct(Wordpress $wordpress)
46 {
47 $this->wordpress = $wordpress;
48 $this->wpDatabase = $wordpress->getDatabase();
49 }
50
51 /**
52 * Returns the wordpress database.
53 *
54 * @return \wpdb
55 */
56 public function getWordpressDatabase()
57 {
58 return $this->wpDatabase;
59 }
60
61 /**
62 * Returns the user group table name.
63 *
64 * @return string
65 */
66 public function getUserGroupTable()
67 {
68 return $this->wpDatabase->prefix.self::USER_GROUP_TABLE_NAME;
69 }
70
71 /**
72 * Returns the user group table name.
73 *
74 * @return string
75 */
76 public function getUserGroupToObjectTable()
77 {
78 return $this->wpDatabase->prefix.self::USER_GROUP_TO_OBJECT_TABLE_NAME;
79 }
80
81 /**
82 * @see dbDelta()
83 *
84 * @param string $queries
85 * @param bool $execute
86 *
87 * @return array
88 */
89 public function dbDelta($queries = '', $execute = true)
90 {
91 return $this->wordpress->dbDelta($queries, $execute);
92 }
93
94 /**
95 * @see \wpdb::$prefix
96 *
97 * @return string
98 */
99 public function getPrefix()
100 {
101 return $this->wpDatabase->prefix;
102 }
103
104 /**
105 * Returns the last insert id.
106 *
107 * @return int
108 */
109 public function getLastInsertId()
110 {
111 return $this->wpDatabase->insert_id;
112 }
113
114 /**
115 * Returns the current blog id.
116 *
117 * @return int
118 */
119 public function getCurrentBlogId()
120 {
121 return $this->wpDatabase->blogid;
122 }
123
124 /**
125 * Returns the blogs table name.
126 *
127 * @return string
128 */
129 public function getBlogsTable()
130 {
131 return $this->wpDatabase->blogs;
132 }
133
134 /**
135 * Returns the posts table name.
136 *
137 * @return string
138 */
139 public function getPostsTable()
140 {
141 return $this->wpDatabase->posts;
142 }
143
144 /**
145 * Returns the term_relationships table name.
146 *
147 * @return string
148 */
149 public function getTermRelationshipsTable()
150 {
151 return $this->wpDatabase->term_relationships;
152 }
153
154 /**
155 * Returns the term_taxonomy table name.
156 *
157 * @return string
158 */
159 public function getTermTaxonomyTable()
160 {
161 return $this->wpDatabase->term_taxonomy;
162 }
163
164 /**
165 * Returns the users table name.
166 *
167 * @return string
168 */
169 public function getUsersTable()
170 {
171 return $this->wpDatabase->users;
172 }
173
174 /**
175 * Returns the capabilities table name.
176 *
177 * @return string
178 */
179 public function getCapabilitiesTable()
180 {
181 return $this->wpDatabase->prefix.'capabilities';
182 }
183
184 /**
185 * @see \wpdb::get_col()
186 *
187 * @param string $query
188 * @param int $column
189 *
190 * @return array
191 */
192 public function getColumn($query = null, $column = 0)
193 {
194 return $this->wpDatabase->get_col($query, $column);
195 }
196
197 /**
198 * @see \wpdb::get_row()
199 *
200 * @param string $query
201 * @param string $output
202 * @param int $row
203 *
204 * @return array|null|object
205 */
206 public function getRow($query = null, $output = OBJECT, $row = 0)
207 {
208 return $this->wpDatabase->get_row($query, $output, $row);
209 }
210
211 /**
212 * @see \wpdb::get_var()
213 *
214 * @param null|string $query
215 * @param int $column
216 * @param int $row
217 *
218 * @return null|string
219 */
220 public function getVariable($query = null, $column = 0, $row = 0)
221 {
222 return $this->wpDatabase->get_var($query, $column, $row);
223 }
224
225 /**
226 * @see \wpdb::get_blog_prefix()
227 *
228 * @param int $blogId
229 *
230 * @return string
231 */
232 public function getBlogPrefix($blogId = null)
233 {
234 return $this->wpDatabase->get_blog_prefix($blogId);
235 }
236
237 /**
238 * @see \wpdb::prepare()
239 *
240 * @param string $query
241 * @param mixed $arguments
242 *
243 * @return string
244 */
245 public function prepare($query, $arguments)
246 {
247 return $this->wpDatabase->prepare($query, $arguments);
248 }
249
250 /**
251 * @see \wpdb::query()
252 *
253 * @param string $query
254 *
255 * @return false|int
256 */
257 public function query($query)
258 {
259 return $this->wpDatabase->query($query);
260 }
261
262 /**
263 * @see \wpdb::get_results()
264 *
265 * @param string $query
266 * @param string $output
267 *
268 * @return array|null|object
269 */
270 public function getResults($query = null, $output = OBJECT)
271 {
272 return $this->wpDatabase->get_results($query, $output);
273 }
274
275 /**
276 * @see \wpdb::insert()
277 *
278 * @param string $table
279 * @param array $data
280 * @param array|string $format
281 *
282 * @return false|int
283 */
284 public function insert($table, array $data, $format = null)
285 {
286 return $this->wpDatabase->insert($table, $data, $format);
287 }
288
289 /**
290 * @see \wpdb::update()
291 *
292 * @param string $table
293 * @param array $data
294 * @param array $where
295 * @param array|string $format
296 * @param array|string $whereFormat
297 *
298 * @return false|int
299 */
300 public function update($table, array $data, array $where, $format = null, $whereFormat = null)
301 {
302 return $this->wpDatabase->update($table, $data, $where, $format, $whereFormat);
303 }
304
305 /**
306 * @see \wpdb::insert()
307 *
308 * @param string $table
309 * @param array $data
310 * @param array|string $format
311 *
312 * @return false|int
313 */
314 public function replace($table, array $data, $format = null)
315 {
316 return $this->wpDatabase->replace($table, $data, $format);
317 }
318
319 /**
320 * @see \wpdb::delete()
321 *
322 * @param string $table
323 * @param array $where
324 * @param array|string $whereFormat
325 *
326 * @return false|int
327 */
328 public function delete($table, array $where, $whereFormat = null)
329 {
330 return $this->wpDatabase->delete($table, $where, $whereFormat);
331 }
332
333 /**
334 * Returns the database charset.
335 *
336 * @return string
337 */
338 public function getCharset()
339 {
340 $charsetCollate = '';
341
342 $mySlqVersion = $this->getVariable('SELECT VERSION() as mysql_version');
343
344 if (version_compare($mySlqVersion, '4.1.0', '>=')) {
345 if (!empty($this->wpDatabase->charset)) {
346 $charsetCollate = "DEFAULT CHARACTER SET {$this->wpDatabase->charset}";
347 }
348
349 if (!empty($this->wpDatabase->collate)) {
350 $charsetCollate .= " COLLATE {$this->wpDatabase->collate}";
351 }
352 }
353
354 return $charsetCollate;
355 }
356 }
357