aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche/Database.class.php
diff options
context:
space:
mode:
authorNicolas Lœuillet <nicolas@loeuillet.org>2014-07-23 13:44:48 +0200
committerNicolas Lœuillet <nicolas@loeuillet.org>2014-07-23 13:44:48 +0200
commit887b015def3098f1e898e7bf3338fa2d093b6d95 (patch)
tree41206132200aa9390e11d600ad2b84ffa23242e4 /inc/poche/Database.class.php
parentebd6bf6007e0fad4c3e11dac0e79f687e1d195a2 (diff)
parent505a74ad1de7cf2cd3605e793233365501f03d87 (diff)
downloadwallabag-887b015def3098f1e898e7bf3338fa2d093b6d95.tar.gz
wallabag-887b015def3098f1e898e7bf3338fa2d093b6d95.tar.zst
wallabag-887b015def3098f1e898e7bf3338fa2d093b6d95.zip
Merge branch 'refactor' into dev
Diffstat (limited to 'inc/poche/Database.class.php')
-rwxr-xr-xinc/poche/Database.class.php175
1 files changed, 101 insertions, 74 deletions
diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php
index 11cccb72..2c80b64b 100755
--- a/inc/poche/Database.class.php
+++ b/inc/poche/Database.class.php
@@ -5,17 +5,18 @@
5 * @category wallabag 5 * @category wallabag
6 * @author Nicolas Lœuillet <nicolas@loeuillet.org> 6 * @author Nicolas Lœuillet <nicolas@loeuillet.org>
7 * @copyright 2013 7 * @copyright 2013
8 * @license http://www.wtfpl.net/ see COPYING file 8 * @license http://opensource.org/licenses/MIT see COPYING file
9 */ 9 */
10 10
11class Database { 11class Database {
12
12 var $handle; 13 var $handle;
13 private $order = array( 14 private $order = array (
14 'ia' => 'ORDER BY entries.id', 15 'ia' => 'ORDER BY entries.id',
15 'id' => 'ORDER BY entries.id DESC', 16 'id' => 'ORDER BY entries.id DESC',
16 'ta' => 'ORDER BY lower(entries.title)', 17 'ta' => 'ORDER BY lower(entries.title)',
17 'td' => 'ORDER BY lower(entries.title) DESC', 18 'td' => 'ORDER BY lower(entries.title) DESC',
18 'default' => 'ORDER BY entries.id' 19 'default' => 'ORDER BY entries.id'
19 ); 20 );
20 21
21 function __construct() 22 function __construct()
@@ -38,28 +39,17 @@ class Database {
38 } 39 }
39 40
40 $this->handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 41 $this->handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
42 $this->_checkTags();
41 Tools::logm('storage type ' . STORAGE); 43 Tools::logm('storage type ' . STORAGE);
42 } 44 }
43 45
44 private function getHandle() { 46 private function getHandle()
47 {
45 return $this->handle; 48 return $this->handle;
46 } 49 }
47 50
48 public function isInstalled() { 51 private function _checkTags()
49 $sql = "SELECT username FROM users"; 52 {
50 $query = $this->executeQuery($sql, array());
51 if ($query == false) {
52 die(STORAGE . ' database looks empty. You have to create it (you can find database structure in install folder).');
53 }
54 $hasAdmin = count($query->fetchAll());
55
56 if ($hasAdmin == 0)
57 return false;
58
59 return true;
60 }
61
62 public function checkTags() {
63 53
64 if (STORAGE == 'sqlite') { 54 if (STORAGE == 'sqlite') {
65 $sql = ' 55 $sql = '
@@ -123,7 +113,8 @@ class Database {
123 $query = $this->executeQuery($sql, array()); 113 $query = $this->executeQuery($sql, array());
124 } 114 }
125 115
126 public function install($login, $password) { 116 public function install($login, $password)
117 {
127 $sql = 'INSERT INTO users ( username, password, name, email) VALUES (?, ?, ?, ?)'; 118 $sql = 'INSERT INTO users ( username, password, name, email) VALUES (?, ?, ?, ?)';
128 $params = array($login, $password, $login, ' '); 119 $params = array($login, $password, $login, ' ');
129 $query = $this->executeQuery($sql, $params); 120 $query = $this->executeQuery($sql, $params);
@@ -150,7 +141,8 @@ class Database {
150 return TRUE; 141 return TRUE;
151 } 142 }
152 143
153 public function getConfigUser($id) { 144 public function getConfigUser($id)
145 {
154 $sql = "SELECT * FROM users_config WHERE user_id = ?"; 146 $sql = "SELECT * FROM users_config WHERE user_id = ?";
155 $query = $this->executeQuery($sql, array($id)); 147 $query = $this->executeQuery($sql, array($id));
156 $result = $query->fetchAll(); 148 $result = $query->fetchAll();
@@ -163,7 +155,8 @@ class Database {
163 return $user_config; 155 return $user_config;
164 } 156 }
165 157
166 public function userExists($username) { 158 public function userExists($username)
159 {
167 $sql = "SELECT * FROM users WHERE username=?"; 160 $sql = "SELECT * FROM users WHERE username=?";
168 $query = $this->executeQuery($sql, array($username)); 161 $query = $this->executeQuery($sql, array($username));
169 $login = $query->fetchAll(); 162 $login = $query->fetchAll();
@@ -174,13 +167,14 @@ class Database {
174 } 167 }
175 } 168 }
176 169
177 public function login($username, $password, $isauthenticated=false) { 170 public function login($username, $password, $isauthenticated = FALSE)
171 {
178 if ($isauthenticated) { 172 if ($isauthenticated) {
179 $sql = "SELECT * FROM users WHERE username=?"; 173 $sql = "SELECT * FROM users WHERE username=?";
180 $query = $this->executeQuery($sql, array($username)); 174 $query = $this->executeQuery($sql, array($username));
181 } else { 175 } else {
182 $sql = "SELECT * FROM users WHERE username=? AND password=?"; 176 $sql = "SELECT * FROM users WHERE username=? AND password=?";
183 $query = $this->executeQuery($sql, array($username, $password)); 177 $query = $this->executeQuery($sql, array($username, $password));
184 } 178 }
185 $login = $query->fetchAll(); 179 $login = $query->fetchAll();
186 180
@@ -204,7 +198,8 @@ class Database {
204 $query = $this->executeQuery($sql_update, $params_update); 198 $query = $this->executeQuery($sql_update, $params_update);
205 } 199 }
206 200
207 public function updateUserConfig($userId, $key, $value) { 201 public function updateUserConfig($userId, $key, $value)
202 {
208 $config = $this->getConfigUser($userId); 203 $config = $this->getConfigUser($userId);
209 204
210 if (! isset($config[$key])) { 205 if (! isset($config[$key])) {
@@ -218,7 +213,8 @@ class Database {
218 $query = $this->executeQuery($sql, $params); 213 $query = $this->executeQuery($sql, $params);
219 } 214 }
220 215
221 private function executeQuery($sql, $params) { 216 private function executeQuery($sql, $params)
217 {
222 try 218 try
223 { 219 {
224 $query = $this->getHandle()->prepare($sql); 220 $query = $this->getHandle()->prepare($sql);
@@ -232,28 +228,32 @@ class Database {
232 } 228 }
233 } 229 }
234 230
235 public function listUsers($username=null) { 231 public function listUsers($username = NULL)
232 {
236 $sql = 'SELECT count(*) FROM users'.( $username ? ' WHERE username=?' : ''); 233 $sql = 'SELECT count(*) FROM users'.( $username ? ' WHERE username=?' : '');
237 $query = $this->executeQuery($sql, ( $username ? array($username) : array())); 234 $query = $this->executeQuery($sql, ( $username ? array($username) : array()));
238 list($count) = $query->fetch(); 235 list($count) = $query->fetch();
239 return $count; 236 return $count;
240 } 237 }
241 238
242 public function getUserPassword($userID) { 239 public function getUserPassword($userID)
240 {
243 $sql = "SELECT * FROM users WHERE id=?"; 241 $sql = "SELECT * FROM users WHERE id=?";
244 $query = $this->executeQuery($sql, array($userID)); 242 $query = $this->executeQuery($sql, array($userID));
245 $password = $query->fetchAll(); 243 $password = $query->fetchAll();
246 return isset($password[0]['password']) ? $password[0]['password'] : null; 244 return isset($password[0]['password']) ? $password[0]['password'] : null;
247 } 245 }
248 246
249 public function deleteUserConfig($userID) { 247 public function deleteUserConfig($userID)
248 {
250 $sql_action = 'DELETE from users_config WHERE user_id=?'; 249 $sql_action = 'DELETE from users_config WHERE user_id=?';
251 $params_action = array($userID); 250 $params_action = array($userID);
252 $query = $this->executeQuery($sql_action, $params_action); 251 $query = $this->executeQuery($sql_action, $params_action);
253 return $query; 252 return $query;
254 } 253 }
255 254
256 public function deleteTagsEntriesAndEntries($userID) { 255 public function deleteTagsEntriesAndEntries($userID)
256 {
257 $entries = $this->retrieveAll($userID); 257 $entries = $this->retrieveAll($userID);
258 foreach($entries as $entryid) { 258 foreach($entries as $entryid) {
259 $tags = $this->retrieveTagsByEntry($entryid); 259 $tags = $this->retrieveTagsByEntry($entryid);
@@ -264,20 +264,23 @@ class Database {
264 } 264 }
265 } 265 }
266 266
267 public function deleteUser($userID) { 267 public function deleteUser($userID)
268 {
268 $sql_action = 'DELETE from users WHERE id=?'; 269 $sql_action = 'DELETE from users WHERE id=?';
269 $params_action = array($userID); 270 $params_action = array($userID);
270 $query = $this->executeQuery($sql_action, $params_action); 271 $query = $this->executeQuery($sql_action, $params_action);
271 } 272 }
272 273
273 public function updateContentAndTitle($id, $title, $body, $user_id) { 274 public function updateContentAndTitle($id, $title, $body, $user_id)
275 {
274 $sql_action = 'UPDATE entries SET content = ?, title = ? WHERE id=? AND user_id=?'; 276 $sql_action = 'UPDATE entries SET content = ?, title = ? WHERE id=? AND user_id=?';
275 $params_action = array($body, $title, $id, $user_id); 277 $params_action = array($body, $title, $id, $user_id);
276 $query = $this->executeQuery($sql_action, $params_action); 278 $query = $this->executeQuery($sql_action, $params_action);
277 return $query; 279 return $query;
278 } 280 }
279 281
280 public function retrieveUnfetchedEntries($user_id, $limit) { 282 public function retrieveUnfetchedEntries($user_id, $limit)
283 {
281 284
282 $sql_limit = "LIMIT 0,".$limit; 285 $sql_limit = "LIMIT 0,".$limit;
283 if (STORAGE == 'postgres') { 286 if (STORAGE == 'postgres') {
@@ -291,7 +294,8 @@ class Database {
291 return $entries; 294 return $entries;
292 } 295 }
293 296
294 public function retrieveUnfetchedEntriesCount($user_id) { 297 public function retrieveUnfetchedEntriesCount($user_id)
298 {
295 $sql = "SELECT count(*) FROM entries WHERE (content = '' OR content IS NULL) AND title LIKE 'Untitled - Import%' AND user_id=?"; 299 $sql = "SELECT count(*) FROM entries WHERE (content = '' OR content IS NULL) AND title LIKE 'Untitled - Import%' AND user_id=?";
296 $query = $this->executeQuery($sql, array($user_id)); 300 $query = $this->executeQuery($sql, array($user_id));
297 list($count) = $query->fetch(); 301 list($count) = $query->fetch();
@@ -299,7 +303,8 @@ class Database {
299 return $count; 303 return $count;
300 } 304 }
301 305
302 public function retrieveAll($user_id) { 306 public function retrieveAll($user_id)
307 {
303 $sql = "SELECT * FROM entries WHERE user_id=? ORDER BY id"; 308 $sql = "SELECT * FROM entries WHERE user_id=? ORDER BY id";
304 $query = $this->executeQuery($sql, array($user_id)); 309 $query = $this->executeQuery($sql, array($user_id));
305 $entries = $query->fetchAll(); 310 $entries = $query->fetchAll();
@@ -307,7 +312,8 @@ class Database {
307 return $entries; 312 return $entries;
308 } 313 }
309 314
310 public function retrieveOneById($id, $user_id) { 315 public function retrieveOneById($id, $user_id)
316 {
311 $entry = NULL; 317 $entry = NULL;
312 $sql = "SELECT * FROM entries WHERE id=? AND user_id=?"; 318 $sql = "SELECT * FROM entries WHERE id=? AND user_id=?";
313 $params = array(intval($id), $user_id); 319 $params = array(intval($id), $user_id);
@@ -317,7 +323,8 @@ class Database {
317 return isset($entry[0]) ? $entry[0] : null; 323 return isset($entry[0]) ? $entry[0] : null;
318 } 324 }
319 325
320 public function retrieveOneByURL($url, $user_id) { 326 public function retrieveOneByURL($url, $user_id)
327 {
321 $entry = NULL; 328 $entry = NULL;
322 $sql = "SELECT * FROM entries WHERE url=? AND user_id=?"; 329 $sql = "SELECT * FROM entries WHERE url=? AND user_id=?";
323 $params = array($url, $user_id); 330 $params = array($url, $user_id);
@@ -327,13 +334,15 @@ class Database {
327 return isset($entry[0]) ? $entry[0] : null; 334 return isset($entry[0]) ? $entry[0] : null;
328 } 335 }
329 336
330 public function reassignTags($old_entry_id, $new_entry_id) { 337 public function reassignTags($old_entry_id, $new_entry_id)
338 {
331 $sql = "UPDATE tags_entries SET entry_id=? WHERE entry_id=?"; 339 $sql = "UPDATE tags_entries SET entry_id=? WHERE entry_id=?";
332 $params = array($new_entry_id, $old_entry_id); 340 $params = array($new_entry_id, $old_entry_id);
333 $query = $this->executeQuery($sql, $params); 341 $query = $this->executeQuery($sql, $params);
334 } 342 }
335 343
336 public function getEntriesByView($view, $user_id, $limit = '', $tag_id = 0) { 344 public function getEntriesByView($view, $user_id, $limit = '', $tag_id = 0)
345 {
337 switch ($view) { 346 switch ($view) {
338 case 'archive': 347 case 'archive':
339 $sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? "; 348 $sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? ";
@@ -361,9 +370,10 @@ class Database {
361 $entries = $query->fetchAll(); 370 $entries = $query->fetchAll();
362 371
363 return $entries; 372 return $entries;
364 } 373 }
365 374
366 public function getEntriesByViewCount($view, $user_id, $tag_id = 0) { 375 public function getEntriesByViewCount($view, $user_id, $tag_id = 0)
376 {
367 switch ($view) { 377 switch ($view) {
368 case 'archive': 378 case 'archive':
369 $sql = "SELECT count(*) FROM entries WHERE user_id=? AND is_read=? "; 379 $sql = "SELECT count(*) FROM entries WHERE user_id=? AND is_read=? ";
@@ -391,7 +401,8 @@ class Database {
391 return $count; 401 return $count;
392 } 402 }
393 403
394 public function updateContent($id, $content, $user_id) { 404 public function updateContent($id, $content, $user_id)
405 {
395 $sql_action = 'UPDATE entries SET content = ? WHERE id=? AND user_id=?'; 406 $sql_action = 'UPDATE entries SET content = ? WHERE id=? AND user_id=?';
396 $params_action = array($content, $id, $user_id); 407 $params_action = array($content, $id, $user_id);
397 $query = $this->executeQuery($sql_action, $params_action); 408 $query = $this->executeQuery($sql_action, $params_action);
@@ -406,7 +417,8 @@ class Database {
406 * @param integer $user_id 417 * @param integer $user_id
407 * @return integer $id of inserted record 418 * @return integer $id of inserted record
408 */ 419 */
409 public function add($url, $title, $content, $user_id, $isFavorite=0, $isRead=0) { 420 public function add($url, $title, $content, $user_id, $isFavorite=0, $isRead=0)
421 {
410 $sql_action = 'INSERT INTO entries ( url, title, content, user_id, is_fav, is_read ) VALUES (?, ?, ?, ?, ?, ?)'; 422 $sql_action = 'INSERT INTO entries ( url, title, content, user_id, is_fav, is_read ) VALUES (?, ?, ?, ?, ?, ?)';
411 $params_action = array($url, $title, $content, $user_id, $isFavorite, $isRead); 423 $params_action = array($url, $title, $content, $user_id, $isFavorite, $isRead);
412 424
@@ -419,36 +431,42 @@ class Database {
419 return $id; 431 return $id;
420 } 432 }
421 433
422 public function deleteById($id, $user_id) { 434 public function deleteById($id, $user_id)
435 {
423 $sql_action = "DELETE FROM entries WHERE id=? AND user_id=?"; 436 $sql_action = "DELETE FROM entries WHERE id=? AND user_id=?";
424 $params_action = array($id, $user_id); 437 $params_action = array($id, $user_id);
425 $query = $this->executeQuery($sql_action, $params_action); 438 $query = $this->executeQuery($sql_action, $params_action);
426 return $query; 439 return $query;
427 } 440 }
428 441
429 public function favoriteById($id, $user_id) { 442 public function favoriteById($id, $user_id)
443 {
430 $sql_action = "UPDATE entries SET is_fav=NOT is_fav WHERE id=? AND user_id=?"; 444 $sql_action = "UPDATE entries SET is_fav=NOT is_fav WHERE id=? AND user_id=?";
431 $params_action = array($id, $user_id); 445 $params_action = array($id, $user_id);
432 $query = $this->executeQuery($sql_action, $params_action); 446 $query = $this->executeQuery($sql_action, $params_action);
433 } 447 }
434 448
435 public function archiveById($id, $user_id) { 449 public function archiveById($id, $user_id)
450 {
436 $sql_action = "UPDATE entries SET is_read=NOT is_read WHERE id=? AND user_id=?"; 451 $sql_action = "UPDATE entries SET is_read=NOT is_read WHERE id=? AND user_id=?";
437 $params_action = array($id, $user_id); 452 $params_action = array($id, $user_id);
438 $query = $this->executeQuery($sql_action, $params_action); 453 $query = $this->executeQuery($sql_action, $params_action);
439 } 454 }
440 455
441 public function archiveAll($user_id) { 456 public function archiveAll($user_id)
457 {
442 $sql_action = "UPDATE entries SET is_read=? WHERE user_id=? AND is_read=?"; 458 $sql_action = "UPDATE entries SET is_read=? WHERE user_id=? AND is_read=?";
443 $params_action = array($user_id, 1, 0); 459 $params_action = array($user_id, 1, 0);
444 $query = $this->executeQuery($sql_action, $params_action); 460 $query = $this->executeQuery($sql_action, $params_action);
445 } 461 }
446 462
447 public function getLastId($column = '') { 463 public function getLastId($column = '')
464 {
448 return $this->getHandle()->lastInsertId($column); 465 return $this->getHandle()->lastInsertId($column);
449 } 466 }
450 467
451 public function search($term, $user_id, $limit = '') { 468 public function search($term, $user_id, $limit = '')
469 {
452 $search = '%'.$term.'%'; 470 $search = '%'.$term.'%';
453 $sql_action = "SELECT * FROM entries WHERE user_id=? AND (content LIKE ? OR title LIKE ? OR url LIKE ?) "; //searches in content, title and URL 471 $sql_action = "SELECT * FROM entries WHERE user_id=? AND (content LIKE ? OR title LIKE ? OR url LIKE ?) "; //searches in content, title and URL
454 $sql_action .= $this->getEntriesOrder().' ' . $limit; 472 $sql_action .= $this->getEntriesOrder().' ' . $limit;
@@ -457,7 +475,8 @@ class Database {
457 return $query->fetchAll(); 475 return $query->fetchAll();
458 } 476 }
459 477
460 public function retrieveAllTags($user_id, $term = null) { 478 public function retrieveAllTags($user_id, $term = NULL)
479 {
461 $sql = "SELECT DISTINCT tags.*, count(entries.id) AS entriescount FROM tags 480 $sql = "SELECT DISTINCT tags.*, count(entries.id) AS entriescount FROM tags
462 LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id 481 LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id
463 LEFT JOIN entries ON tags_entries.entry_id=entries.id 482 LEFT JOIN entries ON tags_entries.entry_id=entries.id
@@ -471,7 +490,8 @@ class Database {
471 return $tags; 490 return $tags;
472 } 491 }
473 492
474 public function retrieveTag($id, $user_id) { 493 public function retrieveTag($id, $user_id)
494 {
475 $tag = NULL; 495 $tag = NULL;
476 $sql = "SELECT DISTINCT tags.* FROM tags 496 $sql = "SELECT DISTINCT tags.* FROM tags
477 LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id 497 LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id
@@ -481,10 +501,11 @@ class Database {
481 $query = $this->executeQuery($sql, $params); 501 $query = $this->executeQuery($sql, $params);
482 $tag = $query->fetchAll(); 502 $tag = $query->fetchAll();
483 503
484 return isset($tag[0]) ? $tag[0] : null; 504 return isset($tag[0]) ? $tag[0] : NULL;
485 } 505 }
486 506
487 public function retrieveEntriesByTag($tag_id, $user_id) { 507 public function retrieveEntriesByTag($tag_id, $user_id)
508 {
488 $sql = 509 $sql =
489 "SELECT entries.* FROM entries 510 "SELECT entries.* FROM entries
490 LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id 511 LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id
@@ -495,7 +516,8 @@ class Database {
495 return $entries; 516 return $entries;
496 } 517 }
497 518
498 public function retrieveTagsByEntry($entry_id) { 519 public function retrieveTagsByEntry($entry_id)
520 {
499 $sql = 521 $sql =
500 "SELECT tags.* FROM tags 522 "SELECT tags.* FROM tags
501 LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id 523 LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id
@@ -506,14 +528,16 @@ class Database {
506 return $tags; 528 return $tags;
507 } 529 }
508 530
509 public function removeTagForEntry($entry_id, $tag_id) { 531 public function removeTagForEntry($entry_id, $tag_id)
532 {
510 $sql_action = "DELETE FROM tags_entries WHERE tag_id=? AND entry_id=?"; 533 $sql_action = "DELETE FROM tags_entries WHERE tag_id=? AND entry_id=?";
511 $params_action = array($tag_id, $entry_id); 534 $params_action = array($tag_id, $entry_id);
512 $query = $this->executeQuery($sql_action, $params_action); 535 $query = $this->executeQuery($sql_action, $params_action);
513 return $query; 536 return $query;
514 } 537 }
515 538
516 public function cleanUnusedTag($tag_id) { 539 public function cleanUnusedTag($tag_id)
540 {
517 $sql_action = "SELECT tags.* FROM tags JOIN tags_entries ON tags_entries.tag_id=tags.id WHERE tags.id=?"; 541 $sql_action = "SELECT tags.* FROM tags JOIN tags_entries ON tags_entries.tag_id=tags.id WHERE tags.id=?";
518 $query = $this->executeQuery($sql_action,array($tag_id)); 542 $query = $this->executeQuery($sql_action,array($tag_id));
519 $tagstokeep = $query->fetchAll(); 543 $tagstokeep = $query->fetchAll();
@@ -532,7 +556,8 @@ class Database {
532 556
533 } 557 }
534 558
535 public function retrieveTagByValue($value) { 559 public function retrieveTagByValue($value)
560 {
536 $tag = NULL; 561 $tag = NULL;
537 $sql = "SELECT * FROM tags WHERE value=?"; 562 $sql = "SELECT * FROM tags WHERE value=?";
538 $params = array($value); 563 $params = array($value);
@@ -542,27 +567,29 @@ class Database {
542 return isset($tag[0]) ? $tag[0] : null; 567 return isset($tag[0]) ? $tag[0] : null;
543 } 568 }
544 569
545 public function createTag($value) { 570 public function createTag($value)
571 {
546 $sql_action = 'INSERT INTO tags ( value ) VALUES (?)'; 572 $sql_action = 'INSERT INTO tags ( value ) VALUES (?)';
547 $params_action = array($value); 573 $params_action = array($value);
548 $query = $this->executeQuery($sql_action, $params_action); 574 $query = $this->executeQuery($sql_action, $params_action);
549 return $query; 575 return $query;
550 } 576 }
551 577
552 public function setTagToEntry($tag_id, $entry_id) { 578 public function setTagToEntry($tag_id, $entry_id)
579 {
553 $sql_action = 'INSERT INTO tags_entries ( tag_id, entry_id ) VALUES (?, ?)'; 580 $sql_action = 'INSERT INTO tags_entries ( tag_id, entry_id ) VALUES (?, ?)';
554 $params_action = array($tag_id, $entry_id); 581 $params_action = array($tag_id, $entry_id);
555 $query = $this->executeQuery($sql_action, $params_action); 582 $query = $this->executeQuery($sql_action, $params_action);
556 return $query; 583 return $query;
557 } 584 }
558 585
559 private function getEntriesOrder() { 586 private function getEntriesOrder()
560 if (isset($_SESSION['sort']) and array_key_exists($_SESSION['sort'], $this->order)) { 587 {
561 return $this->order[$_SESSION['sort']]; 588 if (isset($_SESSION['sort']) and array_key_exists($_SESSION['sort'], $this->order)) {
562 } 589 return $this->order[$_SESSION['sort']];
563 else {
564 return $this->order['default'];
565 }
566 } 590 }
567 591 else {
592 return $this->order['default'];
593 }
594 }
568} 595}