Create ItemFeed model

This commit is contained in:
Frederic Guillot 2016-08-18 21:53:59 -04:00
parent 321f8a71f8
commit 34ef7b95b9
No known key found for this signature in database
GPG Key ID: 92D77191BA7FBC99
7 changed files with 61 additions and 56 deletions

View File

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

View File

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

52
app/models/item_feed.php Normal file
View File

@ -0,0 +1,52 @@
<?php
namespace Model\ItemFeed;
use PicoDb\Database;
function count_items($feed_id)
{
return Database::getInstance('db')
->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'));
}

View File

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

View File

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

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

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