diff --git a/app/controllers/item.php b/app/controllers/item.php index dfc2108..f4b2989 100644 --- a/app/controllers/item.php +++ b/app/controllers/item.php @@ -101,11 +101,11 @@ Router\get_action('show', function () { Router\get_action('feed-items', function () { $feed_id = Request\int_param('feed_id', 0); $offset = Request\int_param('offset', 0); - $nb_items = Model\Item\count_by_feed($feed_id); + $nb_items = Model\ItemFeed\count_items($feed_id); $feed = Model\Feed\get($feed_id); $order = Request\param('order', 'updated'); $direction = Request\param('direction', Model\Config\get('items_sorting_direction')); - $items = Model\Item\get_all_by_feed($feed_id, $offset, Model\Config\get('items_per_page'), $order, $direction); + $items = Model\ItemFeed\get_all_items($feed_id, $offset, Model\Config\get('items_per_page'), $order, $direction); Response\html(Template\layout('feed_items', array( 'favicons' => Model\Favicon\get_favicons(array($feed['id'])), @@ -173,7 +173,7 @@ Router\get_action('mark-all-read', function () { Router\get_action('mark-feed-as-read', function () { $feed_id = Request\int_param('feed_id'); - Model\Item\mark_feed_as_read($feed_id); + Model\ItemFeed\mark_all_as_read($feed_id); Response\redirect('?action=feed-items&feed_id='.$feed_id); }); @@ -182,7 +182,7 @@ Router\get_action('mark-feed-as-read', function () { // that where marked read from the frontend, since the number of unread items // on page 2+ is unknown. Router\post_action('mark-feed-as-read', function () { - Model\Item\mark_feed_as_read(Request\int_param('feed_id')); + Model\ItemFeed\mark_all_as_read(Request\int_param('feed_id')); $nb_items = Model\Item\count_by_status('unread'); Response\raw($nb_items); diff --git a/app/models/item.php b/app/models/item.php index f00298e..93287f5 100644 --- a/app/models/item.php +++ b/app/models/item.php @@ -169,46 +169,6 @@ function count_by_status($status, $feed_ids = array()) ->count(); } -// Get the number of items per feed -function count_by_feed($feed_id) -{ - return Database::getInstance('db') - ->table('items') - ->eq('feed_id', $feed_id) - ->in('status', array('unread', 'read')) - ->count(); -} - -// Get all items per feed -function get_all_by_feed($feed_id, $offset = null, $limit = null, $order_column = 'updated', $order_direction = 'desc') -{ - return Database::getInstance('db') - ->table('items') - ->columns( - 'items.id', - 'items.title', - 'items.updated', - 'items.url', - 'items.enclosure', - 'items.enclosure_type', - 'items.feed_id', - 'items.status', - 'items.content', - 'items.bookmark', - 'items.language', - 'items.author', - 'feeds.site_url', - 'feeds.rtl' - ) - ->join('feeds', 'id', 'feed_id') - ->in('status', array('unread', 'read')) - ->eq('feed_id', $feed_id) - ->orderBy($order_column, $order_direction) - ->offset($offset) - ->limit($limit) - ->findAll(); -} - // Get one item by id function get($id) { @@ -337,16 +297,6 @@ function mark_all_as_removed() ->save(array('status' => 'removed', 'content' => '')); } -// Mark all items of a feed as read -function mark_feed_as_read($feed_id) -{ - return Database::getInstance('db') - ->table('items') - ->eq('status', 'unread') - ->eq('feed_id', $feed_id) - ->update(array('status' => 'read')); -} - // Mark all items of a group as read function mark_group_as_read($group_id) { diff --git a/app/models/item_feed.php b/app/models/item_feed.php new file mode 100644 index 0000000..7b25cf8 --- /dev/null +++ b/app/models/item_feed.php @@ -0,0 +1,52 @@ +table('items') + ->eq('feed_id', $feed_id) + ->in('status', array('unread', 'read')) + ->count(); +} + +function get_all_items($feed_id, $offset = null, $limit = null, $order_column = 'updated', $order_direction = 'desc') +{ + return Database::getInstance('db') + ->table('items') + ->columns( + 'items.id', + 'items.title', + 'items.updated', + 'items.url', + 'items.enclosure', + 'items.enclosure_type', + 'items.feed_id', + 'items.status', + 'items.content', + 'items.bookmark', + 'items.language', + 'items.author', + 'feeds.site_url', + 'feeds.rtl' + ) + ->join('feeds', 'id', 'feed_id') + ->in('status', array('unread', 'read')) + ->eq('feed_id', $feed_id) + ->orderBy($order_column, $order_direction) + ->offset($offset) + ->limit($limit) + ->findAll(); +} + +function mark_all_as_read($feed_id) +{ + return Database::getInstance('db') + ->table('items') + ->eq('status', 'unread') + ->eq('feed_id', $feed_id) + ->update(array('status' => 'read')); +} diff --git a/composer.json b/composer.json index 1c108d6..30dde02 100644 --- a/composer.json +++ b/composer.json @@ -43,6 +43,7 @@ "app/models/user.php", "app/models/feed.php", "app/models/item.php", + "app/models/item_feed.php", "app/models/bookmark.php", "app/models/proxy.php", "app/models/auto_update.php", diff --git a/jsonrpc.php b/jsonrpc.php index 0ac89e4..1a6fa26 100644 --- a/jsonrpc.php +++ b/jsonrpc.php @@ -129,12 +129,12 @@ $procedureHandler->withCallback('group.update_feed_groups', function($feed_id, $ // Get all items for a specific feed $procedureHandler->withCallback('item.feed.list', function ($feed_id, $offset = null, $limit = null) { - return Model\Item\get_all_by_feed($feed_id, $offset, $limit); + return Model\ItemFeed\get_all_items($feed_id, $offset, $limit); }); // Count all feed items $procedureHandler->withCallback('item.feed.count', function ($feed_id) { - return Model\Item\count_by_feed($feed_id); + return Model\ItemFeed\count_items($feed_id); }); // Get all bookmark items diff --git a/vendor/composer/autoload_files.php b/vendor/composer/autoload_files.php index f654cfe..0af2422 100644 --- a/vendor/composer/autoload_files.php +++ b/vendor/composer/autoload_files.php @@ -24,6 +24,7 @@ return array( '73671a34a21e27508f85cea36a9837de' => $baseDir . '/app/models/user.php', 'e8bcd5701df9db676003b87e27b091c9' => $baseDir . '/app/models/feed.php', '7318478c1ab18cc398507355a29a93c3' => $baseDir . '/app/models/item.php', + 'c0f7d31e45ab3b885f3f3567be6b8cda' => $baseDir . '/app/models/item_feed.php', '546998ee103e300ad614144f30a1de8e' => $baseDir . '/app/models/bookmark.php', '0bdc342df97b8a477df96dbb288b21bf' => $baseDir . '/app/models/proxy.php', 'd06207bd4580f7e9250cf39d0d648fc5' => $baseDir . '/app/models/auto_update.php', diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 5ee43b9..257e94c 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -25,6 +25,7 @@ class ComposerStaticInitfd7e8d436e1dc450edc3153ac8bc31b4 '73671a34a21e27508f85cea36a9837de' => __DIR__ . '/../..' . '/app/models/user.php', 'e8bcd5701df9db676003b87e27b091c9' => __DIR__ . '/../..' . '/app/models/feed.php', '7318478c1ab18cc398507355a29a93c3' => __DIR__ . '/../..' . '/app/models/item.php', + 'c0f7d31e45ab3b885f3f3567be6b8cda' => __DIR__ . '/../..' . '/app/models/item_feed.php', '546998ee103e300ad614144f30a1de8e' => __DIR__ . '/../..' . '/app/models/bookmark.php', '0bdc342df97b8a477df96dbb288b21bf' => __DIR__ . '/../..' . '/app/models/proxy.php', 'd06207bd4580f7e9250cf39d0d648fc5' => __DIR__ . '/../..' . '/app/models/auto_update.php',