Create Bookmark model
This commit is contained in:
parent
a52c670c79
commit
321f8a71f8
@ -11,7 +11,7 @@ Router\post_action('bookmark', function () {
|
|||||||
Response\json(array(
|
Response\json(array(
|
||||||
'id' => $id,
|
'id' => $id,
|
||||||
'value' => $value,
|
'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);
|
$offset = Request\int_param('offset', 0);
|
||||||
$feed_id = Request\int_param('feed_id', 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') {
|
if ($redirect === 'show') {
|
||||||
Response\redirect('?action=show&menu='.$menu.'&id='.$id);
|
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);
|
$feed_ids = Model\Group\get_feeds_by_group($group_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
$nb_items = Model\Item\count_bookmarks($feed_ids);
|
$nb_items = Model\Bookmark\count_items($feed_ids);
|
||||||
$items = Model\Item\get_bookmarks(
|
$items = Model\Bookmark\get_all_items(
|
||||||
$offset,
|
$offset,
|
||||||
Model\Config\get('items_per_page'),
|
Model\Config\get('items_per_page'),
|
||||||
$feed_ids
|
$feed_ids
|
||||||
@ -87,7 +87,7 @@ Router\get_action('bookmark-feed', function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Build Feed
|
// Build Feed
|
||||||
$bookmarks = Model\Item\get_bookmarks();
|
$bookmarks = Model\Bookmark\get_all_items();
|
||||||
|
|
||||||
$feedBuilder = AtomFeedBuilder::create()
|
$feedBuilder = AtomFeedBuilder::create()
|
||||||
->withTitle(t('Bookmarks').' - Miniflux')
|
->withTitle(t('Bookmarks').' - Miniflux')
|
||||||
|
62
app/models/bookmark.php
Normal file
62
app/models/bookmark.php
Normal 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));
|
||||||
|
}
|
@ -169,49 +169,6 @@ function count_by_status($status, $feed_ids = array())
|
|||||||
->count();
|
->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
|
// Get the number of items per feed
|
||||||
function count_by_feed($feed_id)
|
function count_by_feed($feed_id)
|
||||||
{
|
{
|
||||||
@ -361,20 +318,6 @@ function set_status($status, array $items)
|
|||||||
->save(array('status' => $status));
|
->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
|
// Mark all unread items as read
|
||||||
function mark_all_as_read()
|
function mark_all_as_read()
|
||||||
{
|
{
|
||||||
|
@ -43,6 +43,7 @@
|
|||||||
"app/models/user.php",
|
"app/models/user.php",
|
||||||
"app/models/feed.php",
|
"app/models/feed.php",
|
||||||
"app/models/item.php",
|
"app/models/item.php",
|
||||||
|
"app/models/bookmark.php",
|
||||||
"app/models/proxy.php",
|
"app/models/proxy.php",
|
||||||
"app/models/auto_update.php",
|
"app/models/auto_update.php",
|
||||||
"app/models/database.php",
|
"app/models/database.php",
|
||||||
|
@ -139,22 +139,22 @@ $procedureHandler->withCallback('item.feed.count', function ($feed_id) {
|
|||||||
|
|
||||||
// Get all bookmark items
|
// Get all bookmark items
|
||||||
$procedureHandler->withCallback('item.bookmark.list', function ($offset = null, $limit = null) {
|
$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
|
// Count bookmarks
|
||||||
$procedureHandler->withCallback('item.bookmark.count', function () {
|
$procedureHandler->withCallback('item.bookmark.count', function () {
|
||||||
return Model\Item\count_bookmarks();
|
return Model\Bookmark\count_items();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add a bookmark
|
// Add a bookmark
|
||||||
$procedureHandler->withCallback('item.bookmark.create', function ($item_id) {
|
$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
|
// Remove a bookmark
|
||||||
$procedureHandler->withCallback('item.bookmark.delete', function ($item_id) {
|
$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
|
// Get all unread items
|
||||||
|
1
vendor/composer/autoload_files.php
vendored
1
vendor/composer/autoload_files.php
vendored
@ -24,6 +24,7 @@ return array(
|
|||||||
'73671a34a21e27508f85cea36a9837de' => $baseDir . '/app/models/user.php',
|
'73671a34a21e27508f85cea36a9837de' => $baseDir . '/app/models/user.php',
|
||||||
'e8bcd5701df9db676003b87e27b091c9' => $baseDir . '/app/models/feed.php',
|
'e8bcd5701df9db676003b87e27b091c9' => $baseDir . '/app/models/feed.php',
|
||||||
'7318478c1ab18cc398507355a29a93c3' => $baseDir . '/app/models/item.php',
|
'7318478c1ab18cc398507355a29a93c3' => $baseDir . '/app/models/item.php',
|
||||||
|
'546998ee103e300ad614144f30a1de8e' => $baseDir . '/app/models/bookmark.php',
|
||||||
'0bdc342df97b8a477df96dbb288b21bf' => $baseDir . '/app/models/proxy.php',
|
'0bdc342df97b8a477df96dbb288b21bf' => $baseDir . '/app/models/proxy.php',
|
||||||
'd06207bd4580f7e9250cf39d0d648fc5' => $baseDir . '/app/models/auto_update.php',
|
'd06207bd4580f7e9250cf39d0d648fc5' => $baseDir . '/app/models/auto_update.php',
|
||||||
'6a19d5803b084354df8269801d4e98e4' => $baseDir . '/app/models/database.php',
|
'6a19d5803b084354df8269801d4e98e4' => $baseDir . '/app/models/database.php',
|
||||||
|
1
vendor/composer/autoload_static.php
vendored
1
vendor/composer/autoload_static.php
vendored
@ -25,6 +25,7 @@ class ComposerStaticInitfd7e8d436e1dc450edc3153ac8bc31b4
|
|||||||
'73671a34a21e27508f85cea36a9837de' => __DIR__ . '/../..' . '/app/models/user.php',
|
'73671a34a21e27508f85cea36a9837de' => __DIR__ . '/../..' . '/app/models/user.php',
|
||||||
'e8bcd5701df9db676003b87e27b091c9' => __DIR__ . '/../..' . '/app/models/feed.php',
|
'e8bcd5701df9db676003b87e27b091c9' => __DIR__ . '/../..' . '/app/models/feed.php',
|
||||||
'7318478c1ab18cc398507355a29a93c3' => __DIR__ . '/../..' . '/app/models/item.php',
|
'7318478c1ab18cc398507355a29a93c3' => __DIR__ . '/../..' . '/app/models/item.php',
|
||||||
|
'546998ee103e300ad614144f30a1de8e' => __DIR__ . '/../..' . '/app/models/bookmark.php',
|
||||||
'0bdc342df97b8a477df96dbb288b21bf' => __DIR__ . '/../..' . '/app/models/proxy.php',
|
'0bdc342df97b8a477df96dbb288b21bf' => __DIR__ . '/../..' . '/app/models/proxy.php',
|
||||||
'd06207bd4580f7e9250cf39d0d648fc5' => __DIR__ . '/../..' . '/app/models/auto_update.php',
|
'd06207bd4580f7e9250cf39d0d648fc5' => __DIR__ . '/../..' . '/app/models/auto_update.php',
|
||||||
'6a19d5803b084354df8269801d4e98e4' => __DIR__ . '/../..' . '/app/models/database.php',
|
'6a19d5803b084354df8269801d4e98e4' => __DIR__ . '/../..' . '/app/models/database.php',
|
||||||
|
Loading…
Reference in New Issue
Block a user