Skip to content

Commit 58903f7

Browse files
committed
Merge branch 'latest-flag'
2 parents 25609b9 + eff6062 commit 58903f7

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

meta/Search.php

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ class Search
5959
/** @var array the revisions of the result rows */
6060
protected $result_revs = [];
6161

62+
/** @var bool Include latest = 1 in select query */
63+
protected $selectLatest = true;
64+
6265
/**
6366
* Search constructor.
6467
*/
@@ -311,6 +314,16 @@ public function setLimit($limit)
311314
}
312315
}
313316

317+
/**
318+
* Allows disabling default 'latest = 1' clause in select statement
319+
*
320+
* @param bool $selectLatest
321+
*/
322+
public function setSelectLatest($selectLatest): void
323+
{
324+
$this->selectLatest = $selectLatest;
325+
}
326+
314327
/**
315328
* Return the number of results (regardless of limit and offset settings)
316329
*
@@ -475,8 +488,8 @@ public function getSQL()
475488

476489
$first_table = $datatable;
477490
}
478-
// phpcs:ignore
479-
$QB->filters()->whereAnd("( (IS_PUBLISHER($datatable.pid) AND $datatable.latest = 1) OR (IS_PUBLISHER($datatable.pid) !=1 AND $datatable.published = 1) )");
491+
492+
$QB->filters()->whereAnd($this->getSpecialFlagsClause($datatable));
480493
}
481494

482495
// columns to select, handling multis
@@ -700,4 +713,19 @@ protected function isEmptyValue(Value $value)
700713
if ($value->getColumn()->getTid() == 0) return true;
701714
return false;
702715
}
716+
717+
/**
718+
* @param string $datatable
719+
* @return string
720+
*/
721+
protected function getSpecialFlagsClause($datatable)
722+
{
723+
$latestClause = "IS_PUBLISHER($datatable.pid)";
724+
if ($this->selectLatest) {
725+
$latestClause .= " AND $datatable.latest = 1";
726+
}
727+
$publishedClause = "IS_PUBLISHER($datatable.pid) !=1 AND $datatable.published = 1";
728+
729+
return "( ($latestClause) OR ($publishedClause) )";
730+
}
703731
}

0 commit comments

Comments
 (0)