Add group filter to the bookmarks section

This commit is contained in:
denfil 2016-02-28 17:39:16 +03:00
parent 55db6f13dd
commit a2976cf542
3 changed files with 31 additions and 6 deletions

View File

@ -37,8 +37,17 @@ Router\get_action('bookmark', function() {
Router\get_action('bookmarks', function() {
$offset = Request\int_param('offset', 0);
$nb_items = Model\Item\count_bookmarks();
$items = Model\Item\get_bookmarks($offset, Model\Config\get('items_per_page'));
$group_id = Request\int_param('group_id', null);
$feed_ids = array();
if (! is_null($group_id)) {
$feed_ids = Model\Group\get_feeds_by_group($group_id);
}
$nb_items = Model\Item\count_bookmarks($feed_ids);
$items = Model\Item\get_bookmarks(
$offset,
Model\Config\get('items_per_page'),
$feed_ids
);
Response\html(Template\layout('bookmarks', array(
'favicons' => Model\Favicon\get_item_favicons($items),
@ -46,6 +55,7 @@ Router\get_action('bookmarks', function() {
'order' => '',
'direction' => '',
'display_mode' => Model\Config\get('items_display_mode'),
'group_id' => $group_id,
'items' => $items,
'nb_items' => $nb_items,
'offset' => $offset,
@ -53,6 +63,7 @@ Router\get_action('bookmarks', function() {
'nothing_to_read' => Request\int_param('nothing_to_read'),
'nb_unread_items' => Model\Item\count_by_status('unread'),
'menu' => 'bookmarks',
'groups' => Model\Group\get_all(),
'title' => t('Bookmarks').' ('.$nb_items.')'
)));
});

View File

@ -131,17 +131,18 @@ function count_by_status($status, $feed_ids = array())
}
// Get the number of bookmarks
function count_bookmarks()
function count_bookmarks($feed_ids = array())
{
return Database::getInstance('db')
->table('items')
->eq('bookmark', 1)
->in('feed_id', $feed_ids)
->in('status', array('read', 'unread'))
->count();
}
// Get all bookmarks
function get_bookmarks($offset = null, $limit = null)
function get_bookmarks($offset = null, $limit = null, $feed_ids = array())
{
return Database::getInstance('db')
->table('items')
@ -163,6 +164,7 @@ function get_bookmarks($offset = null, $limit = null)
'feeds.rtl'
)
->join('feeds', 'id', 'feed_id')
->in('feed_id', $feed_ids)
->in('status', array('read', 'unread'))
->eq('bookmark', 1)
->orderBy('updated', Config\get('items_sorting_direction'))

View File

@ -1,9 +1,21 @@
<?php if (empty($items)): ?>
<?php if (empty($items) && is_null($group_id)): ?>
<p class="alert alert-info"><?= t('No bookmark') ?></p>
<?php else: ?>
<div class="page-header">
<h2><?= t('Bookmarks') ?><span id="page-counter"><?= isset($nb_items) ? $nb_items : '' ?></span></h2>
<?php if (!empty($groups)): ?>
<nav>
<ul id="grouplist">
<?php foreach ($groups as $group): ?>
<li <?= $group['id'] == $group_id ? 'class="active"' : '' ?>>
<a href="?action=bookmarks&group_id=<?=$group['id']?>"><?=$group['title']?></a>
</li>
<?php endforeach ?>
</ul>
</nav>
<?php endif ?>
</div>
<?php if ($nothing_to_read): ?>
@ -23,7 +35,7 @@
)) ?>
<?php endforeach ?>
<?= \Template\load('paging', array('menu' => $menu, 'nb_items' => $nb_items, 'items_per_page' => $items_per_page, 'offset' => $offset, 'order' => $order, 'direction' => $direction)) ?>
<?= \Template\load('paging', array('menu' => $menu, 'nb_items' => $nb_items, 'items_per_page' => $items_per_page, 'offset' => $offset, 'order' => $order, 'direction' => $direction, 'group_id' => $group_id)) ?>
</section>
<?php endif ?>