aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche/Database.class.php
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas.loeuillet@gmail.com>2014-02-21 13:44:30 +0100
committerNicolas LÅ“uillet <nicolas.loeuillet@gmail.com>2014-02-21 13:44:30 +0100
commite7345a2c4feaa64c8582844425f388e57f1f933d (patch)
tree5f2b7fa7917186052519193542f126692031d095 /inc/poche/Database.class.php
parent3ade95a3d79d356ff4979eeaa6cf1fe3c6da1794 (diff)
parent032e0ca13ab8ebf99b5169f6f733db4184cdde6c (diff)
downloadwallabag-e7345a2c4feaa64c8582844425f388e57f1f933d.tar.gz
wallabag-e7345a2c4feaa64c8582844425f388e57f1f933d.tar.zst
wallabag-e7345a2c4feaa64c8582844425f388e57f1f933d.zip
Merge branch 'dev' of git://github.com/mariroz/wallabag into dev
Diffstat (limited to 'inc/poche/Database.class.php')
-rwxr-xr-x[-rw-r--r--]inc/poche/Database.class.php79
1 files changed, 55 insertions, 24 deletions
diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php
index a366e866..c998fe14 100644..100755
--- a/inc/poche/Database.class.php
+++ b/inc/poche/Database.class.php
@@ -10,8 +10,15 @@
10 10
11class Database { 11class Database {
12 var $handle; 12 var $handle;
13 13 private $order = array(
14 function __construct() 14 'ia' => 'ORDER BY entries.id',
15 'id' => 'ORDER BY entries.id DESC',
16 'ta' => 'ORDER BY lower(entries.title)',
17 'td' => 'ORDER BY lower(entries.title) DESC',
18 'default' => 'ORDER BY entries.id'
19 );
20
21 function __construct()
15 { 22 {
16 switch (STORAGE) { 23 switch (STORAGE) {
17 case 'sqlite': 24 case 'sqlite':
@@ -257,48 +264,62 @@ class Database {
257 $query = $this->executeQuery($sql, $params); 264 $query = $this->executeQuery($sql, $params);
258 } 265 }
259 266
260 public function getEntriesByView($view, $user_id, $limit = '') { 267 public function getEntriesByView($view, $user_id, $limit = '', $tag_id = 0) {
261 switch ($_SESSION['sort']) 268 switch ($view) {
262 { 269 case 'archive':
263 case 'ia': 270 $sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? ";
264 $order = 'ORDER BY id'; 271 $params = array($user_id, 1);
265 break;
266 case 'id':
267 $order = 'ORDER BY id DESC';
268 break; 272 break;
269 case 'ta': 273 case 'fav' :
270 $order = 'ORDER BY lower(title)'; 274 $sql = "SELECT * FROM entries WHERE user_id=? AND is_fav=? ";
275 $params = array($user_id, 1);
271 break; 276 break;
272 case 'td': 277 case 'tag' :
273 $order = 'ORDER BY lower(title) DESC'; 278 $sql = "SELECT entries.* FROM entries
279 LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id
280 WHERE entries.user_id=? AND tags_entries.tag_id = ? ";
281 $params = array($user_id, $tag_id);
274 break; 282 break;
275 default: 283 default:
276 $order = 'ORDER BY id'; 284 $sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? ";
285 $params = array($user_id, 0);
277 break; 286 break;
278 } 287 }
279 288
280 switch ($view) 289 $sql .= $this->getEntriesOrder().' ' . $limit;
281 { 290
291 $query = $this->executeQuery($sql, $params);
292 $entries = $query->fetchAll();
293
294 return $entries;
295 }
296
297 public function getEntriesByViewCount($view, $user_id, $tag_id = 0) {
298 switch ($view) {
282 case 'archive': 299 case 'archive':
283 $sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? " . $order; 300 $sql = "SELECT count(*) FROM entries WHERE user_id=? AND is_read=? ";
284 $params = array($user_id, 1); 301 $params = array($user_id, 1);
285 break; 302 break;
286 case 'fav' : 303 case 'fav' :
287 $sql = "SELECT * FROM entries WHERE user_id=? AND is_fav=? " . $order; 304 $sql = "SELECT count(*) FROM entries WHERE user_id=? AND is_fav=? ";
288 $params = array($user_id, 1); 305 $params = array($user_id, 1);
289 break; 306 break;
307 case 'tag' :
308 $sql = "SELECT count(*) FROM entries
309 LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id
310 WHERE entries.user_id=? AND tags_entries.tag_id = ? ";
311 $params = array($user_id, $tag_id);
312 break;
290 default: 313 default:
291 $sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? " . $order; 314 $sql = "SELECT count(*) FROM entries WHERE user_id=? AND is_read=? ";
292 $params = array($user_id, 0); 315 $params = array($user_id, 0);
293 break; 316 break;
294 } 317 }
295 318
296 $sql .= ' ' . $limit;
297
298 $query = $this->executeQuery($sql, $params); 319 $query = $this->executeQuery($sql, $params);
299 $entries = $query->fetchAll(); 320 list($count) = $query->fetch();
300 321
301 return $entries; 322 return $count;
302 } 323 }
303 324
304 public function updateContent($id, $content, $user_id) { 325 public function updateContent($id, $content, $user_id) {
@@ -420,4 +441,14 @@ class Database {
420 $query = $this->executeQuery($sql_action, $params_action); 441 $query = $this->executeQuery($sql_action, $params_action);
421 return $query; 442 return $query;
422 } 443 }
444
445 private function getEntriesOrder() {
446 if (isset($_SESSION['sort']) and array_key_exists($_SESSION['sort'], $this->order)) {
447 return $this->order[$_SESSION['sort']];
448 }
449 else {
450 return $this->order['default'];
451 }
452 }
453
423} 454}