mirror of
https://github.com/wallabag/wallabag.git
synced 2025-08-01 17:38:38 +00:00
fix for #1153, a couple of improvements and fixed bugs
This commit is contained in:
parent
ab87a7fe69
commit
f76dab12c9
3 changed files with 55 additions and 12 deletions
|
@ -411,10 +411,22 @@ class Database {
|
|||
|
||||
return $count;
|
||||
}
|
||||
public function getRandomId($user_id) {
|
||||
public function getRandomId($user_id, $view) {
|
||||
$random = (STORAGE == 'mysql') ? 'RAND()' : 'RANDOM()';
|
||||
$sql = "SELECT id FROM entries WHERE user_id=? ORDER BY ". $random . " LIMIT 1";
|
||||
$params = array($user_id);
|
||||
switch ($view) {
|
||||
case 'archive':
|
||||
$sql = "SELECT id FROM entries WHERE user_id=? AND is_read=? ORDER BY ". $random . " LIMIT 1";
|
||||
$params = array($user_id,1);
|
||||
break;
|
||||
case 'fav':
|
||||
$sql = "SELECT id FROM entries WHERE user_id=? AND is_fav=? ORDER BY ". $random . " LIMIT 1";
|
||||
$params = array($user_id,1);
|
||||
break;
|
||||
default:
|
||||
$sql = "SELECT id FROM entries WHERE user_id=? AND is_read=? ORDER BY ". $random . " LIMIT 1";
|
||||
$params = array($user_id,0);
|
||||
break;
|
||||
}
|
||||
$query = $this->executeQuery($sql, $params);
|
||||
$id = $query->fetchAll();
|
||||
|
||||
|
|
|
@ -406,8 +406,9 @@ class Poche
|
|||
/* For some unknown reason I can't get displayView() to work here (it redirects to home view afterwards). So here's a dirty fix which redirects directly to URL */
|
||||
case 'random':
|
||||
Tools::logm('get a random article');
|
||||
if ($this->store->getRandomId($this->user->getId())) {
|
||||
$id_array = $this->store->getRandomId($this->user->getId());
|
||||
$view = $_GET['view'];
|
||||
if ($this->store->getRandomId($this->user->getId(),$view)) {
|
||||
$id_array = $this->store->getRandomId($this->user->getId(),$view);
|
||||
$id = $id_array[0];
|
||||
Tools::redirect('?view=view&id=' . $id[0]);
|
||||
Tools::logm('got the article with id ' . $id[0]);
|
||||
|
@ -522,7 +523,7 @@ class Poche
|
|||
$this->pagination->page_links('?view=' . $view . '?search=' . $search . '&sort=' . $_SESSION['sort'] . '&' ));
|
||||
$tpl_vars['page_links'] = $page_links;
|
||||
$tpl_vars['nb_results'] = $count;
|
||||
$tpl_vars['searchterm'] = $search;
|
||||
$tpl_vars['search_term'] = $search;
|
||||
}
|
||||
break;
|
||||
case 'view':
|
||||
|
@ -578,6 +579,7 @@ class Poche
|
|||
'page_links' => '',
|
||||
'nb_results' => '',
|
||||
'listmode' => (isset($_COOKIE['listmode']) ? true : false),
|
||||
'view' => $view,
|
||||
);
|
||||
|
||||
//if id is given - we retrieve entries by tag: id is tag id
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue