Skip to content

Commit

Permalink
fix(Bazar/annuaire_alphabetique): maage sorting characters with accent
Browse files Browse the repository at this point in the history
  • Loading branch information
J9rem committed Dec 13, 2021
1 parent 03d393d commit ab9838f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Expand Up @@ -40,7 +40,7 @@

<?php
$fiche['bf_titre'] = trim($fiche['bf_titre']);
$firstChar = mb_strtolower($fiche['bf_titre'][0]);
$firstChar = strtolower(removeAccents($fiche['bf_titre'])[0]);

// si on change de lettre dans le parcours alphabétique, on rajoute une ancre avec le titre de la lettre
if (empty($curChar) || $firstChar != $curChar) : ?>
Expand Down
16 changes: 14 additions & 2 deletions tools/bazar/services/BazarListService.php
Expand Up @@ -247,10 +247,22 @@ private function buildFieldSorter($ordre, $champ): callable
{
return function ($a, $b) use ($ordre, $champ) {
if ($ordre == 'desc') {
return strcoll($b[$champ], $a[$champ]);
$first = $b[$champ] ?? '';
$second = $a[$champ] ?? '';
} else {
return strcoll($a[$champ], $b[$champ]);
$first = $a[$champ] ?? '';
$second = $b[$champ] ?? '';
}
// compare insentive uppercase even for special chars
return strcmp($this->sanitizeStringForCompare($first), $this->sanitizeStringForCompare($second));
};
}

private function sanitizeStringForCompare($value): string
{
$value = is_scalar($value)
? strval($value)
: json_encode($value);
return strtoupper(removeAccents($value));
}
}

0 comments on commit ab9838f

Please sign in to comment.