From 00644bb2b8ed29b9949018861a4ab025b65b53b4 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Tue, 30 Apr 2013 22:34:02 -0400 Subject: [PATCH] Bug fix #26: previous/next issue (items with same updated value) --- miniflux/index.php | 3 ++- miniflux/model.php | 24 ++++++++++++++---------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/miniflux/index.php b/miniflux/index.php index 6168bb4..23f2fa3 100644 --- a/miniflux/index.php +++ b/miniflux/index.php @@ -107,12 +107,13 @@ Router\get_action('read', function() { $id = Request\param('id'); $item = Model\get_item($id); + $nav = Model\get_nav_item($item); // must be placed before set_item_read() Model\set_item_read($id); Response\html(Template\layout('read_item', array( 'item' => $item, - 'item_nav' => Model\get_nav_item($item) + 'item_nav' => $nav ))); }); diff --git a/miniflux/model.php b/miniflux/model.php index d14887e..2bcf339 100644 --- a/miniflux/model.php +++ b/miniflux/model.php @@ -241,21 +241,25 @@ function get_item($id) function get_nav_item($item) { - $next_item = \PicoTools\singleton('db') + $unread_items = \PicoTools\singleton('db') ->table('items') ->columns('items.id') ->eq('status', 'unread') - ->lt('updated', $item['updated']) ->desc('updated') - ->findOne(); + ->findAll(); - $previous_item = \PicoTools\singleton('db') - ->table('items') - ->columns('items.id') - ->eq('status', 'unread') - ->gt('updated', $item['updated']) - ->asc('updated') - ->findOne(); + $next_item = null; + $previous_item = null; + + for ($i = 0, $ilen = count($unread_items); $i < $ilen; $i++) { + + if ($unread_items[$i]['id'] == $item['id']) { + + if ($i > 0) $previous_item = $unread_items[$i - 1]; + if ($i < ($ilen - 1)) $next_item = $unread_items[$i + 1]; + break; + } + } return array( 'next' => $next_item,