diff --git a/lib/Database.php b/lib/Database.php index 00cd3ca0..1ed8793a 100644 --- a/lib/Database.php +++ b/lib/Database.php @@ -917,7 +917,13 @@ class Database { } $q->setWhere("exists(select article from arsse_label_members where assigned is 1 and article is arsse_articles.id and label is ?)", "int", $id); } - // filter based on edition offset + // filter based on article or edition offset + if ($context->oldestArticle()) { + $q->setWhere("arsse_articles.id >= ?", "int", $context->oldestArticle); + } + if ($context->latestArticle()) { + $q->setWhere("arsse_articles.id <= ?", "int", $context->latestArticle); + } if ($context->oldestEdition()) { $q->setWhere("edition >= ?", "int", $context->oldestEdition); } diff --git a/lib/Misc/Context.php b/lib/Misc/Context.php index b36a032a..4ae64e1f 100644 --- a/lib/Misc/Context.php +++ b/lib/Misc/Context.php @@ -16,6 +16,8 @@ class Context { public $folder; public $folderShallow; public $subscription; + public $oldestArticle; + public $latestArticle; public $oldestEdition; public $latestEdition; public $unread = null; @@ -81,6 +83,14 @@ class Context { return $this->act(__FUNCTION__, func_num_args(), $spec); } + public function latestArticle(int $spec = null) { + return $this->act(__FUNCTION__, func_num_args(), $spec); + } + + public function oldestArticle(int $spec = null) { + return $this->act(__FUNCTION__, func_num_args(), $spec); + } + public function latestEdition(int $spec = null) { return $this->act(__FUNCTION__, func_num_args(), $spec); } diff --git a/tests/Misc/TestContext.php b/tests/Misc/TestContext.php index 13f11b78..4f9b3300 100644 --- a/tests/Misc/TestContext.php +++ b/tests/Misc/TestContext.php @@ -32,6 +32,8 @@ class TestContext extends Test\AbstractTest { 'subscription' => 2112, 'article' => 255, 'edition' => 65535, + 'latestArticle' => 47, + 'oldestArticle' => 1337, 'latestEdition' => 47, 'oldestEdition' => 1337, 'unread' => true, diff --git a/tests/lib/Database/SeriesArticle.php b/tests/lib/Database/SeriesArticle.php index 9fcbbbf8..c474a672 100644 --- a/tests/lib/Database/SeriesArticle.php +++ b/tests/lib/Database/SeriesArticle.php @@ -411,6 +411,9 @@ trait SeriesArticle { $this->compareIds([19], (new Context)->subscription(5)->latestEdition(19)); $this->compareIds([20], (new Context)->subscription(5)->oldestEdition(999)); $this->compareIds([20], (new Context)->subscription(5)->oldestEdition(1001)); + // get items relative to article ID + $this->compareIds([1,2,3], (new Context)->latestArticle(3)); + $this->compareIds([19,20], (new Context)->oldestArticle(19)); // get items relative to (feed) modification date $exp = [2,4,6,8,20]; $this->compareIds($exp, (new Context)->modifiedSince("2005-01-01T00:00:00Z"));