Create ItemGroup model

This commit is contained in:
Frederic Guillot 2016-08-18 22:08:29 -04:00
parent 34ef7b95b9
commit 309ccf0a32
No known key found for this signature in database
GPG Key ID: 92D77191BA7FBC99
8 changed files with 34 additions and 29 deletions

View File

@ -60,7 +60,7 @@ Router\get_action('flush-history', function () {
$group_id = Request\int_param('group_id', null);
if ($group_id !== null) {
Model\Item\mark_group_as_removed($group_id);
Model\ItemGroup\mark_all_as_removed($group_id);
} else {
Model\Item\mark_all_as_removed();
}

View File

@ -161,7 +161,7 @@ Router\get_action('mark-all-read', function () {
$group_id = Request\int_param('group_id', null);
if ($group_id !== null) {
Model\Item\mark_group_as_read($group_id);
Model\ItemGroup\mark_all_as_read($group_id);
} else {
Model\Item\mark_all_as_read();
}

View File

@ -47,7 +47,6 @@ function get_all_items($offset = null, $limit = null, $feed_ids = array())
->findAll();
}
// Enable/disable bookmark flag
function set_flag($id, $value)
{
if ($value == 1) {

View File

@ -297,32 +297,6 @@ function mark_all_as_removed()
->save(array('status' => 'removed', 'content' => ''));
}
// Mark all items of a group as read
function mark_group_as_read($group_id)
{
// workaround for missing update with join
$feed_ids = Group\get_feeds_by_group($group_id);
return Database::getInstance('db')
->table('items')
->eq('status', 'unread')
->in('feed_id', $feed_ids)
->update(array('status' => 'read'));
}
// Mark all items of a group as removed
function mark_group_as_removed($group_id)
{
$feed_ids = Group\get_feeds_by_group($group_id);
return Database::getInstance('db')
->table('items')
->eq('status', 'read')
->eq('bookmark', 0)
->in('feed_id', $feed_ids)
->save(array('status' => 'removed', 'content' => ''));
}
// Mark all read items to removed after X days
function autoflush_read()
{

29
app/models/item_group.php Normal file
View File

@ -0,0 +1,29 @@
<?php
namespace Model\ItemGroup;
use PicoDb\Database;
use Model\Group;
function mark_all_as_read($group_id)
{
$feed_ids = Group\get_feeds_by_group($group_id);
return Database::getInstance('db')
->table('items')
->eq('status', 'unread')
->in('feed_id', $feed_ids)
->update(array('status' => 'read'));
}
function mark_all_as_removed($group_id)
{
$feed_ids = Group\get_feeds_by_group($group_id);
return Database::getInstance('db')
->table('items')
->eq('status', 'read')
->eq('bookmark', 0)
->in('feed_id', $feed_ids)
->save(array('status' => 'removed', 'content' => ''));
}

View File

@ -44,6 +44,7 @@
"app/models/feed.php",
"app/models/item.php",
"app/models/item_feed.php",
"app/models/item_group.php",
"app/models/bookmark.php",
"app/models/proxy.php",
"app/models/auto_update.php",

View File

@ -25,6 +25,7 @@ return array(
'e8bcd5701df9db676003b87e27b091c9' => $baseDir . '/app/models/feed.php',
'7318478c1ab18cc398507355a29a93c3' => $baseDir . '/app/models/item.php',
'c0f7d31e45ab3b885f3f3567be6b8cda' => $baseDir . '/app/models/item_feed.php',
'c9e2906d32a129f63c98d210037c227b' => $baseDir . '/app/models/item_group.php',
'546998ee103e300ad614144f30a1de8e' => $baseDir . '/app/models/bookmark.php',
'0bdc342df97b8a477df96dbb288b21bf' => $baseDir . '/app/models/proxy.php',
'd06207bd4580f7e9250cf39d0d648fc5' => $baseDir . '/app/models/auto_update.php',

View File

@ -26,6 +26,7 @@ class ComposerStaticInitfd7e8d436e1dc450edc3153ac8bc31b4
'e8bcd5701df9db676003b87e27b091c9' => __DIR__ . '/../..' . '/app/models/feed.php',
'7318478c1ab18cc398507355a29a93c3' => __DIR__ . '/../..' . '/app/models/item.php',
'c0f7d31e45ab3b885f3f3567be6b8cda' => __DIR__ . '/../..' . '/app/models/item_feed.php',
'c9e2906d32a129f63c98d210037c227b' => __DIR__ . '/../..' . '/app/models/item_group.php',
'546998ee103e300ad614144f30a1de8e' => __DIR__ . '/../..' . '/app/models/bookmark.php',
'0bdc342df97b8a477df96dbb288b21bf' => __DIR__ . '/../..' . '/app/models/proxy.php',
'd06207bd4580f7e9250cf39d0d648fc5' => __DIR__ . '/../..' . '/app/models/auto_update.php',