From 6b60741600321e4a2c414e91595b09d35516a3ea Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 16 Feb 2015 00:43:18 +0100 Subject: alternative random function to fix #1082 --- inc/poche/Poche.class.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'inc/poche/Poche.class.php') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 6d4ce137..4b85d52f 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -393,13 +393,12 @@ 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': - $id = 0; - while ($this->store->retrieveOneById($id,$this->user->getId()) == null) { - $count = $this->store->getEntriesByViewCount($view, $this->user->getId()); - $id = rand(1,$count); - } + $count = $this->store->getEntriesByViewCount($view, $this->user->getId()); + $id_query = $this->store->getRandomId(rand(1,$count)-1, $this->user->getId()); + $id = $id_query[0]; Tools::logm('get a random article'); - Tools::redirect('?view=view&id=' . $id); + Tools::redirect('?view=view&id=' . $id[0]); + //$this->displayView('view', $id); break; default: -- cgit v1.2.3