aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche/Database.class.php
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2014-02-19 13:47:11 +0100
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2014-02-19 13:47:11 +0100
commit60ca369cd328f4eae31005c547b9419a5ab33324 (patch)
treef9ab84e607cb54bdb0dc1d0027435af213a722f3 /inc/poche/Database.class.php
parent5e98c2183ae824ab6a1dd2dc22f8619a0d718977 (diff)
parentb89d5a2bf48c2c1eb796963b3401aca498618ec4 (diff)
downloadwallabag-60ca369cd328f4eae31005c547b9419a5ab33324.tar.gz
wallabag-60ca369cd328f4eae31005c547b9419a5ab33324.tar.zst
wallabag-60ca369cd328f4eae31005c547b9419a5ab33324.zip
Merge pull request #468 from wallabag/dev1.5.1
1.5.1
Diffstat (limited to 'inc/poche/Database.class.php')
-rw-r--r--inc/poche/Database.class.php40
1 files changed, 31 insertions, 9 deletions
diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php
index 9f553fa1..3332b5a3 100644
--- a/inc/poche/Database.class.php
+++ b/inc/poche/Database.class.php
@@ -241,6 +241,22 @@ class Database {
241 return isset($entry[0]) ? $entry[0] : null; 241 return isset($entry[0]) ? $entry[0] : null;
242 } 242 }
243 243
244 public function retrieveOneByURL($url, $user_id) {
245 $entry = NULL;
246 $sql = "SELECT * FROM entries WHERE url=? AND user_id=?";
247 $params = array($url, $user_id);
248 $query = $this->executeQuery($sql, $params);
249 $entry = $query->fetchAll();
250
251 return isset($entry[0]) ? $entry[0] : null;
252 }
253
254 public function reassignTags($old_entry_id, $new_entry_id) {
255 $sql = "UPDATE tags_entries SET entry_id=? WHERE entry_id=?";
256 $params = array($new_entry_id, $old_entry_id);
257 $query = $this->executeQuery($sql, $params);
258 }
259
244 public function getEntriesByView($view, $user_id, $limit = '') { 260 public function getEntriesByView($view, $user_id, $limit = '') {
245 switch ($_SESSION['sort']) 261 switch ($_SESSION['sort'])
246 { 262 {
@@ -328,30 +344,36 @@ class Database {
328 return $this->getHandle()->lastInsertId($column); 344 return $this->getHandle()->lastInsertId($column);
329 } 345 }
330 346
331 public function retrieveAllTags() { 347 public function retrieveAllTags($user_id) {
332 $sql = "SELECT * FROM tags"; 348 $sql = "SELECT tags.* FROM tags
333 $query = $this->executeQuery($sql, array()); 349 LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id
350 LEFT JOIN entries ON tags_entries.entry_id=entries.id
351 WHERE entries.user_id=?";
352 $query = $this->executeQuery($sql, array($user_id));
334 $tags = $query->fetchAll(); 353 $tags = $query->fetchAll();
335 354
336 return $tags; 355 return $tags;
337 } 356 }
338 357
339 public function retrieveTag($id) { 358 public function retrieveTag($id, $user_id) {
340 $tag = NULL; 359 $tag = NULL;
341 $sql = "SELECT * FROM tags WHERE id=?"; 360 $sql = "SELECT tags.* FROM tags
342 $params = array(intval($id)); 361 LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id
362 LEFT JOIN entries ON tags_entries.entry_id=entries.id
363 WHERE tags.id=? AND entries.user_id=?";
364 $params = array(intval($id), $user_id);
343 $query = $this->executeQuery($sql, $params); 365 $query = $this->executeQuery($sql, $params);
344 $tag = $query->fetchAll(); 366 $tag = $query->fetchAll();
345 367
346 return isset($tag[0]) ? $tag[0] : null; 368 return isset($tag[0]) ? $tag[0] : null;
347 } 369 }
348 370
349 public function retrieveEntriesByTag($tag_id) { 371 public function retrieveEntriesByTag($tag_id, $user_id) {
350 $sql = 372 $sql =
351 "SELECT entries.* FROM entries 373 "SELECT entries.* FROM entries
352 LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id 374 LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id
353 WHERE tags_entries.tag_id = ?"; 375 WHERE tags_entries.tag_id = ? AND entries.user_id=?";
354 $query = $this->executeQuery($sql, array($tag_id)); 376 $query = $this->executeQuery($sql, array($tag_id, $user_id));
355 $entries = $query->fetchAll(); 377 $entries = $query->fetchAll();
356 378
357 return $entries; 379 return $entries;