1
0
mirror of https://github.com/flarum/core.git synced 2025-08-08 17:36:38 +02:00

Only pin to top if viewing a tag with no other filters

This commit is contained in:
Toby Zerner
2018-01-11 12:28:35 +10:30
parent b58f97fd5e
commit 8bfaff339e

View File

@@ -49,24 +49,23 @@ class PinStickiedDiscussionsToTop
// discussions to the top no matter what. // discussions to the top no matter what.
$gambits = $search->getActiveGambits(); $gambits = $search->getActiveGambits();
foreach ($gambits as $gambit) { if ($count = count($gambits)) {
if ($gambit instanceof TagGambit) { if ($count === 1 && $gambits[0] instanceof TagGambit) {
if (! is_array($query->orders)) { if (! is_array($query->orders)) {
$query->orders = []; $query->orders = [];
} }
array_unshift($query->orders, ['column' => 'is_sticky', 'direction' => 'desc']); array_unshift($query->orders, ['column' => 'is_sticky', 'direction' => 'desc']);
}
return; return;
} }
}
// Otherwise, if we are viewing "all discussions", only pin stickied // Otherwise, if we are viewing "all discussions", only pin stickied
// discussions to the top if they are unread. To do this in a // discussions to the top if they are unread. To do this in a
// performant way we create another query which will select all // performant way we create another query which will select all
// stickied discussions, marry them into the main query, and then // stickied discussions, marry them into the main query, and then
// reorder the unread ones up to the top. // reorder the unread ones up to the top.
if (empty($gambits)) {
$sticky = clone $query; $sticky = clone $query;
$sticky->where('is_sticky', true); $sticky->where('is_sticky', true);
$sticky->orders = null; $sticky->orders = null;
@@ -94,5 +93,4 @@ class PinStickiedDiscussionsToTop
$query->offset = $sticky->offset = null; $query->offset = $sticky->offset = null;
} }
} }
}
} }