aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/utils/ReferenceLinkDB.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2018-05-22 22:44:38 +0200
committerArthurHoaro <arthur@hoa.ro>2018-10-06 12:55:05 +0200
commit4154c25b5f2f8044a37d7f84e04173bb54f2375b (patch)
treee7f61835072a54eee8590286496bdbbbef0e4a37 /tests/utils/ReferenceLinkDB.php
parent10a7b5cee96a742fbe86edbea977f3c55c92e9aa (diff)
downloadShaarli-4154c25b5f2f8044a37d7f84e04173bb54f2375b.tar.gz
Shaarli-4154c25b5f2f8044a37d7f84e04173bb54f2375b.tar.zst
Shaarli-4154c25b5f2f8044a37d7f84e04173bb54f2375b.zip
Add a button to set links as sticky
Meaning that they always appear on top of all links Fixes #186
Diffstat (limited to 'tests/utils/ReferenceLinkDB.php')
-rw-r--r--tests/utils/ReferenceLinkDB.php45
1 files changed, 43 insertions, 2 deletions
diff --git a/tests/utils/ReferenceLinkDB.php b/tests/utils/ReferenceLinkDB.php
index e887aa78..7426ad07 100644
--- a/tests/utils/ReferenceLinkDB.php
+++ b/tests/utils/ReferenceLinkDB.php
@@ -4,7 +4,7 @@
4 */ 4 */
5class ReferenceLinkDB 5class ReferenceLinkDB
6{ 6{
7 public static $NB_LINKS_TOTAL = 9; 7 public static $NB_LINKS_TOTAL = 11;
8 8
9 private $_links = array(); 9 private $_links = array();
10 private $_publicCount = 0; 10 private $_publicCount = 0;
@@ -16,6 +16,32 @@ class ReferenceLinkDB
16 public function __construct() 16 public function __construct()
17 { 17 {
18 $this->addLink( 18 $this->addLink(
19 11,
20 'Pined older',
21 '?PCRizQ',
22 'This is an older pinned link',
23 0,
24 DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20100309_101010'),
25 '',
26 null,
27 'PCRizQ',
28 true
29 );
30
31 $this->addLink(
32 10,
33 'Pined',
34 '?0gCTjQ',
35 'This is a pinned link',
36 0,
37 DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121207_152312'),
38 '',
39 null,
40 '0gCTjQ',
41 true
42 );
43
44 $this->addLink(
19 41, 45 41,
20 'Link title: @website', 46 'Link title: @website',
21 '?WDWyig', 47 '?WDWyig',
@@ -114,7 +140,17 @@ class ReferenceLinkDB
114 /** 140 /**
115 * Adds a new link 141 * Adds a new link
116 */ 142 */
117 protected function addLink($id, $title, $url, $description, $private, $date, $tags, $updated = '', $shorturl = '') 143 protected function addLink(
144 $id,
145 $title,
146 $url,
147 $description,
148 $private,
149 $date,
150 $tags,
151 $updated = '',
152 $shorturl = '',
153 $pinned = false)
118 { 154 {
119 $link = array( 155 $link = array(
120 'id' => $id, 156 'id' => $id,
@@ -126,6 +162,7 @@ class ReferenceLinkDB
126 'created' => $date, 162 'created' => $date,
127 'updated' => $updated, 163 'updated' => $updated,
128 'shorturl' => $shorturl ? $shorturl : smallHash($date->format(LinkDB::LINK_DATE_FORMAT) . $id), 164 'shorturl' => $shorturl ? $shorturl : smallHash($date->format(LinkDB::LINK_DATE_FORMAT) . $id),
165 'sticky' => $pinned
129 ); 166 );
130 $this->_links[$id] = $link; 167 $this->_links[$id] = $link;
131 168
@@ -165,6 +202,10 @@ class ReferenceLinkDB
165 $order = $order === 'ASC' ? -1 : 1; 202 $order = $order === 'ASC' ? -1 : 1;
166 // Reorder array by dates. 203 // Reorder array by dates.
167 usort($this->_links, function($a, $b) use ($order) { 204 usort($this->_links, function($a, $b) use ($order) {
205 if (isset($a['sticky']) && isset($b['sticky']) && $a['sticky'] !== $b['sticky']) {
206 return $a['sticky'] ? -1 : 1;
207 }
208
168 return $a['created'] < $b['created'] ? 1 * $order : -1 * $order; 209 return $a['created'] < $b['created'] ? 1 * $order : -1 * $order;
169 }); 210 });
170 } 211 }