Fixed: Pinned bookmarks are displayed first in ATOM/RSS feeds
Fixes #1485
This commit is contained in:
parent
bea062149e
commit
a8e210faa6
5 changed files with 31 additions and 14 deletions
|
@ -234,16 +234,17 @@ public function getByUrl($url)
|
|||
*
|
||||
* Also update the urls and ids mapping arrays.
|
||||
*
|
||||
* @param string $order ASC|DESC
|
||||
* @param string $order ASC|DESC
|
||||
* @param bool $ignoreSticky If set to true, sticky bookmarks won't be first
|
||||
*/
|
||||
public function reorder($order = 'DESC')
|
||||
public function reorder(string $order = 'DESC', bool $ignoreSticky = false): void
|
||||
{
|
||||
$order = $order === 'ASC' ? -1 : 1;
|
||||
// Reorder array by dates.
|
||||
usort($this->bookmarks, function ($a, $b) use ($order) {
|
||||
usort($this->bookmarks, function ($a, $b) use ($order, $ignoreSticky) {
|
||||
/** @var $a Bookmark */
|
||||
/** @var $b Bookmark */
|
||||
if ($a->isSticky() !== $b->isSticky()) {
|
||||
if (false === $ignoreSticky && $a->isSticky() !== $b->isSticky()) {
|
||||
return $a->isSticky() ? -1 : 1;
|
||||
}
|
||||
return $a->getCreated() < $b->getCreated() ? 1 * $order : -1 * $order;
|
||||
|
|
|
@ -114,8 +114,13 @@ public function findByUrl($url)
|
|||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function search($request = [], $visibility = null, $caseSensitive = false, $untaggedOnly = false)
|
||||
{
|
||||
public function search(
|
||||
$request = [],
|
||||
$visibility = null,
|
||||
$caseSensitive = false,
|
||||
$untaggedOnly = false,
|
||||
bool $ignoreSticky = false
|
||||
) {
|
||||
if ($visibility === null) {
|
||||
$visibility = $this->isLoggedIn ? BookmarkFilter::$ALL : BookmarkFilter::$PUBLIC;
|
||||
}
|
||||
|
@ -124,6 +129,10 @@ public function search($request = [], $visibility = null, $caseSensitive = false
|
|||
$searchtags = isset($request['searchtags']) ? $request['searchtags'] : '';
|
||||
$searchterm = isset($request['searchterm']) ? $request['searchterm'] : '';
|
||||
|
||||
if ($ignoreSticky) {
|
||||
$this->bookmarks->reorder('DESC', true);
|
||||
}
|
||||
|
||||
return $this->bookmarkFilter->filter(
|
||||
BookmarkFilter::$FILTER_TAG | BookmarkFilter::$FILTER_TEXT,
|
||||
[$searchtags, $searchterm],
|
||||
|
|
|
@ -49,10 +49,17 @@ public function findByUrl($url);
|
|||
* @param string $visibility
|
||||
* @param bool $caseSensitive
|
||||
* @param bool $untaggedOnly
|
||||
* @param bool $ignoreSticky
|
||||
*
|
||||
* @return Bookmark[]
|
||||
*/
|
||||
public function search($request = [], $visibility = null, $caseSensitive = false, $untaggedOnly = false);
|
||||
public function search(
|
||||
$request = [],
|
||||
$visibility = null,
|
||||
$caseSensitive = false,
|
||||
$untaggedOnly = false,
|
||||
bool $ignoreSticky = false
|
||||
);
|
||||
|
||||
/**
|
||||
* Get a single bookmark by its ID.
|
||||
|
|
|
@ -102,7 +102,7 @@ public function buildData(string $feedType, ?array $userInput)
|
|||
}
|
||||
|
||||
// Optionally filter the results:
|
||||
$linksToDisplay = $this->linkDB->search($userInput);
|
||||
$linksToDisplay = $this->linkDB->search($userInput, null, false, false, true);
|
||||
|
||||
$nblinksToDisplay = $this->getNbLinks(count($linksToDisplay), $userInput);
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ public function testRSSBuildData()
|
|||
$this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links']));
|
||||
|
||||
// Test first not pinned link (note link)
|
||||
$link = $data['links'][array_keys($data['links'])[2]];
|
||||
$link = $data['links'][array_keys($data['links'])[0]];
|
||||
$this->assertEquals(41, $link['id']);
|
||||
$this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']);
|
||||
$this->assertEquals('http://host.tld/shaare/WDWyig', $link['guid']);
|
||||
|
@ -128,7 +128,7 @@ public function testAtomBuildData()
|
|||
$data = $feedBuilder->buildData(FeedBuilder::$FEED_ATOM, null);
|
||||
$this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links']));
|
||||
$this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['last_update']);
|
||||
$link = $data['links'][array_keys($data['links'])[2]];
|
||||
$link = $data['links'][array_keys($data['links'])[0]];
|
||||
$this->assertRegExp('/2015-03-10T11:46:51\+\d{2}:\d{2}/', $link['pub_iso_date']);
|
||||
$this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['links'][8]['up_iso_date']);
|
||||
}
|
||||
|
@ -173,7 +173,7 @@ public function testBuildDataCount()
|
|||
$feedBuilder->setLocale(self::$LOCALE);
|
||||
$data = $feedBuilder->buildData(FeedBuilder::$FEED_ATOM, $criteria);
|
||||
$this->assertEquals(3, count($data['links']));
|
||||
$link = $data['links'][array_keys($data['links'])[2]];
|
||||
$link = $data['links'][array_keys($data['links'])[0]];
|
||||
$this->assertEquals(41, $link['id']);
|
||||
$this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']);
|
||||
}
|
||||
|
@ -195,7 +195,7 @@ public function testBuildDataPermalinks()
|
|||
$this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links']));
|
||||
$this->assertTrue($data['usepermalinks']);
|
||||
// First link is a permalink
|
||||
$link = $data['links'][array_keys($data['links'])[2]];
|
||||
$link = $data['links'][array_keys($data['links'])[0]];
|
||||
$this->assertEquals(41, $link['id']);
|
||||
$this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']);
|
||||
$this->assertEquals('http://host.tld/shaare/WDWyig', $link['guid']);
|
||||
|
@ -203,7 +203,7 @@ public function testBuildDataPermalinks()
|
|||
$this->assertContains('Direct link', $link['description']);
|
||||
$this->assertContains('http://host.tld/shaare/WDWyig', $link['description']);
|
||||
// Second link is a direct link
|
||||
$link = $data['links'][array_keys($data['links'])[3]];
|
||||
$link = $data['links'][array_keys($data['links'])[1]];
|
||||
$this->assertEquals(8, $link['id']);
|
||||
$this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114633'), $link['created']);
|
||||
$this->assertEquals('http://host.tld/shaare/RttfEw', $link['guid']);
|
||||
|
@ -270,7 +270,7 @@ public function testBuildDataServerSubdir()
|
|||
);
|
||||
|
||||
// Test first link (note link)
|
||||
$link = $data['links'][array_keys($data['links'])[2]];
|
||||
$link = $data['links'][array_keys($data['links'])[0]];
|
||||
$this->assertEquals('http://host.tld:8080/~user/shaarli/shaare/WDWyig', $link['guid']);
|
||||
$this->assertEquals('http://host.tld:8080/~user/shaarli/shaare/WDWyig', $link['url']);
|
||||
$this->assertContains('http://host.tld:8080/~user/shaarli/./add-tag/hashtag', $link['description']);
|
||||
|
|
Loading…
Reference in a new issue