Skip to content

Commit

Permalink
Honor sortby/sortdir prefs in Tagsearch block.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrubinsk committed Dec 11, 2014
1 parent b09c3f0 commit e687d5f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions trean/lib/Block/Tagsearch.php
Expand Up @@ -61,7 +61,7 @@ protected function _title()
*/
protected function _content()
{
global $trean_gateway, $registry, $injector;
global $trean_gateway, $registry, $injector, $prefs;

$template = TREAN_TEMPLATES . '/block/' . $this->_params['template'] . '.inc';

Expand All @@ -73,7 +73,7 @@ protected function _content()
$ids = array();
}

$bookmarks = $trean_gateway->getBookmarks($ids);
$bookmarks = $trean_gateway->getBookmarks($ids, array('sortby' => $prefs->getValue('sortby'), 'sortdir' => $prefs->getValue('sortdir')));
foreach ($bookmarks as $bookmark) {
ob_start();
require $template;
Expand Down
18 changes: 13 additions & 5 deletions trean/lib/Bookmarks.php
Expand Up @@ -184,18 +184,26 @@ public function getBookmark($id)
* Returns the bookmarks corresponding to the given ids.
*
* @param array $id An array of integer IDs of the bookmarks to retrieve.
* @param array $options An array of options:
* - sortby: (string) The field to sort by.
* DEFAULT: No sorting is done.
* - sortdir: (integer) The direction to sort, if sorting.
*
* @return array An array of Trean_Bookmark objects.
* @throws Trean_Exception
* @since 1.2.0
*/
public function getBookmarks(array $ids)
public function getBookmarks(array $ids, array $options = array())
{
try {
$bookmarks = $GLOBALS['trean_db']->selectAll('
SELECT bookmark_id, user_id, bookmark_url, bookmark_title, bookmark_description, bookmark_clicks, bookmark_http_status, favicon_url, bookmark_dt
$sql = 'SELECT bookmark_id, user_id, bookmark_url, bookmark_title, bookmark_description, bookmark_clicks, bookmark_http_status, favicon_url, bookmark_dt
FROM trean_bookmarks
WHERE bookmark_id IN (' . implode(',', $ids) . ')');
WHERE bookmark_id IN (' . implode(',', $ids) . ')';
if (!empty($options['sortby'])) {
$sql .= ' ORDER BY bookmark_' . $options['sortby'] . ($options['sortdir'] ? ' DESC' : '');
}

try {
$bookmarks = $GLOBALS['trean_db']->selectAll($sql);
} catch (Horde_Db_Exception $e) {
throw new Trean_Exception($e);
}
Expand Down

0 comments on commit e687d5f

Please sign in to comment.