mirror of
https://gitlab.easter-eggs.com/ee/ldapsaisie.git
synced 2024-12-24 01:13:51 +01:00
LSattr_html :: select_list : Add sort feature (with sort and sortDirection parameters)
This commit is contained in:
parent
4d40bba83d
commit
f24f574430
2 changed files with 48 additions and 4 deletions
|
@ -20,7 +20,9 @@
|
|||
'scope' => '[Scope de la recherche]',
|
||||
'basedn' => '[Basedn de la recherche]'
|
||||
)
|
||||
)
|
||||
),
|
||||
'sort' => [Booléen],
|
||||
'sortDirection' => '[ASC|DESC]'
|
||||
),]]>
|
||||
...
|
||||
</programlisting>
|
||||
|
@ -104,6 +106,23 @@
|
|||
</varlistentry>
|
||||
|
||||
</variablelist>
|
||||
|
||||
|
||||
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term>sort</term>
|
||||
<listitem>
|
||||
<simpara>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.</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
|
||||
<varlistentry>
|
||||
<term>sortDirection</term>
|
||||
<listitem>
|
||||
<simpara>Mot clé déterminant le sens du trie des valeurs possibles.</simpara>
|
||||
<simpara>Valeurs possibles : <literal>ASC</literal> ou <literal>DESC</literal> (<literal>ASC</literal> par défaut).</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</sect4>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in a new issue