Add group filter to the bookmarks section
This commit is contained in:
parent
55db6f13dd
commit
a2976cf542
@ -37,8 +37,17 @@ Router\get_action('bookmark', function() {
|
|||||||
Router\get_action('bookmarks', function() {
|
Router\get_action('bookmarks', function() {
|
||||||
|
|
||||||
$offset = Request\int_param('offset', 0);
|
$offset = Request\int_param('offset', 0);
|
||||||
$nb_items = Model\Item\count_bookmarks();
|
$group_id = Request\int_param('group_id', null);
|
||||||
$items = Model\Item\get_bookmarks($offset, Model\Config\get('items_per_page'));
|
$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(
|
Response\html(Template\layout('bookmarks', array(
|
||||||
'favicons' => Model\Favicon\get_item_favicons($items),
|
'favicons' => Model\Favicon\get_item_favicons($items),
|
||||||
@ -46,6 +55,7 @@ Router\get_action('bookmarks', function() {
|
|||||||
'order' => '',
|
'order' => '',
|
||||||
'direction' => '',
|
'direction' => '',
|
||||||
'display_mode' => Model\Config\get('items_display_mode'),
|
'display_mode' => Model\Config\get('items_display_mode'),
|
||||||
|
'group_id' => $group_id,
|
||||||
'items' => $items,
|
'items' => $items,
|
||||||
'nb_items' => $nb_items,
|
'nb_items' => $nb_items,
|
||||||
'offset' => $offset,
|
'offset' => $offset,
|
||||||
@ -53,6 +63,7 @@ Router\get_action('bookmarks', function() {
|
|||||||
'nothing_to_read' => Request\int_param('nothing_to_read'),
|
'nothing_to_read' => Request\int_param('nothing_to_read'),
|
||||||
'nb_unread_items' => Model\Item\count_by_status('unread'),
|
'nb_unread_items' => Model\Item\count_by_status('unread'),
|
||||||
'menu' => 'bookmarks',
|
'menu' => 'bookmarks',
|
||||||
|
'groups' => Model\Group\get_all(),
|
||||||
'title' => t('Bookmarks').' ('.$nb_items.')'
|
'title' => t('Bookmarks').' ('.$nb_items.')'
|
||||||
)));
|
)));
|
||||||
});
|
});
|
||||||
|
@ -131,17 +131,18 @@ function count_by_status($status, $feed_ids = array())
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the number of bookmarks
|
// Get the number of bookmarks
|
||||||
function count_bookmarks()
|
function count_bookmarks($feed_ids = array())
|
||||||
{
|
{
|
||||||
return Database::getInstance('db')
|
return Database::getInstance('db')
|
||||||
->table('items')
|
->table('items')
|
||||||
->eq('bookmark', 1)
|
->eq('bookmark', 1)
|
||||||
|
->in('feed_id', $feed_ids)
|
||||||
->in('status', array('read', 'unread'))
|
->in('status', array('read', 'unread'))
|
||||||
->count();
|
->count();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get all bookmarks
|
// Get all bookmarks
|
||||||
function get_bookmarks($offset = null, $limit = null)
|
function get_bookmarks($offset = null, $limit = null, $feed_ids = array())
|
||||||
{
|
{
|
||||||
return Database::getInstance('db')
|
return Database::getInstance('db')
|
||||||
->table('items')
|
->table('items')
|
||||||
@ -163,6 +164,7 @@ function get_bookmarks($offset = null, $limit = null)
|
|||||||
'feeds.rtl'
|
'feeds.rtl'
|
||||||
)
|
)
|
||||||
->join('feeds', 'id', 'feed_id')
|
->join('feeds', 'id', 'feed_id')
|
||||||
|
->in('feed_id', $feed_ids)
|
||||||
->in('status', array('read', 'unread'))
|
->in('status', array('read', 'unread'))
|
||||||
->eq('bookmark', 1)
|
->eq('bookmark', 1)
|
||||||
->orderBy('updated', Config\get('items_sorting_direction'))
|
->orderBy('updated', Config\get('items_sorting_direction'))
|
||||||
|
@ -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>
|
<p class="alert alert-info"><?= t('No bookmark') ?></p>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
|
|
||||||
<div class="page-header">
|
<div class="page-header">
|
||||||
<h2><?= t('Bookmarks') ?><span id="page-counter"><?= isset($nb_items) ? $nb_items : '' ?></span></h2>
|
<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>
|
</div>
|
||||||
|
|
||||||
<?php if ($nothing_to_read): ?>
|
<?php if ($nothing_to_read): ?>
|
||||||
@ -23,7 +35,7 @@
|
|||||||
)) ?>
|
)) ?>
|
||||||
<?php endforeach ?>
|
<?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>
|
</section>
|
||||||
|
|
||||||
<?php endif ?>
|
<?php endif ?>
|
Loading…
Reference in New Issue
Block a user