aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche/Database.class.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/poche/Database.class.php')
-rwxr-xr-xinc/poche/Database.class.php53
1 files changed, 50 insertions, 3 deletions
diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php
index 65675afe..7be7a394 100755
--- a/inc/poche/Database.class.php
+++ b/inc/poche/Database.class.php
@@ -323,6 +323,21 @@ class Database {
323 return $entries; 323 return $entries;
324 } 324 }
325 325
326 public function retrieveAllWithTags($user_id)
327 {
328 $entries = $this->retrieveAll($user_id);
329 $count = count($entries);
330 for ($i = 0; $i < $count; $i++) {
331 $tag_entries = $this->retrieveTagsByEntry($entries[$i]['id']);
332 $tags = [];
333 foreach ($tag_entries as $tag) {
334 $tags[] = $tag[1];
335 }
336 $entries[$i]['tags'] = implode(',', $tags);
337 }
338 return $entries;
339 }
340
326 public function retrieveOneById($id, $user_id) 341 public function retrieveOneById($id, $user_id)
327 { 342 {
328 $entry = NULL; 343 $entry = NULL;
@@ -411,16 +426,48 @@ class Database {
411 426
412 return $count; 427 return $count;
413 } 428 }
414 public function getRandomId($user_id) { 429 public function getRandomId($user_id, $view) {
415 $random = (STORAGE == 'mysql') ? 'RAND()' : 'RANDOM()'; 430 $random = (STORAGE == 'mysql') ? 'RAND()' : 'RANDOM()';
416 $sql = "SELECT id FROM entries WHERE user_id=? ORDER BY ". $random . " LIMIT 1"; 431 switch ($view) {
417 $params = array($user_id); 432 case 'archive':
433 $sql = "SELECT id FROM entries WHERE user_id=? AND is_read=? ORDER BY ". $random . " LIMIT 1";
434 $params = array($user_id,1);
435 break;
436 case 'fav':
437 $sql = "SELECT id FROM entries WHERE user_id=? AND is_fav=? ORDER BY ". $random . " LIMIT 1";
438 $params = array($user_id,1);
439 break;
440 default:
441 $sql = "SELECT id FROM entries WHERE user_id=? AND is_read=? ORDER BY ". $random . " LIMIT 1";
442 $params = array($user_id,0);
443 break;
444 }
418 $query = $this->executeQuery($sql, $params); 445 $query = $this->executeQuery($sql, $params);
419 $id = $query->fetchAll(); 446 $id = $query->fetchAll();
420 447
421 return $id; 448 return $id;
422 } 449 }
423 450
451 public function getPreviousArticle($id, $user_id)
452 {
453 $sql = "SELECT id FROM entries WHERE id = (SELECT max(id) FROM entries WHERE id < ? AND is_read=0) AND user_id=? AND is_read=0";
454 $params = array($id, $user_id);
455 $query = $this->executeQuery($sql, $params);
456 $id_entry = $query->fetchAll();
457 $id = $id_entry[0][0];
458 return $id;
459 }
460
461 public function getNextArticle($id, $user_id)
462 {
463 $sql = "SELECT id FROM entries WHERE id = (SELECT min(id) FROM entries WHERE id > ? AND is_read=0) AND user_id=? AND is_read=0";
464 $params = array($id, $user_id);
465 $query = $this->executeQuery($sql, $params);
466 $id_entry = $query->fetchAll();
467 $id = $id_entry[0][0];
468 return $id;
469 }
470
424 471
425 public function updateContent($id, $content, $user_id) 472 public function updateContent($id, $content, $user_id)
426 { 473 {