2016-08-19 03:44:36 +02:00
|
|
|
<?php
|
|
|
|
|
2016-08-25 03:17:58 +02:00
|
|
|
namespace Miniflux\Model\Bookmark;
|
2016-08-19 03:44:36 +02:00
|
|
|
|
2016-12-26 15:44:53 +01:00
|
|
|
use Miniflux\Helper;
|
|
|
|
use Miniflux\Model;
|
2016-08-19 03:44:36 +02:00
|
|
|
use PicoDb\Database;
|
|
|
|
|
2016-12-26 15:44:53 +01:00
|
|
|
function count_bookmarked_items($user_id, array $feed_ids = array())
|
2016-08-19 03:44:36 +02:00
|
|
|
{
|
|
|
|
return Database::getInstance('db')
|
2016-12-26 15:44:53 +01:00
|
|
|
->table(Model\Item\TABLE)
|
2016-08-19 03:44:36 +02:00
|
|
|
->eq('bookmark', 1)
|
2016-12-26 15:44:53 +01:00
|
|
|
->eq('user_id', $user_id)
|
2016-08-19 03:44:36 +02:00
|
|
|
->in('feed_id', $feed_ids)
|
2016-12-26 15:44:53 +01:00
|
|
|
->in('status', array(Model\Item\STATUS_READ, Model\Item\STATUS_UNREAD))
|
2016-08-19 03:44:36 +02:00
|
|
|
->count();
|
|
|
|
}
|
|
|
|
|
2016-12-26 15:44:53 +01:00
|
|
|
function get_bookmarked_items($user_id, $offset = null, $limit = null, array $feed_ids = array())
|
2016-08-19 03:44:36 +02:00
|
|
|
{
|
|
|
|
return Database::getInstance('db')
|
2016-12-26 15:44:53 +01:00
|
|
|
->table(Model\Item\TABLE)
|
2016-08-19 03:44:36 +02:00
|
|
|
->columns(
|
|
|
|
'items.id',
|
2016-12-26 15:44:53 +01:00
|
|
|
'items.checksum',
|
2016-08-19 03:44:36 +02:00
|
|
|
'items.title',
|
|
|
|
'items.updated',
|
|
|
|
'items.url',
|
2016-12-26 15:44:53 +01:00
|
|
|
'items.enclosure_url',
|
2016-08-19 03:44:36 +02:00
|
|
|
'items.enclosure_type',
|
|
|
|
'items.bookmark',
|
|
|
|
'items.status',
|
|
|
|
'items.content',
|
|
|
|
'items.feed_id',
|
|
|
|
'items.language',
|
2016-12-26 15:44:53 +01:00
|
|
|
'items.rtl',
|
2016-08-19 03:44:36 +02:00
|
|
|
'items.author',
|
|
|
|
'feeds.site_url',
|
2016-12-26 15:44:53 +01:00
|
|
|
'feeds.title AS feed_title'
|
2016-08-19 03:44:36 +02:00
|
|
|
)
|
2016-12-26 15:44:53 +01:00
|
|
|
->join(Model\Feed\TABLE, 'id', 'feed_id')
|
|
|
|
->eq('items.user_id', $user_id)
|
|
|
|
->in('items.feed_id', $feed_ids)
|
|
|
|
->neq('items.status', Model\Item\STATUS_REMOVED)
|
|
|
|
->eq('items.bookmark', 1)
|
|
|
|
->orderBy('items.updated', Helper\config('items_sorting_direction'))
|
2016-08-19 03:44:36 +02:00
|
|
|
->offset($offset)
|
|
|
|
->limit($limit)
|
|
|
|
->findAll();
|
|
|
|
}
|
|
|
|
|
2016-12-26 15:44:53 +01:00
|
|
|
function get_bookmarked_item_ids($user_id)
|
2016-08-19 03:44:36 +02:00
|
|
|
{
|
2016-12-26 15:44:53 +01:00
|
|
|
return Database::getInstance('db')
|
|
|
|
->table(Model\Item\TABLE)
|
|
|
|
->eq('user_id', $user_id)
|
|
|
|
->eq('bookmark', 1)
|
2016-12-30 00:04:56 +01:00
|
|
|
->asc('id')
|
2016-12-26 15:44:53 +01:00
|
|
|
->findAllByColumn('id');
|
|
|
|
}
|
2016-08-19 03:44:36 +02:00
|
|
|
|
2016-12-26 15:44:53 +01:00
|
|
|
function set_flag($user_id, $item_id, $value)
|
|
|
|
{
|
2016-08-19 03:44:36 +02:00
|
|
|
return Database::getInstance('db')
|
2016-12-26 15:44:53 +01:00
|
|
|
->table(Model\Item\TABLE)
|
|
|
|
->eq('user_id', $user_id)
|
|
|
|
->eq('id', $item_id)
|
|
|
|
->update(array('bookmark' => (int) $value));
|
2016-08-19 03:44:36 +02:00
|
|
|
}
|