Skip to content

Commit

Permalink
add "sort" param for sorting LDAP multivalued attributes (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
David Coutadeur committed Nov 4, 2024
1 parent 34e5a0e commit a09bbcf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
4 changes: 2 additions & 2 deletions conf/config.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@
'authtimestamp' => array( 'attribute' => 'authtimestamp', 'faclass' => 'lock', 'type' => 'date' ),
'identifier' => array( 'attribute' => 'uid', 'faclass' => 'user-o', 'type' => 'text' ),
'pwdaccountlockedtime' => array( 'attribute' => 'pwdaccountlockedtime', 'faclass' => 'lock', 'type' => 'date' ),
'pwdchangedtime' => array( 'attribute' => 'pwdchangedtime', 'faclass' => 'lock', 'type' => 'date' ),
'pwdfailuretime' => array( 'attribute' => 'pwdfailuretime', 'faclass' => 'lock', 'type' => 'date' ),
'pwdchangedtime' => array( 'attribute' => 'pwdchangedtime', 'faclass' => 'lock', 'type' => 'date', 'sort' => 'descending' ),
'pwdfailuretime' => array( 'attribute' => 'pwdfailuretime', 'faclass' => 'lock', 'type' => 'date', 'sort' => 'descending' ),
'pwdlastsuccess' => array( 'attribute' => 'pwdlastsuccess', 'faclass' => 'lock', 'type' => 'date' ),
'pwdpolicysubentry' => array( 'attribute' => 'pwdpolicysubentry', 'faclass' => 'lock', 'type' => 'ppolicy_dn' ),
'pwdgraceusetime' => array( 'attribute' => ' pwdgraceusetime', 'faclass' => 'lock', 'type' => 'date' ),
Expand Down
1 change: 1 addition & 0 deletions docs/attributes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Attributes are defined in ``$attributes_map``, where each item is an array with
* ``attribute``: name of LDAP attribute, in lower case
* ``faclass``: name of Font Awesome icon class
* ``type``: type of attribute (text, mailto, tel or date)
* ``sort``: optional, when attribute is multi-valued, sort them. Two possible values: ``ascending`` (default) or ``descending``

This is used to configure how attribute is displayed.

Expand Down
19 changes: 18 additions & 1 deletion htdocs/display.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,24 @@
# Sort attributes values
foreach ($entry[0] as $attr => $values) {
if ( is_array($values) && $values['count'] > 1 ) {
asort($values);
if(isset($attributes_map[$attr]['sort']))
{
if($attributes_map[$attr]['sort'] == "descending" )
{
# descending sort
arsort($values);
}
else
{
# ascending sort
asort($values);
}
}
else
{
# if 'sort' param unset: default to ascending sort
asort($values);
}
}
if ( isset($values['count']) ) {
unset($values['count']);
Expand Down

0 comments on commit a09bbcf

Please sign in to comment.