Skip to content

Commit

Permalink
Bug fix #26: previous/next issue (items with same updated value)
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederic Guillot committed May 1, 2013
1 parent 40f20a9 commit 00644bb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
3 changes: 2 additions & 1 deletion miniflux/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,13 @@

$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
)));
});

Expand Down
24 changes: 14 additions & 10 deletions miniflux/model.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 00644bb

Please sign in to comment.