LSattr_html :: select_list : Add sort feature (with sort and sortDirection parameters)

This commit is contained in:
Benjamin Renard 2014-09-30 14:46:36 +02:00
parent 4d40bba83d
commit f24f574430
2 changed files with 48 additions and 4 deletions

View file

@ -20,7 +20,9 @@
'scope' => '[Scope de la recherche]', 'scope' => '[Scope de la recherche]',
'basedn' => '[Basedn de la recherche]' 'basedn' => '[Basedn de la recherche]'
) )
) ),
'sort' => [Booléen],
'sortDirection' => '[ASC|DESC]'
),]]> ),]]>
... ...
</programlisting> </programlisting>
@ -104,6 +106,23 @@
</varlistentry> </varlistentry>
</variablelist> </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> </sect4>

View file

@ -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; 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;
}
} }
/* /*