diff --git a/app/controllers/bookmark.php b/app/controllers/bookmark.php index 69ba8b4..55b1f62 100644 --- a/app/controllers/bookmark.php +++ b/app/controllers/bookmark.php @@ -11,7 +11,7 @@ Router\post_action('bookmark', function () { Response\json(array( 'id' => $id, 'value' => $value, - 'result' => Model\Item\set_bookmark_value($id, $value), + 'result' => Model\Bookmark\set_flag($id, $value), )); }); @@ -23,7 +23,7 @@ Router\get_action('bookmark', function () { $offset = Request\int_param('offset', 0); $feed_id = Request\int_param('feed_id', 0); - Model\Item\set_bookmark_value($id, Request\int_param('value')); + Model\Bookmark\set_flag($id, Request\int_param('value')); if ($redirect === 'show') { Response\redirect('?action=show&menu='.$menu.'&id='.$id); @@ -42,8 +42,8 @@ Router\get_action('bookmarks', function () { $feed_ids = Model\Group\get_feeds_by_group($group_id); } - $nb_items = Model\Item\count_bookmarks($feed_ids); - $items = Model\Item\get_bookmarks( + $nb_items = Model\Bookmark\count_items($feed_ids); + $items = Model\Bookmark\get_all_items( $offset, Model\Config\get('items_per_page'), $feed_ids @@ -87,7 +87,7 @@ Router\get_action('bookmark-feed', function () { } // Build Feed - $bookmarks = Model\Item\get_bookmarks(); + $bookmarks = Model\Bookmark\get_all_items(); $feedBuilder = AtomFeedBuilder::create() ->withTitle(t('Bookmarks').' - Miniflux') diff --git a/app/models/bookmark.php b/app/models/bookmark.php new file mode 100644 index 0000000..79c0670 --- /dev/null +++ b/app/models/bookmark.php @@ -0,0 +1,62 @@ +table('items') + ->eq('bookmark', 1) + ->in('feed_id', $feed_ids) + ->in('status', array('read', 'unread')) + ->count(); +} + +function get_all_items($offset = null, $limit = null, $feed_ids = array()) +{ + return Database::getInstance('db') + ->table('items') + ->columns( + 'items.id', + 'items.title', + 'items.updated', + 'items.url', + 'items.enclosure', + 'items.enclosure_type', + 'items.bookmark', + 'items.status', + 'items.content', + 'items.feed_id', + 'items.language', + 'items.author', + 'feeds.site_url', + 'feeds.title AS feed_title', + 'feeds.rtl' + ) + ->join('feeds', 'id', 'feed_id') + ->in('feed_id', $feed_ids) + ->in('status', array('read', 'unread')) + ->eq('bookmark', 1) + ->orderBy('updated', Config\get('items_sorting_direction')) + ->offset($offset) + ->limit($limit) + ->findAll(); +} + +// Enable/disable bookmark flag +function set_flag($id, $value) +{ + if ($value == 1) { + Service\push($id); + } + + return Database::getInstance('db') + ->table('items') + ->eq('id', $id) + ->in('status', array('read', 'unread')) + ->save(array('bookmark' => $value)); +} diff --git a/app/models/item.php b/app/models/item.php index ece9d6a..f00298e 100644 --- a/app/models/item.php +++ b/app/models/item.php @@ -169,49 +169,6 @@ function count_by_status($status, $feed_ids = array()) ->count(); } -// Get the number of bookmarks -function count_bookmarks($feed_ids = array()) -{ - return Database::getInstance('db') - ->table('items') - ->eq('bookmark', 1) - ->in('feed_id', $feed_ids) - ->in('status', array('read', 'unread')) - ->count(); -} - -// Get all bookmarks -function get_bookmarks($offset = null, $limit = null, $feed_ids = array()) -{ - return Database::getInstance('db') - ->table('items') - ->columns( - 'items.id', - 'items.title', - 'items.updated', - 'items.url', - 'items.enclosure', - 'items.enclosure_type', - 'items.bookmark', - 'items.status', - 'items.content', - 'items.feed_id', - 'items.language', - 'items.author', - 'feeds.site_url', - 'feeds.title AS feed_title', - 'feeds.rtl' - ) - ->join('feeds', 'id', 'feed_id') - ->in('feed_id', $feed_ids) - ->in('status', array('read', 'unread')) - ->eq('bookmark', 1) - ->orderBy('updated', Config\get('items_sorting_direction')) - ->offset($offset) - ->limit($limit) - ->findAll(); -} - // Get the number of items per feed function count_by_feed($feed_id) { @@ -361,20 +318,6 @@ function set_status($status, array $items) ->save(array('status' => $status)); } -// Enable/disable bookmark flag -function set_bookmark_value($id, $value) -{ - if ($value == 1) { - Service\push($id); - } - - return Database::getInstance('db') - ->table('items') - ->eq('id', $id) - ->in('status', array('read', 'unread')) - ->save(array('bookmark' => $value)); -} - // Mark all unread items as read function mark_all_as_read() { diff --git a/composer.json b/composer.json index d1120d6..1c108d6 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/bookmark.php", "app/models/proxy.php", "app/models/auto_update.php", "app/models/database.php", diff --git a/jsonrpc.php b/jsonrpc.php index 4c4f157..0ac89e4 100644 --- a/jsonrpc.php +++ b/jsonrpc.php @@ -139,22 +139,22 @@ $procedureHandler->withCallback('item.feed.count', function ($feed_id) { // Get all bookmark items $procedureHandler->withCallback('item.bookmark.list', function ($offset = null, $limit = null) { - return Model\Item\get_bookmarks($offset, $limit); + return Model\Bookmark\get_all_items($offset, $limit); }); // Count bookmarks $procedureHandler->withCallback('item.bookmark.count', function () { - return Model\Item\count_bookmarks(); + return Model\Bookmark\count_items(); }); // Add a bookmark $procedureHandler->withCallback('item.bookmark.create', function ($item_id) { - return Model\Item\set_bookmark_value($item_id, 1); + return Model\Bookmark\set_flag($item_id, 1); }); // Remove a bookmark $procedureHandler->withCallback('item.bookmark.delete', function ($item_id) { - return Model\Item\set_bookmark_value($item_id, 0); + return Model\Bookmark\set_flag($item_id, 0); }); // Get all unread items diff --git a/vendor/composer/autoload_files.php b/vendor/composer/autoload_files.php index 632f494..f654cfe 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', + '546998ee103e300ad614144f30a1de8e' => $baseDir . '/app/models/bookmark.php', '0bdc342df97b8a477df96dbb288b21bf' => $baseDir . '/app/models/proxy.php', 'd06207bd4580f7e9250cf39d0d648fc5' => $baseDir . '/app/models/auto_update.php', '6a19d5803b084354df8269801d4e98e4' => $baseDir . '/app/models/database.php', diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 508a534..5ee43b9 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', + '546998ee103e300ad614144f30a1de8e' => __DIR__ . '/../..' . '/app/models/bookmark.php', '0bdc342df97b8a477df96dbb288b21bf' => __DIR__ . '/../..' . '/app/models/proxy.php', 'd06207bd4580f7e9250cf39d0d648fc5' => __DIR__ . '/../..' . '/app/models/auto_update.php', '6a19d5803b084354df8269801d4e98e4' => __DIR__ . '/../..' . '/app/models/database.php',