aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc
diff options
context:
space:
mode:
authorMaryana Rozhankivska <mariroz@mr.lviv.ua>2014-02-20 19:28:39 +0200
committerMaryana Rozhankivska <mariroz@mr.lviv.ua>2014-02-20 19:28:39 +0200
commit032e0ca13ab8ebf99b5169f6f733db4184cdde6c (patch)
tree202f259fc3d9157e66195036584211e4c84515c1 /inc
parent6203ef8e51c8b2712e54a01a183f30d282926b0b (diff)
downloadwallabag-032e0ca13ab8ebf99b5169f6f733db4184cdde6c.tar.gz
wallabag-032e0ca13ab8ebf99b5169f6f733db4184cdde6c.tar.zst
wallabag-032e0ca13ab8ebf99b5169f6f733db4184cdde6c.zip
a lot of refactoring: tag action is now handled by home view and uses sorting and pagination. Some small view enhacenments. Fix of #476, #461 for baggy and other themes
Diffstat (limited to 'inc')
-rwxr-xr-x[-rw-r--r--]inc/poche/Database.class.php79
-rwxr-xr-xinc/poche/Poche.class.php31
-rw-r--r--inc/poche/Tools.class.php2
3 files changed, 71 insertions, 41 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}
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php
index fc9a455a..23e51c7e 100755
--- a/inc/poche/Poche.class.php
+++ b/inc/poche/Poche.class.php
@@ -585,14 +585,7 @@ class Poche
585 $tpl_vars = array( 585 $tpl_vars = array(
586 'entry_id' => $id, 586 'entry_id' => $id,
587 'tags' => $tags, 587 'tags' => $tags,
588 ); 588 'entry' => $entry,
589 break;
590 case 'tag':
591 $entries = $this->store->retrieveEntriesByTag($id, $this->user->getId());
592 $tag = $this->store->retrieveTag($id, $this->user->getId());
593 $tpl_vars = array(
594 'tag' => $tag,
595 'entries' => $entries,
596 ); 589 );
597 break; 590 break;
598 case 'tags': 591 case 'tags':
@@ -633,22 +626,28 @@ class Poche
633 Tools::logm('error in view call : entry is null'); 626 Tools::logm('error in view call : entry is null');
634 } 627 }
635 break; 628 break;
636 default: # home, favorites and archive views 629 default: # home, favorites, archive and tag views
637 $entries = $this->store->getEntriesByView($view, $this->user->getId());
638 $tpl_vars = array( 630 $tpl_vars = array(
639 'entries' => '', 631 'entries' => '',
640 'page_links' => '', 632 'page_links' => '',
641 'nb_results' => '', 633 'nb_results' => '',
642 ); 634 );
643 635
644 if (count($entries) > 0) { 636 //if id is given - we retrive entries by tag: id is tag id
645 $this->pagination->set_total(count($entries)); 637 if ($id) {
638 $tpl_vars['tag'] = $this->store->retrieveTag($id, $this->user->getId());
639 $tpl_vars['id'] = intval($id);
640 }
641
642 $count = $this->store->getEntriesByViewCount($view, $this->user->getId(), $id);
643
644 if ($count > 0) {
645 $this->pagination->set_total($count);
646 $page_links = str_replace(array('previous', 'next'), array(_('previous'), _('next')), 646 $page_links = str_replace(array('previous', 'next'), array(_('previous'), _('next')),
647 $this->pagination->page_links('?view=' . $view . '&sort=' . $_SESSION['sort'] . '&')); 647 $this->pagination->page_links('?view=' . $view . '&sort=' . $_SESSION['sort'] . (($id)?'&id='.$id:'') . '&' ));
648 $datas = $this->store->getEntriesByView($view, $this->user->getId(), $this->pagination->get_limit()); 648 $tpl_vars['entries'] = $this->store->getEntriesByView($view, $this->user->getId(), $this->pagination->get_limit(), $id);
649 $tpl_vars['entries'] = $datas;
650 $tpl_vars['page_links'] = $page_links; 649 $tpl_vars['page_links'] = $page_links;
651 $tpl_vars['nb_results'] = count($entries); 650 $tpl_vars['nb_results'] = $count;
652 } 651 }
653 Tools::logm('display ' . $view . ' view'); 652 Tools::logm('display ' . $view . ' view');
654 break; 653 break;
diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php
index 515a08aa..4ed28ed1 100644
--- a/inc/poche/Tools.class.php
+++ b/inc/poche/Tools.class.php
@@ -92,7 +92,7 @@ class Tools
92 { 92 {
93 $views = array( 93 $views = array(
94 'install', 'import', 'export', 'config', 'tags', 94 'install', 'import', 'export', 'config', 'tags',
95 'edit-tags', 'view', 'login', 'error', 'tag' 95 'edit-tags', 'view', 'login', 'error'
96 ); 96 );
97 97
98 if (in_array($view, $views)) { 98 if (in_array($view, $views)) {