aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/store
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas.loeuillet@gmail.com>2013-08-06 15:51:48 +0200
committerNicolas LÅ“uillet <nicolas.loeuillet@gmail.com>2013-08-06 15:51:48 +0200
commit8d3275bee488d058c6ff0efe6e81d20a584d3709 (patch)
tree80b82707b6aecc5e29fa72cbdcf8ffe76ba8b7b4 /inc/store
parent7ce7ec4c942e0a3567858ad0ec8e654000b49a3f (diff)
downloadwallabag-8d3275bee488d058c6ff0efe6e81d20a584d3709.tar.gz
wallabag-8d3275bee488d058c6ff0efe6e81d20a584d3709.tar.zst
wallabag-8d3275bee488d058c6ff0efe6e81d20a584d3709.zip
multi user
Diffstat (limited to 'inc/store')
-rw-r--r--inc/store/file.class.php4
-rw-r--r--inc/store/mysql.class.php7
-rw-r--r--inc/store/sqlite.class.php75
-rw-r--r--inc/store/store.class.php4
4 files changed, 34 insertions, 56 deletions
diff --git a/inc/store/file.class.php b/inc/store/file.class.php
index ad20937d..c9d85dcc 100644
--- a/inc/store/file.class.php
+++ b/inc/store/file.class.php
@@ -44,8 +44,4 @@ class File extends Store {
44 public function getLastId() { 44 public function getLastId() {
45 45
46 } 46 }
47
48 public function updateContentById($id) {
49
50 }
51} 47}
diff --git a/inc/store/mysql.class.php b/inc/store/mysql.class.php
index 78254a5f..8b7f83da 100644
--- a/inc/store/mysql.class.php
+++ b/inc/store/mysql.class.php
@@ -192,11 +192,4 @@ class Mysql extends Store {
192 parent::__construct(); 192 parent::__construct();
193 return $this->getHandle()->lastInsertId(); 193 return $this->getHandle()->lastInsertId();
194 } 194 }
195
196 public function updateContentById($id) {
197 parent::__construct();
198 $sql_update = "UPDATE entries SET content=? WHERE id=?";
199 $params_update = array($content, $id);
200 $query = $this->executeQuery($sql_update, $params_update);
201 }
202} 195}
diff --git a/inc/store/sqlite.class.php b/inc/store/sqlite.class.php
index 3cc5276d..4c628dc1 100644
--- a/inc/store/sqlite.class.php
+++ b/inc/store/sqlite.class.php
@@ -57,9 +57,9 @@ class Sqlite extends Store {
57 } 57 }
58 58
59 public function login($username, $password) { 59 public function login($username, $password) {
60 $sql = "SELECT * FROM users WHERE username=? AND password=?"; 60 $sql = "SELECT * FROM users WHERE username=? AND password=?";
61 $query = $this->executeQuery($sql, array($username, $password)); 61 $query = $this->executeQuery($sql, array($username, $password));
62 $login = $query->fetchAll(); 62 $login = $query->fetchAll();
63 63
64 $user = array(); 64 $user = array();
65 if (isset($login[0])) { 65 if (isset($login[0])) {
@@ -76,9 +76,9 @@ class Sqlite extends Store {
76 76
77 public function updatePassword($id, $password) 77 public function updatePassword($id, $password)
78 { 78 {
79 $sql_update = "UPDATE users SET password=? WHERE id=?"; 79 $sql_update = "UPDATE users SET password=? WHERE id=?";
80 $params_update = array($password, $id); 80 $params_update = array($password, $id);
81 $query = $this->executeQuery($sql_update, $params_update); 81 $query = $this->executeQuery($sql_update, $params_update);
82 } 82 }
83 83
84 private function executeQuery($sql, $params) { 84 private function executeQuery($sql, $params) {
@@ -94,27 +94,27 @@ class Sqlite extends Store {
94 } 94 }
95 } 95 }
96 96
97 public function retrieveAll() { 97 public function retrieveAll($user_id) {
98 $sql = "SELECT * FROM entries ORDER BY id"; 98 $sql = "SELECT * FROM entries WHERE user_id=? ORDER BY id";
99 $query = $this->executeQuery($sql, array()); 99 $query = $this->executeQuery($sql, array($user_id));
100 $entries = $query->fetchAll(); 100 $entries = $query->fetchAll();
101 101
102 return $entries; 102 return $entries;
103 } 103 }
104 104
105 public function retrieveOneById($id) { 105 public function retrieveOneById($id, $user_id) {
106 parent::__construct(); 106 parent::__construct();
107 107
108 $entry = NULL; 108 $entry = NULL;
109 $sql = "SELECT * FROM entries WHERE id=?"; 109 $sql = "SELECT * FROM entries WHERE id=? AND user_id=?";
110 $params = array(intval($id)); 110 $params = array(intval($id), $user_id);
111 $query = $this->executeQuery($sql, $params); 111 $query = $this->executeQuery($sql, $params);
112 $entry = $query->fetchAll(); 112 $entry = $query->fetchAll();
113 113
114 return $entry[0]; 114 return $entry[0];
115 } 115 }
116 116
117 public function getEntriesByView($view, $limit = '') { 117 public function getEntriesByView($view, $user_id, $limit = '') {
118 parent::__construct(); 118 parent::__construct();
119 119
120 switch ($_SESSION['sort']) 120 switch ($_SESSION['sort'])
@@ -139,54 +139,54 @@ class Sqlite extends Store {
139 switch ($view) 139 switch ($view)
140 { 140 {
141 case 'archive': 141 case 'archive':
142 $sql = "SELECT * FROM entries WHERE is_read=? " . $order; 142 $sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? " . $order;
143 $params = array(-1); 143 $params = array($user_id, -1);
144 break; 144 break;
145 case 'fav' : 145 case 'fav' :
146 $sql = "SELECT * FROM entries WHERE is_fav=? " . $order; 146 $sql = "SELECT * FROM entries WHERE user_id=? AND is_fav=? " . $order;
147 $params = array(-1); 147 $params = array($user_id, -1);
148 break; 148 break;
149 default: 149 default:
150 $sql = "SELECT * FROM entries WHERE is_read=? " . $order; 150 $sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? " . $order;
151 $params = array(0); 151 $params = array($user_id, 0);
152 break; 152 break;
153 } 153 }
154 154
155 $sql .= ' ' . $limit; 155 $sql .= ' ' . $limit;
156 156
157 $query = $this->executeQuery($sql, $params); 157 $query = $this->executeQuery($sql, $params);
158 $entries = $query->fetchAll(); 158 $entries = $query->fetchAll();
159 159
160 return $entries; 160 return $entries;
161 } 161 }
162 162
163 public function add($url, $title, $content) { 163 public function add($url, $title, $content, $user_id) {
164 parent::__construct(); 164 parent::__construct();
165 $sql_action = 'INSERT INTO entries ( url, title, content ) VALUES (?, ?, ?)'; 165 $sql_action = 'INSERT INTO entries ( url, title, content, user_id ) VALUES (?, ?, ?, ?)';
166 $params_action = array($url, $title, $content); 166 $params_action = array($url, $title, $content, $user_id);
167 $query = $this->executeQuery($sql_action, $params_action); 167 $query = $this->executeQuery($sql_action, $params_action);
168 return $query; 168 return $query;
169 } 169 }
170 170
171 public function deleteById($id) { 171 public function deleteById($id, $user_id) {
172 parent::__construct(); 172 parent::__construct();
173 $sql_action = "DELETE FROM entries WHERE id=?"; 173 $sql_action = "DELETE FROM entries WHERE id=? AND user_id=?";
174 $params_action = array($id); 174 $params_action = array($id, $user_id);
175 $query = $this->executeQuery($sql_action, $params_action); 175 $query = $this->executeQuery($sql_action, $params_action);
176 return $query; 176 return $query;
177 } 177 }
178 178
179 public function favoriteById($id) { 179 public function favoriteById($id, $user_id) {
180 parent::__construct(); 180 parent::__construct();
181 $sql_action = "UPDATE entries SET is_fav=~is_fav WHERE id=?"; 181 $sql_action = "UPDATE entries SET is_fav=~is_fav WHERE id=? AND user_id=?";
182 $params_action = array($id); 182 $params_action = array($id, $user_id);
183 $query = $this->executeQuery($sql_action, $params_action); 183 $query = $this->executeQuery($sql_action, $params_action);
184 } 184 }
185 185
186 public function archiveById($id) { 186 public function archiveById($id, $user_id) {
187 parent::__construct(); 187 parent::__construct();
188 $sql_action = "UPDATE entries SET is_read=~is_read WHERE id=?"; 188 $sql_action = "UPDATE entries SET is_read=~is_read WHERE id=? AND user_id=?";
189 $params_action = array($id); 189 $params_action = array($id, $user_id);
190 $query = $this->executeQuery($sql_action, $params_action); 190 $query = $this->executeQuery($sql_action, $params_action);
191 } 191 }
192 192
@@ -194,11 +194,4 @@ class Sqlite extends Store {
194 parent::__construct(); 194 parent::__construct();
195 return $this->getHandle()->lastInsertId(); 195 return $this->getHandle()->lastInsertId();
196 } 196 }
197
198 public function updateContentById($id) {
199 parent::__construct();
200 $sql_update = "UPDATE entries SET content=? WHERE id=?";
201 $params_update = array($content, $id);
202 $query = $this->executeQuery($sql_update, $params_update);
203 }
204} 197}
diff --git a/inc/store/store.class.php b/inc/store/store.class.php
index 5f8939b9..d6e63014 100644
--- a/inc/store/store.class.php
+++ b/inc/store/store.class.php
@@ -52,8 +52,4 @@ class Store {
52 public function getLastId() { 52 public function getLastId() {
53 53
54 } 54 }
55
56 public function updateContentById($id) {
57
58 }
59} 55}