Commit 27481749 authored by haemmer's avatar haemmer

Order of categories is now preserved

parent 23b21ef1
...@@ -868,34 +868,44 @@ function convertToShibDSStructure($IDProviders){ ...@@ -868,34 +868,44 @@ function convertToShibDSStructure($IDProviders){
/******************************************************************************/ /******************************************************************************/
// Sorts the IDProviders array // Sorts the IDProviders array
function sortIdentityProviders(&$IDProviders){ function sortIdentityProviders(&$IDProviders){
$sortedIDProviders = Array();
$orderedCategories = Array(); $orderedCategories = Array();
// Create array with categories and IdPs in categories // Create array with categories and IdPs in categories
$unknownCategory = array(); $unknownCategory = array();
foreach ($IDProviders as $entityId => $IDProvider){ foreach ($IDProviders as $entityId => $IDProvider){
// Skip incomplete descriptions
if (!is_array($IDProvider) || !isset($IDProvider['Name'])){
continue;
}
// Add categories // Add categories
if ($IDProvider['Type'] == 'category'){ if ($IDProvider['Type'] == 'category'){
$orderedCategories[$entityId]['data'] = $IDProvider; $orderedCategories[$entityId]['data'] = $IDProvider;
}
}
// Add category 'unknown' if not present
if (!isset($orderedCategories['unknown'])){
$orderedCategories['unknown']['data'] = array (
'Name' => 'Unknown',
'Type' => 'category',
);
}
foreach ($IDProviders as $entityId => $IDProvider){
// Skip categories
if ($IDProvider['Type'] == 'category'){
continue; continue;
} }
// Skip incomplete descriptions
if (!is_array($IDProvider) || !isset($IDProvider['Name'])){
continue;
}
// Sanitize category // Sanitize category
if (!isset($IDProvider['Type'])){ if (!isset($IDProvider['Type'])){
$IDProvider['Type'] = 'unknown'; $IDProvider['Type'] = 'unknown';
} }
if ($IDProvider['Type'] == 'unknown'){ // Add IdP
$unknownCategory[$entityId] = $IDProvider; $orderedCategories[$IDProvider['Type']]['IdPs'][$entityId] = $IDProvider;
} else {
$orderedCategories[$IDProvider['Type']]['IdPs'][$entityId] = $IDProvider;
}
} }
// Relocate all IdPs for which no category with a name was defined // Relocate all IdPs for which no category with a name was defined
...@@ -914,23 +924,12 @@ function sortIdentityProviders(&$IDProviders){ ...@@ -914,23 +924,12 @@ function sortIdentityProviders(&$IDProviders){
unset($orderedCategories[$category]); unset($orderedCategories[$category]);
} }
// Add category 'unknown' if not present
if (!isset($orderedCategories['unknown'])){
$orderedCategories['unknown']['data'] = array (
'Name' => 'Unknown',
'Type' => 'category',
);
}
// Push unknown category to the end
$orderedCategories['unknown']['IdPs'] = $unknownCategory;
// Recompose $IDProviders // Recompose $IDProviders
$IDProviders = Array(); $IDProviders = Array();
foreach ($orderedCategories as $category => $object){ foreach ($orderedCategories as $category => $object){
// Skip category if it contains no IdPs // Skip category if it contains no IdPs
if (count($object['IdPs']) < 1 ){ if (!isset($object['IdPs']) || count($object['IdPs']) < 1 ){
continue; continue;
} }
...@@ -945,7 +944,6 @@ function sortIdentityProviders(&$IDProviders){ ...@@ -945,7 +944,6 @@ function sortIdentityProviders(&$IDProviders){
$IDProviders[$entityId] = $IDProvider; $IDProviders[$entityId] = $IDProvider;
} }
} }
} }
/******************************************************************************/ /******************************************************************************/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment