From f24f57443099517651e87dae129d9cabf8b8074e Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Tue, 30 Sep 2014 14:46:36 +0200 Subject: [PATCH] LSattr_html :: select_list : Add sort feature (with sort and sortDirection parameters) --- .../LSattr_html_select_list.docbook | 25 ++++++++++++++--- .../class/class.LSattr_html_select_list.php | 27 ++++++++++++++++++- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/doc/conf/LSattribute/LSattr_html/LSattr_html_select_list.docbook b/doc/conf/LSattribute/LSattr_html/LSattr_html_select_list.docbook index e03f2a6b..4b4dab85 100644 --- a/doc/conf/LSattribute/LSattr_html/LSattr_html_select_list.docbook +++ b/doc/conf/LSattribute/LSattr_html/LSattr_html_select_list.docbook @@ -20,7 +20,9 @@ 'scope' => '[Scope de la recherche]', 'basedn' => '[Basedn de la recherche]' ) - ) + ), + 'sort' => [Booléen], + 'sortDirection' => '[ASC|DESC]' ),]]> ... @@ -104,6 +106,23 @@ - - + + + + sort + + Booléen définissant si les valeurs possibles doivent être + triées ou non (Vrai par défaut). Le trie est effectué sur les libellés + des valeurs possibles. + + + + + + sortDirection + + Mot clé déterminant le sens du trie des valeurs possibles. + Valeurs possibles : ASC ou DESC (ASC par défaut). + + diff --git a/public_html/includes/class/class.LSattr_html_select_list.php b/public_html/includes/class/class.LSattr_html_select_list.php index 7bfeaae5..eaf275ca 100644 --- a/public_html/includes/class/class.LSattr_html_select_list.php +++ b/public_html/includes/class/class.LSattr_html_select_list.php @@ -122,9 +122,34 @@ class LSattr_html_select_list extends LSattr_html{ } } } + + if (!isset($this -> config['html_options']['sort']) || $this -> config['html_options']['sort']) { + uasort($retInfos,array($this,'_sortTwoValues')); + } + return $retInfos; } - + + /** + * Function use with uasort to sort two values + * + * @param[in] $va string One value + * @param[in] $vb string One value + * + * @retval int Value for uasort + **/ + private function _sortTwoValues(&$va,&$vb) { + if (isset($this -> config['html_options']['sortDirection']) && $this -> config['html_options']['sortDirection']=='DESC') { + $dir=-1; + } + else { + $dir=1; + } + if ($va == $vb) return 0; + $val = strcoll(strtolower($va), strtolower($vb)); + return $val*$dir; + } + } /*