]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - inc/poche/Database.class.php
fix for long lasting session
[github/wallabag/wallabag.git] / inc / poche / Database.class.php
index 1d3ff0c29752f11a1e3a62a9fa77b9930a209179..d95b9b8101c08903bd4dfa80875697aca957b9db 100644 (file)
@@ -74,7 +74,7 @@ class Database {
         return TRUE;
     }
 
-    private function getConfigUser($id) {
+    public function getConfigUser($id) {
         $sql = "SELECT * FROM users_config WHERE user_id = ?";
         $query = $this->executeQuery($sql, array($id));
         $result = $query->fetchAll();
@@ -166,7 +166,7 @@ class Database {
         $query  = $this->executeQuery($sql, $params);
         $entry  = $query->fetchAll();
 
-        return $entry[0];
+        return isset($entry[0]) ? $entry[0] : null;
     }
 
     public function getEntriesByView($view, $user_id, $limit = '') {
@@ -249,4 +249,75 @@ class Database {
     public function getLastId($column = '') {
         return $this->getHandle()->lastInsertId($column);
     }
+
+    public function retrieveAllTags() {
+        $sql = "SELECT * FROM tags";
+        $query = $this->executeQuery($sql, array());
+        $tags = $query->fetchAll();
+
+        return $tags;
+    }
+
+    public function retrieveTag($id) {
+        $tag  = NULL;
+        $sql    = "SELECT * FROM tags WHERE id=?";
+        $params = array(intval($id));
+        $query  = $this->executeQuery($sql, $params);
+        $tag  = $query->fetchAll();
+
+        return isset($tag[0]) ? $tag[0] : null;
+    }
+
+    public function retrieveEntriesByTag($tag_id) {
+        $sql = 
+            "SELECT * FROM entries
+            LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id
+            WHERE tags_entries.tag_id = ?";
+        $query = $this->executeQuery($sql, array($tag_id));
+        $entries = $query->fetchAll();
+
+        return $entries;
+    }
+
+    public function retrieveTagsByEntry($entry_id) {
+        $sql = 
+            "SELECT * FROM tags
+            LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id
+            WHERE tags_entries.entry_id = ?";
+        $query = $this->executeQuery($sql, array($entry_id));
+        $tags = $query->fetchAll();
+
+        return $tags;
+    }
+
+    public function removeTagForEntry($entry_id, $tag_id) {
+        $sql_action     = "DELETE FROM tags_entries WHERE tag_id=? AND entry_id=?";
+        $params_action  = array($tag_id, $entry_id);
+        $query          = $this->executeQuery($sql_action, $params_action);
+        return $query;
+    }
+
+    public function retrieveTagByValue($value) {
+        $tag  = NULL;
+        $sql    = "SELECT * FROM tags WHERE value=?";
+        $params = array($value);
+        $query  = $this->executeQuery($sql, $params);
+        $tag  = $query->fetchAll();
+
+        return isset($tag[0]) ? $tag[0] : null;
+    }
+
+    public function createTag($value) {
+        $sql_action = 'INSERT INTO tags ( value ) VALUES (?)';
+        $params_action = array($value);
+        $query = $this->executeQuery($sql_action, $params_action);
+        return $query;
+    }
+
+    public function setTagToEntry($tag_id, $entry_id) {
+        $sql_action = 'INSERT INTO tags_entries ( tag_id, entry_id ) VALUES (?, ?)';
+        $params_action = array($tag_id, $entry_id);
+        $query = $this->executeQuery($sql_action, $params_action);
+        return $query;
+    }
 }