diff --git a/lib/Database.php b/lib/Database.php index e23cfe6c..8c1674d7 100644 --- a/lib/Database.php +++ b/lib/Database.php @@ -1650,9 +1650,12 @@ class Database { // handle the simple context options $options = [ // each context array consists of a column identifier (see $colDefs above), a comparison operator, and a data type; the "between" operator has special handling + "edition" => ["edition", "=", "int"], + "editions" => ["edition", "in", "int"], "article" => ["id", "=", "int"], "articles" => ["id", "in", "int"], "articleRange" => ["id", "between", "int"], + "editionRange" => ["edition", "between", "int"], "modifiedRange" => ["modified_date", "between", "datetime"], "markedRange" => ["marked_date", "between", "datetime"], "folderShallow" => ["folder", "=", "int"], @@ -1808,45 +1811,6 @@ class Database { } } } - // handle edition-related selections - if ($context->edition()) { - $q->setWhere("{$colDefs['id']} = (select article from arsse_editions where id = ?)", "int", $context->edition); - } - if ($context->not->edition()) { - $q->setWhereNot("{$colDefs['id']} = (select article from arsse_editions where id = ?)", "int", $context->not->edition); - } - if ($context->editions()) { - [$inClause, $inTypes, $inValues] = $this->generateIn($context->editions, "int"); - $q->setWhere("{$colDefs['id']} in (select article from arsse_editions where id in ($inClause))", $inTypes, $inValues); - } - if ($context->not->editions()) { - [$inClause, $inTypes, $inValues] = $this->generateIn($context->not->editions, "int"); - $q->setWhereNot("{$colDefs['id']} in (select article from arsse_editions where id in ($inClause))", $inTypes, $inValues); - } - if ($context->editionRange()) { - if ($context->editionRange[0] === null) { - // range is open at the low end - $q->setWhere("{$colDefs['id']} in (select article from arsse_editions where id <= ?)", "int", $context->editionRange[1]); - } elseif ($context->editionRange[1] === null) { - // range is open at the high end - $q->setWhere("{$colDefs['id']} in (select article from arsse_editions where id >= ?)", "int", $context->editionRange[0]); - } else { - // range is bounded in both directions - $q->setWhere("{$colDefs['id']} in (select article from arsse_editions where id between ? and ?)", ["int", "int"], $context->editionRange); - } - } - if ($context->not->editionRange()) { - if ($context->not->editionRange[0] === null) { - // range is open at the low end - $q->setWhereNot("{$colDefs['id']} in (select article from arsse_editions where id <= ?)", "int", $context->not->editionRange[1]); - } elseif ($context->not->editionRange[1] === null) { - // range is open at the high end - $q->setWhereNot("{$colDefs['id']} in (select article from arsse_editions where id >= ?)", "int", $context->not->editionRange[0]); - } else { - // range is bounded in both directions - $q->setWhereNot("{$colDefs['id']} in (select article from arsse_editions where id between ? and ?)", ["int", "int"], $context->not->editionRange); - } - } return $q; } diff --git a/tests/cases/Database/SeriesArticle.php b/tests/cases/Database/SeriesArticle.php index c507cded..ed386175 100644 --- a/tests/cases/Database/SeriesArticle.php +++ b/tests/cases/Database/SeriesArticle.php @@ -411,7 +411,7 @@ trait SeriesArticle { 'Not hidden' => [(new Context)->hidden(false), [1,2,3,4,5,7,8,19,20]], 'Labelled' => [(new Context)->labelled(true), [1,5,8,19,20]], 'Not labelled' => [(new Context)->labelled(false), [2,3,4,6,7]], - 'Not after edition 999' => [(new Context)->subscription(5)->editionRange(null, 999), [19, 20]], + 'Not after edition 999' => [(new Context)->subscription(5)->editionRange(null, 999), [19]], 'Not after edition 19' => [(new Context)->subscription(5)->editionRange(null, 19), [19]], 'Not before edition 999' => [(new Context)->subscription(5)->editionRange(999, null), [20]], 'Not before edition 1001' => [(new Context)->subscription(5)->editionRange(1001, null), [20]], @@ -435,7 +435,7 @@ trait SeriesArticle { 'With label "Fascinating"' => [(new Context)->labelName("Fascinating"), [1,5,20]], 'With label "Interesting" or "Fascinating"' => [(new Context)->labelNames(["Interesting","Fascinating"]), [1,5,19,20]], 'Article ID 20' => [(new Context)->article(20), [20]], - 'Edition ID 20' => [(new Context)->edition(20), [20]], + 'Edition ID 20' => [(new Context)->edition(20), []], 'Edition ID 1001' => [(new Context)->edition(1001), [20]], 'Multiple articles' => [(new Context)->articles([1,20,50]), [1,20]], 'Multiple starred articles' => [(new Context)->articles([1,2,3])->starred(true), [1]],