diff options
Diffstat (limited to 'inc/poche/Database.class.php')
-rwxr-xr-x | inc/poche/Database.class.php | 76 |
1 files changed, 52 insertions, 24 deletions
diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index c998fe14..5b51b507 100755 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php | |||
@@ -230,8 +230,30 @@ class Database { | |||
230 | } | 230 | } |
231 | } | 231 | } |
232 | 232 | ||
233 | public function updateContentAndTitle($id, $title, $body, $user_id) { | ||
234 | $sql_action = 'UPDATE entries SET content = ?, title = ? WHERE id=? AND user_id=?'; | ||
235 | $params_action = array($body, $title, $id, $user_id); | ||
236 | $query = $this->executeQuery($sql_action, $params_action); | ||
237 | |||
238 | return $query; | ||
239 | } | ||
240 | |||
241 | public function retrieveUnfetchedEntries($user_id, $limit) { | ||
242 | |||
243 | $sql_limit = "LIMIT 0,".$limit; | ||
244 | if (STORAGE == 'postgres') { | ||
245 | $sql_limit = "LIMIT ".$limit." OFFSET 0"; | ||
246 | } | ||
247 | |||
248 | $sql = "SELECT * FROM entries WHERE (content = '' OR content IS NULL) AND user_id=? ORDER BY id " . $sql_limit; | ||
249 | $query = $this->executeQuery($sql, array($user_id)); | ||
250 | $entries = $query->fetchAll(); | ||
251 | |||
252 | return $entries; | ||
253 | } | ||
254 | |||
233 | public function retrieveAll($user_id) { | 255 | public function retrieveAll($user_id) { |
234 | $sql = "SELECT * FROM entries WHERE user_id=? ORDER BY id"; | 256 | $sql = "SELECT * FROM entries WHERE content <> '' AND user_id=? ORDER BY id"; |
235 | $query = $this->executeQuery($sql, array($user_id)); | 257 | $query = $this->executeQuery($sql, array($user_id)); |
236 | $entries = $query->fetchAll(); | 258 | $entries = $query->fetchAll(); |
237 | 259 | ||
@@ -250,7 +272,7 @@ class Database { | |||
250 | 272 | ||
251 | public function retrieveOneByURL($url, $user_id) { | 273 | public function retrieveOneByURL($url, $user_id) { |
252 | $entry = NULL; | 274 | $entry = NULL; |
253 | $sql = "SELECT * FROM entries WHERE url=? AND user_id=?"; | 275 | $sql = "SELECT * FROM entries WHERE content <> '' AND url=? AND user_id=?"; |
254 | $params = array($url, $user_id); | 276 | $params = array($url, $user_id); |
255 | $query = $this->executeQuery($sql, $params); | 277 | $query = $this->executeQuery($sql, $params); |
256 | $entry = $query->fetchAll(); | 278 | $entry = $query->fetchAll(); |
@@ -267,21 +289,22 @@ class Database { | |||
267 | public function getEntriesByView($view, $user_id, $limit = '', $tag_id = 0) { | 289 | public function getEntriesByView($view, $user_id, $limit = '', $tag_id = 0) { |
268 | switch ($view) { | 290 | switch ($view) { |
269 | case 'archive': | 291 | case 'archive': |
270 | $sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? "; | 292 | $sql = "SELECT * FROM entries WHERE content <> '' AND user_id=? AND is_read=? "; |
271 | $params = array($user_id, 1); | 293 | $params = array($user_id, 1); |
272 | break; | 294 | break; |
273 | case 'fav' : | 295 | case 'fav' : |
274 | $sql = "SELECT * FROM entries WHERE user_id=? AND is_fav=? "; | 296 | $sql = "SELECT * FROM entries WHERE content <> '' AND user_id=? AND is_fav=? "; |
275 | $params = array($user_id, 1); | 297 | $params = array($user_id, 1); |
276 | break; | 298 | break; |
277 | case 'tag' : | 299 | case 'tag' : |
278 | $sql = "SELECT entries.* FROM entries | 300 | $sql = "SELECT entries.* FROM entries |
279 | LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id | 301 | LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id |
280 | WHERE entries.user_id=? AND tags_entries.tag_id = ? "; | 302 | WHERE entries.content <> '' AND |
303 | entries.user_id=? AND tags_entries.tag_id = ? "; | ||
281 | $params = array($user_id, $tag_id); | 304 | $params = array($user_id, $tag_id); |
282 | break; | 305 | break; |
283 | default: | 306 | default: |
284 | $sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? "; | 307 | $sql = "SELECT * FROM entries WHERE content <> '' AND user_id=? AND is_read=? "; |
285 | $params = array($user_id, 0); | 308 | $params = array($user_id, 0); |
286 | break; | 309 | break; |
287 | } | 310 | } |
@@ -294,24 +317,25 @@ class Database { | |||
294 | return $entries; | 317 | return $entries; |
295 | } | 318 | } |
296 | 319 | ||
297 | public function getEntriesByViewCount($view, $user_id, $tag_id = 0) { | 320 | public function getEntriesByViewCount($view, $user_id, $tag_id = 0) { |
298 | switch ($view) { | 321 | switch ($view) { |
299 | case 'archive': | 322 | case 'archive': |
300 | $sql = "SELECT count(*) FROM entries WHERE user_id=? AND is_read=? "; | 323 | $sql = "SELECT count(*) FROM entries WHERE content <> '' AND user_id=? AND is_read=? "; |
301 | $params = array($user_id, 1); | 324 | $params = array($user_id, 1); |
302 | break; | 325 | break; |
303 | case 'fav' : | 326 | case 'fav' : |
304 | $sql = "SELECT count(*) FROM entries WHERE user_id=? AND is_fav=? "; | 327 | $sql = "SELECT count(*) FROM entries WHERE content <> '' AND user_id=? AND is_fav=? "; |
305 | $params = array($user_id, 1); | 328 | $params = array($user_id, 1); |
306 | break; | 329 | break; |
307 | case 'tag' : | 330 | case 'tag' : |
308 | $sql = "SELECT count(*) FROM entries | 331 | $sql = "SELECT count(*) FROM entries |
309 | LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id | 332 | LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id |
310 | WHERE entries.user_id=? AND tags_entries.tag_id = ? "; | 333 | WHERE entries.content <> '' AND |
311 | $params = array($user_id, $tag_id); | 334 | entries.user_id=? AND tags_entries.tag_id = ? "; |
312 | break; | 335 | $params = array($user_id, $tag_id); |
336 | break; | ||
313 | default: | 337 | default: |
314 | $sql = "SELECT count(*) FROM entries WHERE user_id=? AND is_read=? "; | 338 | $sql = "SELECT count(*) FROM entries WHERE content <> '' AND user_id=? AND is_read=? "; |
315 | $params = array($user_id, 0); | 339 | $params = array($user_id, 0); |
316 | break; | 340 | break; |
317 | } | 341 | } |
@@ -319,7 +343,7 @@ class Database { | |||
319 | $query = $this->executeQuery($sql, $params); | 343 | $query = $this->executeQuery($sql, $params); |
320 | list($count) = $query->fetch(); | 344 | list($count) = $query->fetch(); |
321 | 345 | ||
322 | return $count; | 346 | return $count; |
323 | } | 347 | } |
324 | 348 | ||
325 | public function updateContent($id, $content, $user_id) { | 349 | public function updateContent($id, $content, $user_id) { |
@@ -365,12 +389,15 @@ class Database { | |||
365 | return $this->getHandle()->lastInsertId($column); | 389 | return $this->getHandle()->lastInsertId($column); |
366 | } | 390 | } |
367 | 391 | ||
368 | public function retrieveAllTags($user_id) { | 392 | public function retrieveAllTags($user_id, $term = null) { |
369 | $sql = "SELECT DISTINCT tags.* FROM tags | 393 | $sql = "SELECT DISTINCT tags.*, count(entries.id) AS entriescount FROM tags |
370 | LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id | 394 | LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id |
371 | LEFT JOIN entries ON tags_entries.entry_id=entries.id | 395 | LEFT JOIN entries ON tags_entries.entry_id=entries.id |
372 | WHERE entries.user_id=?"; | 396 | WHERE entries.content <> '' AND entries.user_id=? |
373 | $query = $this->executeQuery($sql, array($user_id)); | 397 | ". (($term) ? "AND lower(tags.value) LIKE ?" : '') ." |
398 | GROUP BY tags.id, tags.value | ||
399 | ORDER BY tags.value"; | ||
400 | $query = $this->executeQuery($sql, (($term)? array($user_id, strtolower('%'.$term.'%')) : array($user_id) )); | ||
374 | $tags = $query->fetchAll(); | 401 | $tags = $query->fetchAll(); |
375 | 402 | ||
376 | return $tags; | 403 | return $tags; |
@@ -381,7 +408,7 @@ class Database { | |||
381 | $sql = "SELECT DISTINCT tags.* FROM tags | 408 | $sql = "SELECT DISTINCT tags.* FROM tags |
382 | LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id | 409 | LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id |
383 | LEFT JOIN entries ON tags_entries.entry_id=entries.id | 410 | LEFT JOIN entries ON tags_entries.entry_id=entries.id |
384 | WHERE tags.id=? AND entries.user_id=?"; | 411 | WHERE entries.content <> '' AND tags.id=? AND entries.user_id=?"; |
385 | $params = array(intval($id), $user_id); | 412 | $params = array(intval($id), $user_id); |
386 | $query = $this->executeQuery($sql, $params); | 413 | $query = $this->executeQuery($sql, $params); |
387 | $tag = $query->fetchAll(); | 414 | $tag = $query->fetchAll(); |
@@ -393,7 +420,8 @@ class Database { | |||
393 | $sql = | 420 | $sql = |
394 | "SELECT entries.* FROM entries | 421 | "SELECT entries.* FROM entries |
395 | LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id | 422 | LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id |
396 | WHERE tags_entries.tag_id = ? AND entries.user_id=?"; | 423 | WHERE entries.content <> '' AND |
424 | tags_entries.tag_id = ? AND entries.user_id=?"; | ||
397 | $query = $this->executeQuery($sql, array($tag_id, $user_id)); | 425 | $query = $this->executeQuery($sql, array($tag_id, $user_id)); |
398 | $entries = $query->fetchAll(); | 426 | $entries = $query->fetchAll(); |
399 | 427 | ||