Browse Source

Added oldestArticle and latestArticle context options

microsub
J. King 7 years ago
parent
commit
2037efce61
  1. 8
      lib/Database.php
  2. 10
      lib/Misc/Context.php
  3. 2
      tests/Misc/TestContext.php
  4. 3
      tests/lib/Database/SeriesArticle.php

8
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);
}

10
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);
}

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

3
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"));

Loading…
Cancel
Save