Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
GIP RENATER
switch-wayf
Commits
85233aff
Commit
85233aff
authored
Sep 20, 2013
by
haemmer
Browse files
Improved IdP sorting code
parent
1d24b2a4
Changes
1
Hide whitespace changes
Inline
Side-by-side
functions.php
View file @
85233aff
...
...
@@ -866,68 +866,67 @@ function convertToShibDSStructure($IDProviders){
// Sorts the IDProviders array
function
sortIdentityProviders
(
&
$IDProviders
){
$sortedIDProviders
=
Array
();
$
s
or
t
edCategories
=
Array
();
$or
der
edCategories
=
Array
();
// Create array with categories and IdPs in categories
$unknownCategory
=
array
();
foreach
(
$IDProviders
as
$entityId
=>
$IDProvider
){
// Skip incomplete descriptions
if
(
!
is_array
(
$IDProvider
)
||
!
isset
(
$IDProvider
[
'Name'
])){
// Remove any entries that are not arrays
unset
(
$IDProviders
[
$entityId
]);
}
elseif
(
$IDProvider
[
'Type'
]
==
'category'
){
$sortedCategories
[
$entityId
]
=
$IDProvider
;
continue
;
}
// Add categories
if
(
$IDProvider
[
'Type'
]
==
'category'
){
$orderedCategories
[
$entityId
][
'data'
]
=
$IDProvider
;
continue
;
}
// Sanitize category
if
(
!
isset
(
$IDProvider
[
'Type'
])){
$IDProvider
[
'Type'
]
=
'unknown'
;
}
if
(
$IDProvider
[
'Type'
]
==
'unknown'
){
$unknownCategory
[]
=
$IDProvider
;
}
else
{
$
s
or
tedIDProviders
[
$entityId
]
=
$IDProvider
;
$or
deredCategories
[
$IDProvider
[
'Type'
]][
'IdPs'
]
[
$entityId
]
=
$IDProvider
;
}
}
// Sort categories and IdPs
if
(
count
(
$sortedCategories
)
>
1
){
// Sort using index
uasort
(
$sortedCategories
,
'sortUsingTypeIndexAndName'
);
}
else
{
// Sort alphabetically using the key of a category
ksort
(
$sortedCategories
);
}
// Add category 'unknown' if not present
if
(
!
isset
(
$
IDProvider
s
[
'unknown'
])){
$
s
or
t
edCategories
[
'unknown'
]
=
array
(
'Name'
=>
'Unknown'
,
'Type'
=>
'category'
,
if
(
!
isset
(
$
orderedCategorie
s
[
'unknown'
])){
$or
der
edCategories
[
'unknown'
]
[
'data'
]
=
array
(
'Name'
=>
'Unknown'
,
'Type'
=>
'category'
,
);
}
// Sort Identity Providers
uasort
(
$sortedIDProviders
,
'sortUsingTypeIndexAndName'
);
$IDProviders
=
Array
();
// Push unknown category to the end
$orderedCategories
[
'unknown'
][
'IdPs'
]
=
$unknownCategory
;
// Compose array
$unknownCategoryIsEmpty
=
true
;
while
(
list
(
$categoryKey
,
$categoryValue
)
=
each
(
$sortedCategories
)){
$IDProviders
[
$categoryKey
]
=
$categoryValue
;
// Recompose $IDProviders
$IDProviders
=
Array
();
foreach
(
$orderedCategories
as
$category
=>
$object
){
// Loop through all IdPs
foreach
(
$sortedIDProviders
as
$IDProvidersPKey
=>
$IDProvidersValue
){
// Add IdP if its type matches the current category
if
(
$IDProvidersValue
[
'Type'
]
==
$categoryKey
){
$IDProviders
[
$IDProvidersPKey
]
=
$IDProvidersValue
;
unset
(
$sortedIDProviders
[
$IDProvidersPKey
]);
}
// Add IdP if its type is 'unknown' or if there doesnt exist a category for its type
if
(
$categoryKey
==
'unknown'
||
!
isset
(
$sortedCategories
[
$IDProvidersValue
[
'Type'
]])){
$IDProviders
[
$IDProvidersPKey
]
=
$IDProvidersValue
;
unset
(
$sortedIDProviders
[
$IDProvidersPKey
]);
$unknownCategoryIsEmpty
=
false
;
}
// Skip category if it contains no IdPs
if
(
count
(
$object
[
'IdPs'
])
<
1
){
continue
;
}
// Add category
$IDProviders
[
$category
]
=
$object
[
'data'
];
// Sort IdPs in category
uasort
(
$object
[
'IdPs'
],
'sortUsingTypeIndexAndName'
);
// Add IdPs
foreach
(
$object
[
'IdPs'
]
as
$entityId
=>
$IDProvider
){
$IDProviders
[
$entityId
]
=
$IDProvider
;
}
}
// Check if unkown category is needed
if
(
$unknownCategoryIsEmpty
||
(
count
(
$sortedCategories
)
==
1
)){
unset
(
$IDProviders
[
'unknown'
]);
}
}
/******************************************************************************/
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment