From eb2684cbedfe7a82447110c8fd7c9e3e97c00698 Mon Sep 17 00:00:00 2001 From: Olav Morken <olav.morken@uninett.no> Date: Thu, 22 Jul 2010 08:25:13 +0000 Subject: [PATCH] discopower: Fix sorting when missing name. git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2427 44740490-163a-0410-bde0-09ae8108e29a --- modules/discopower/lib/PowerIdPDisco.php | 32 ++++++++++++++++++------ 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/modules/discopower/lib/PowerIdPDisco.php b/modules/discopower/lib/PowerIdPDisco.php index 7ab43ff83..8d07bc6f6 100644 --- a/modules/discopower/lib/PowerIdPDisco.php +++ b/modules/discopower/lib/PowerIdPDisco.php @@ -44,16 +44,32 @@ class sspmod_discopower_PowerIdPDisco extends SimpleSAML_XHTML_IdPDisco { protected function log($message) { SimpleSAML_Logger::info('PowerIdPDisco.' . $this->instance . ': ' . $message); } - - - public static function mcmp($a, $b) { -# echo 'aort'; exit; - if ($a['name']['en'] == $b['name']['en']) { - return 0; - } - return ($a['name']['en'] < $b['name']['en']) ? -1 : 1; + + + /** + * Compare two entities. + * + * This function is used to sort the entity list. It sorts based on english name, + * and will always put IdP's with names configured before those with only an + * entityID. + * + * @param array $a The metadata of the first entity. + * @param array $b The metadata of the second entity. + * @return int How $a compares to $b. + */ + public static function mcmp(array $a, array $b) { + if (isset($a['name']['en']) && isset($b['name']['en'])) { + return strcasecmp($a['name']['en'], $b['name']['en']); + } elseif (isset($a['name']['en'])) { + return -1; /* Place name before entity ID. */ + } elseif (isset($b['name']['en'])) { + return 1; /* Place entity ID after name. */ + } else { + return strcasecmp($a['entityid'], $b['entityid']); + } } + /* * This function will structure the idp list in a hierarchy based upon the tags. */ -- GitLab