From 55db6f13dd93ed35e0655cd738e6121559f302a1 Mon Sep 17 00:00:00 2001 From: denfil Date: Sun, 28 Feb 2016 16:58:07 +0300 Subject: [PATCH 1/3] Add group filter to the history section --- controllers/history.php | 22 +++++++++++++++++----- models/item.php | 13 +++++++++++++ templates/confirm_flush_items.php | 4 ++-- templates/history.php | 16 ++++++++++++++-- 4 files changed, 46 insertions(+), 9 deletions(-) diff --git a/controllers/history.php b/controllers/history.php index 98e1957..ecf473c 100644 --- a/controllers/history.php +++ b/controllers/history.php @@ -4,15 +4,20 @@ Router\get_action('history', function() { $offset = Request\int_param('offset', 0); - $nb_items = Model\Item\count_by_status('read'); + $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); + } $items = Model\Item\get_all_by_status( 'read', - array(), + $feed_ids, $offset, Model\Config\get('items_per_page'), 'updated', Model\Config\get('items_sorting_direction') ); + $nb_items = Model\Item\count_by_status('read', $feed_ids); Response\html(Template\layout('history', array( 'favicons' => Model\Favicon\get_item_favicons($items), @@ -21,20 +26,23 @@ Router\get_action('history', function() { 'order' => '', 'direction' => '', 'display_mode' => Model\Config\get('items_display_mode'), + 'group_id' => $group_id, 'nb_items' => $nb_items, 'nb_unread_items' => Model\Item\count_by_status('unread'), 'offset' => $offset, 'items_per_page' => Model\Config\get('items_per_page'), 'nothing_to_read' => Request\int_param('nothing_to_read'), 'menu' => 'history', + 'groups' => Model\Group\get_all(), 'title' => t('History').' ('.$nb_items.')' ))); }); // Confirmation box to flush history Router\get_action('confirm-flush-history', function() { - + $group_id = Request\int_param('group_id', null); Response\html(Template\layout('confirm_flush_items', array( + 'group_id' => $group_id, 'nb_unread_items' => Model\Item\count_by_status('unread'), 'menu' => 'history', 'title' => t('Confirmation') @@ -43,7 +51,11 @@ Router\get_action('confirm-flush-history', function() { // Flush history Router\get_action('flush-history', function() { - - Model\Item\mark_all_as_removed(); + $group_id = Request\int_param('group_id', null); + if (!is_null($group_id)) { + Model\Item\mark_group_as_removed($group_id); + } else { + Model\Item\mark_all_as_removed(); + } Response\redirect('?action=history'); }); diff --git a/models/item.php b/models/item.php index 5ab8736..91e887e 100644 --- a/models/item.php +++ b/models/item.php @@ -376,6 +376,19 @@ function mark_group_as_read($group_id) ->update(array('status' => 'read')); } +// Mark all items of a group as removed +function mark_group_as_removed($group_id) +{ + $feed_ids = Group\get_feeds_by_group($group_id); + + return Database::getInstance('db') + ->table('items') + ->eq('status', 'read') + ->eq('bookmark', 0) + ->in('feed_id', $feed_ids) + ->save(array('status' => 'removed', 'content' => '')); +} + // Mark all read items to removed after X days function autoflush_read() { diff --git a/templates/confirm_flush_items.php b/templates/confirm_flush_items.php index 8a64d60..c554bba 100644 --- a/templates/confirm_flush_items.php +++ b/templates/confirm_flush_items.php @@ -5,6 +5,6 @@

- - + +
\ No newline at end of file diff --git a/templates/history.php b/templates/history.php index b8cbebe..1c4d886 100644 --- a/templates/history.php +++ b/templates/history.php @@ -4,8 +4,20 @@ @@ -26,7 +38,7 @@ )) ?> - $menu, 'nb_items' => $nb_items, 'items_per_page' => $items_per_page, 'offset' => $offset, 'order' => $order, 'direction' => $direction)) ?> + $menu, 'nb_items' => $nb_items, 'items_per_page' => $items_per_page, 'offset' => $offset, 'order' => $order, 'direction' => $direction, 'group_id' => $group_id)) ?> From a2976cf5424a91cf9e0ae25aa41e1a9d350e70a1 Mon Sep 17 00:00:00 2001 From: denfil Date: Sun, 28 Feb 2016 17:39:16 +0300 Subject: [PATCH 2/3] Add group filter to the bookmarks section --- controllers/bookmark.php | 15 +++++++++++++-- models/item.php | 6 ++++-- templates/bookmarks.php | 16 ++++++++++++++-- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/controllers/bookmark.php b/controllers/bookmark.php index 47f4607..d0f7ac6 100644 --- a/controllers/bookmark.php +++ b/controllers/bookmark.php @@ -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.')' ))); }); diff --git a/models/item.php b/models/item.php index 91e887e..d9e65ca 100644 --- a/models/item.php +++ b/models/item.php @@ -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')) diff --git a/templates/bookmarks.php b/templates/bookmarks.php index 41406f3..d4d5b58 100644 --- a/templates/bookmarks.php +++ b/templates/bookmarks.php @@ -1,9 +1,21 @@ - +

@@ -23,7 +35,7 @@ )) ?> - $menu, 'nb_items' => $nb_items, 'items_per_page' => $items_per_page, 'offset' => $offset, 'order' => $order, 'direction' => $direction)) ?> + $menu, 'nb_items' => $nb_items, 'items_per_page' => $items_per_page, 'offset' => $offset, 'order' => $order, 'direction' => $direction, 'group_id' => $group_id)) ?> \ No newline at end of file From 341a2e4ee52e929b63333771496bc86eda7dc299 Mon Sep 17 00:00:00 2001 From: denfil Date: Sun, 28 Feb 2016 17:40:48 +0300 Subject: [PATCH 3/3] Add group_id to the previous page link --- templates/paging.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/paging.php b/templates/paging.php index 2c56b3a..40634d9 100644 --- a/templates/paging.php +++ b/templates/paging.php @@ -1,6 +1,6 @@
0): ?> - « + «   $items_per_page): ?>