Bug fix #26: previous/next issue (items with same updated value)

This commit is contained in:
Frederic Guillot 2013-04-30 22:34:02 -04:00
parent 40f20a9bf5
commit 00644bb2b8
2 changed files with 16 additions and 11 deletions

View File

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

View File

@ -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,