Bug fix #26: previous/next issue (items with same updated value)
This commit is contained in:
parent
40f20a9bf5
commit
00644bb2b8
@ -107,12 +107,13 @@ Router\get_action('read', function() {
|
|||||||
|
|
||||||
$id = Request\param('id');
|
$id = Request\param('id');
|
||||||
$item = Model\get_item($id);
|
$item = Model\get_item($id);
|
||||||
|
$nav = Model\get_nav_item($item); // must be placed before set_item_read()
|
||||||
|
|
||||||
Model\set_item_read($id);
|
Model\set_item_read($id);
|
||||||
|
|
||||||
Response\html(Template\layout('read_item', array(
|
Response\html(Template\layout('read_item', array(
|
||||||
'item' => $item,
|
'item' => $item,
|
||||||
'item_nav' => Model\get_nav_item($item)
|
'item_nav' => $nav
|
||||||
)));
|
)));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -241,21 +241,25 @@ function get_item($id)
|
|||||||
|
|
||||||
function get_nav_item($item)
|
function get_nav_item($item)
|
||||||
{
|
{
|
||||||
$next_item = \PicoTools\singleton('db')
|
$unread_items = \PicoTools\singleton('db')
|
||||||
->table('items')
|
->table('items')
|
||||||
->columns('items.id')
|
->columns('items.id')
|
||||||
->eq('status', 'unread')
|
->eq('status', 'unread')
|
||||||
->lt('updated', $item['updated'])
|
|
||||||
->desc('updated')
|
->desc('updated')
|
||||||
->findOne();
|
->findAll();
|
||||||
|
|
||||||
$previous_item = \PicoTools\singleton('db')
|
$next_item = null;
|
||||||
->table('items')
|
$previous_item = null;
|
||||||
->columns('items.id')
|
|
||||||
->eq('status', 'unread')
|
for ($i = 0, $ilen = count($unread_items); $i < $ilen; $i++) {
|
||||||
->gt('updated', $item['updated'])
|
|
||||||
->asc('updated')
|
if ($unread_items[$i]['id'] == $item['id']) {
|
||||||
->findOne();
|
|
||||||
|
if ($i > 0) $previous_item = $unread_items[$i - 1];
|
||||||
|
if ($i < ($ilen - 1)) $next_item = $unread_items[$i + 1];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'next' => $next_item,
|
'next' => $next_item,
|
||||||
|
Loading…
Reference in New Issue
Block a user