mirror of
https://github.com/wallabag/wallabag.git
synced 2025-07-12 16:58:37 +00:00
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
This commit is contained in:
parent
6203ef8e51
commit
032e0ca13a
15 changed files with 143 additions and 130 deletions
89
inc/poche/Database.class.php
Normal file → Executable file
89
inc/poche/Database.class.php
Normal file → Executable file
|
@ -10,8 +10,15 @@
|
|||
|
||||
class Database {
|
||||
var $handle;
|
||||
private $order = array(
|
||||
'ia' => 'ORDER BY entries.id',
|
||||
'id' => 'ORDER BY entries.id DESC',
|
||||
'ta' => 'ORDER BY lower(entries.title)',
|
||||
'td' => 'ORDER BY lower(entries.title) DESC',
|
||||
'default' => 'ORDER BY entries.id'
|
||||
);
|
||||
|
||||
function __construct()
|
||||
function __construct()
|
||||
{
|
||||
switch (STORAGE) {
|
||||
case 'sqlite':
|
||||
|
@ -257,48 +264,62 @@ class Database {
|
|||
$query = $this->executeQuery($sql, $params);
|
||||
}
|
||||
|
||||
public function getEntriesByView($view, $user_id, $limit = '') {
|
||||
switch ($_SESSION['sort'])
|
||||
{
|
||||
case 'ia':
|
||||
$order = 'ORDER BY id';
|
||||
break;
|
||||
case 'id':
|
||||
$order = 'ORDER BY id DESC';
|
||||
break;
|
||||
case 'ta':
|
||||
$order = 'ORDER BY lower(title)';
|
||||
break;
|
||||
case 'td':
|
||||
$order = 'ORDER BY lower(title) DESC';
|
||||
break;
|
||||
default:
|
||||
$order = 'ORDER BY id';
|
||||
break;
|
||||
}
|
||||
|
||||
switch ($view)
|
||||
{
|
||||
public function getEntriesByView($view, $user_id, $limit = '', $tag_id = 0) {
|
||||
switch ($view) {
|
||||
case 'archive':
|
||||
$sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? " . $order;
|
||||
$sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? ";
|
||||
$params = array($user_id, 1);
|
||||
break;
|
||||
case 'fav' :
|
||||
$sql = "SELECT * FROM entries WHERE user_id=? AND is_fav=? " . $order;
|
||||
$sql = "SELECT * FROM entries WHERE user_id=? AND is_fav=? ";
|
||||
$params = array($user_id, 1);
|
||||
break;
|
||||
case 'tag' :
|
||||
$sql = "SELECT entries.* FROM entries
|
||||
LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id
|
||||
WHERE entries.user_id=? AND tags_entries.tag_id = ? ";
|
||||
$params = array($user_id, $tag_id);
|
||||
break;
|
||||
default:
|
||||
$sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? " . $order;
|
||||
$sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? ";
|
||||
$params = array($user_id, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
$sql .= ' ' . $limit;
|
||||
$sql .= $this->getEntriesOrder().' ' . $limit;
|
||||
|
||||
$query = $this->executeQuery($sql, $params);
|
||||
$entries = $query->fetchAll();
|
||||
|
||||
return $entries;
|
||||
}
|
||||
|
||||
public function getEntriesByViewCount($view, $user_id, $tag_id = 0) {
|
||||
switch ($view) {
|
||||
case 'archive':
|
||||
$sql = "SELECT count(*) FROM entries WHERE user_id=? AND is_read=? ";
|
||||
$params = array($user_id, 1);
|
||||
break;
|
||||
case 'fav' :
|
||||
$sql = "SELECT count(*) FROM entries WHERE user_id=? AND is_fav=? ";
|
||||
$params = array($user_id, 1);
|
||||
break;
|
||||
case 'tag' :
|
||||
$sql = "SELECT count(*) FROM entries
|
||||
LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id
|
||||
WHERE entries.user_id=? AND tags_entries.tag_id = ? ";
|
||||
$params = array($user_id, $tag_id);
|
||||
break;
|
||||
default:
|
||||
$sql = "SELECT count(*) FROM entries WHERE user_id=? AND is_read=? ";
|
||||
$params = array($user_id, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
$query = $this->executeQuery($sql, $params);
|
||||
$entries = $query->fetchAll();
|
||||
list($count) = $query->fetch();
|
||||
|
||||
return $entries;
|
||||
return $count;
|
||||
}
|
||||
|
||||
public function updateContent($id, $content, $user_id) {
|
||||
|
@ -420,4 +441,14 @@ class Database {
|
|||
$query = $this->executeQuery($sql_action, $params_action);
|
||||
return $query;
|
||||
}
|
||||
|
||||
private function getEntriesOrder() {
|
||||
if (isset($_SESSION['sort']) and array_key_exists($_SESSION['sort'], $this->order)) {
|
||||
return $this->order[$_SESSION['sort']];
|
||||
}
|
||||
else {
|
||||
return $this->order['default'];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -585,14 +585,7 @@ class Poche
|
|||
$tpl_vars = array(
|
||||
'entry_id' => $id,
|
||||
'tags' => $tags,
|
||||
);
|
||||
break;
|
||||
case 'tag':
|
||||
$entries = $this->store->retrieveEntriesByTag($id, $this->user->getId());
|
||||
$tag = $this->store->retrieveTag($id, $this->user->getId());
|
||||
$tpl_vars = array(
|
||||
'tag' => $tag,
|
||||
'entries' => $entries,
|
||||
'entry' => $entry,
|
||||
);
|
||||
break;
|
||||
case 'tags':
|
||||
|
@ -633,22 +626,28 @@ class Poche
|
|||
Tools::logm('error in view call : entry is null');
|
||||
}
|
||||
break;
|
||||
default: # home, favorites and archive views
|
||||
$entries = $this->store->getEntriesByView($view, $this->user->getId());
|
||||
default: # home, favorites, archive and tag views
|
||||
$tpl_vars = array(
|
||||
'entries' => '',
|
||||
'page_links' => '',
|
||||
'nb_results' => '',
|
||||
);
|
||||
|
||||
if (count($entries) > 0) {
|
||||
$this->pagination->set_total(count($entries));
|
||||
//if id is given - we retrive entries by tag: id is tag id
|
||||
if ($id) {
|
||||
$tpl_vars['tag'] = $this->store->retrieveTag($id, $this->user->getId());
|
||||
$tpl_vars['id'] = intval($id);
|
||||
}
|
||||
|
||||
$count = $this->store->getEntriesByViewCount($view, $this->user->getId(), $id);
|
||||
|
||||
if ($count > 0) {
|
||||
$this->pagination->set_total($count);
|
||||
$page_links = str_replace(array('previous', 'next'), array(_('previous'), _('next')),
|
||||
$this->pagination->page_links('?view=' . $view . '&sort=' . $_SESSION['sort'] . '&'));
|
||||
$datas = $this->store->getEntriesByView($view, $this->user->getId(), $this->pagination->get_limit());
|
||||
$tpl_vars['entries'] = $datas;
|
||||
$this->pagination->page_links('?view=' . $view . '&sort=' . $_SESSION['sort'] . (($id)?'&id='.$id:'') . '&' ));
|
||||
$tpl_vars['entries'] = $this->store->getEntriesByView($view, $this->user->getId(), $this->pagination->get_limit(), $id);
|
||||
$tpl_vars['page_links'] = $page_links;
|
||||
$tpl_vars['nb_results'] = count($entries);
|
||||
$tpl_vars['nb_results'] = $count;
|
||||
}
|
||||
Tools::logm('display ' . $view . ' view');
|
||||
break;
|
||||
|
|
|
@ -92,7 +92,7 @@ class Tools
|
|||
{
|
||||
$views = array(
|
||||
'install', 'import', 'export', 'config', 'tags',
|
||||
'edit-tags', 'view', 'login', 'error', 'tag'
|
||||
'edit-tags', 'view', 'login', 'error'
|
||||
);
|
||||
|
||||
if (in_array($view, $views)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue