Create Bookmark model

This commit is contained in:
Frederic Guillot 2016-08-18 21:44:36 -04:00
parent a52c670c79
commit 321f8a71f8
No known key found for this signature in database
GPG Key ID: 92D77191BA7FBC99
7 changed files with 74 additions and 66 deletions

View File

@ -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')

62
app/models/bookmark.php Normal file
View File

@ -0,0 +1,62 @@
<?php
namespace Model\Bookmark;
use Model\Config;
use Model\Service;
use PicoDb\Database;
function count_items($feed_ids = array())
{
return Database::getInstance('db')
->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));
}

View File

@ -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()
{

View File

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

View File

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

View File

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

View File

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