*
* 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;
/**
* @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;
}
$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],
$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']);
$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']);
}
$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']);
}
$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']);
$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']);
);
// 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']);