mirror of
https://gitlab.easter-eggs.com/ee/ldapsaisie.git
synced 2024-11-22 09:59:06 +01:00
LSformElement :: select_object : Add sort feature (with sort and sortDirection parameters)
This commit is contained in:
parent
f24f574430
commit
04f2518d35
2 changed files with 45 additions and 7 deletions
|
@ -12,7 +12,9 @@
|
|||
'object_type' => '[Type d'LSobject selectionnable]',
|
||||
'display_name_format' => '[LSformat du nom d'affichage des LSobjects]',
|
||||
'value_attribute' => '[Nom de l'attribut clé des LSobjects]'
|
||||
)
|
||||
),
|
||||
'sort' => [Booléen],
|
||||
'sortDirection' => '[ASC|DESC]'
|
||||
),]]>
|
||||
...
|
||||
</programlisting>
|
||||
|
@ -35,18 +37,14 @@
|
|||
<simpara>Nom du type d'&LSobject; en référence.</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term>display_name_format</term>
|
||||
<listitem>
|
||||
<simpara>&LSformat; du nom d'affichage des objets lors de leur sélection.</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term>value_attribute</term>
|
||||
<listitem>
|
||||
|
@ -55,9 +53,7 @@
|
|||
<emphasis>uid</emphasis>).</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term>filter</term>
|
||||
<listitem>
|
||||
|
@ -70,6 +66,23 @@
|
|||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term>sort</term>
|
||||
<listitem>
|
||||
<simpara>Booléen définissant si la liste des objets choisis doit être
|
||||
triée ou non (Vrai par défaut). Le trie est effectué sur les libellés
|
||||
des objets choisis.</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term>sortDirection</term>
|
||||
<listitem>
|
||||
<simpara>Mot clé déterminant le sens du trie des objets choisis.</simpara>
|
||||
<simpara>Valeurs possibles : <literal>ASC</literal> ou <literal>DESC</literal> (<literal>ASC</literal> par défaut).</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
</variablelist>
|
||||
|
||||
|
||||
|
|
|
@ -89,6 +89,11 @@ class LSformElement_select_object extends LSformElement {
|
|||
LSselect :: loadDependenciesDisplay();
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($this -> params['html_options']['sort']) || $this -> params['html_options']['sort']) {
|
||||
uasort($this -> values,array($this,'_sortTwoValues'));
|
||||
}
|
||||
|
||||
$return['html'] = $this -> fetchTemplate(NULL,array(
|
||||
'selectableObject' => $this -> selectableObject,
|
||||
'unrecognizedValues' => $this -> attr_html -> unrecognizedValues,
|
||||
|
@ -96,6 +101,26 @@ class LSformElement_select_object extends LSformElement {
|
|||
));
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 -> params['html_options']['sortDirection']) && $this -> params['html_options']['sortDirection']=='DESC') {
|
||||
$dir=-1;
|
||||
}
|
||||
else {
|
||||
$dir=1;
|
||||
}
|
||||
if ($va == $vb) return 0;
|
||||
$val = strcoll(strtolower($va), strtolower($vb));
|
||||
return $val*$dir;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the values of the object form the session variable
|
||||
|
|
Loading…
Reference in a new issue