From 6a78b6bde4cba50bfbd9d32c4b47cdc1ad1dc2ed Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Sun, 14 Feb 2010 18:45:39 +0100 Subject: [PATCH] - LSsearch : - Added formIsSubmited() method and use it in setParamsFormPostData() method - Added redirectWhenOnlyOneResult() method - View : - Used LSsearch::redirectWhenOnlyOneResult() to redirect the user on object view page when the search return only on result --- public_html/includes/class/class.LSsearch.php | 23 ++++++++++++++++++- public_html/view.php | 3 +++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/public_html/includes/class/class.LSsearch.php b/public_html/includes/class/class.LSsearch.php index e575a25e..8f8703df 100644 --- a/public_html/includes/class/class.LSsearch.php +++ b/public_html/includes/class/class.LSsearch.php @@ -495,6 +495,15 @@ class LSsearch { return $OK; } + /** + * Return true only if the form is submited + * + * @retval boolean True only if the is submited + **/ + private function formIsSubmited() { + return isset($_REQUEST['LSsearch_submit']); + } + /** * Define search parameters by reading Post Data ($_REQUEST) * @@ -503,7 +512,7 @@ class LSsearch { public function setParamsFormPostData() { $data = $_REQUEST; - if (isset($data['LSsearch_submit'])) { + if (self::formIsSubmited()) { // Recursive if (is_null($data['recursive'])) { $data['recursive']=false; @@ -1019,6 +1028,18 @@ class LSsearch { $this -> addResultToCache(); } + /** + * Redirect user to object view if the search have only one result + * + * @retval boolean True only if user have been redirected + **/ + function redirectWhenOnlyOneResult() { + if ($this -> total == 1 && $this -> result && self::formIsSubmited()) { + LSsession :: redirect('view.php?LSobject='.$this -> LSobject.'&dn='.$this -> result['list'][0]['dn']); + } + return; + } + /** * Run the sort if it's enabled and if the result is not in the cache * diff --git a/public_html/view.php b/public_html/view.php index 0d06d32d..97d4559d 100644 --- a/public_html/view.php +++ b/public_html/view.php @@ -137,6 +137,9 @@ if(LSsession :: startLSsession()) { $GLOBALS['Smarty']->assign('LSview_actions',$LSview_actions); $LSsearch -> run(); + + $LSsearch -> redirectWhenOnlyOneResult(); + $page=(int)$_REQUEST['page']; $page = $LSsearch -> getPage($page); $GLOBALS['Smarty']->assign('page',$page);