Skip to content
This repository was archived by the owner on Sep 19, 2022. It is now read-only.

Commit 1a0f043

Browse files
author
Dominik František Bučík
authored
Merge pull request #184 from CESNET/fix-listofSps
fix: bugfixes in list of SPs
2 parents 5d1f846 + 1cd84a8 commit 1a0f043

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

lib/ListOfSps.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ class ListOfSps
88
{
99
public static function sortByName($a, $b)
1010
{
11-
return strcmp(strtolower($a['name']['value']), strtolower($b['name']['value']));
11+
return strnatcasecmp(
12+
transliterator_transliterate('Any-Latin; Latin-ASCII', $a['name']['value']),
13+
transliterator_transliterate('Any-Latin; Latin-ASCII', $b['name']['value'])
14+
);
1215
}
1316

1417
public static function getClass($type)

templates/listOfSps-tpl.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,25 @@
2424
$samlServices = $this->data['samlServices'];
2525
$oidcServices = $this->data['oidcServices'];
2626
$allServices = $this->data['allServices'];
27-
27+
if ($this->data['isNameMultilingual']) {
28+
// translate service name for sorting
29+
$allServices = array_map(function ($service) {
30+
if (empty($service['name']) || empty($service['name']['value']) || ! is_array($service['name']['value'])) {
31+
$service['name'] = [
32+
'type' => 'java.lang.String',
33+
'value' => '-',
34+
];
35+
} else {
36+
$service['name']['type'] = 'java.lang.String';
37+
$service['name']['value'] = ListOfSps::getPreferredTranslation(
38+
$service['name']['value'],
39+
$this->getLanguage()
40+
);
41+
}
42+
return $service;
43+
}, $allServices);
44+
}
45+
usort($allServices, ['\\SimpleSAML\\Module\\perun\\ListOfSps', 'sortByName']);
2846

2947
$productionServicesCount = $statistics['samlServicesCount'] - $statistics['samlTestServicesCount'] +
3048
$statistics['oidcServicesCount'] - $statistics['oidcTestServicesCount'];

www/listOfSps.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@
164164
}
165165

166166
$allServices = array_merge($samlServices, $oidcServices);
167-
usort($allServices, 'ListOfSps::sortByName');
168167

169168
if (isset($_GET['output']) && $_GET['output'] === 'json') {
170169
$json = [];
@@ -201,6 +200,7 @@
201200
$t->data['statistics'] = $statistics;
202201
$t->data['attributesToShow'] = $attributesToShow;
203202
$t->data['multilingualAttributes'] = $multilingualAttributes;
203+
$t->data['isNameMultilingual'] = in_array($perunServiceNameAttr, $multilingualAttributes, true);
204204
$t->data['samlServices'] = $samlServices;
205205
$t->data['oidcServices'] = $oidcServices;
206206
$t->data['allServices'] = $allServices;

0 commit comments

Comments
 (0)