diff options
Diffstat (limited to 'inc/poche/Database.class.php')
-rw-r--r-- | inc/poche/Database.class.php | 40 |
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; |