* locale based sorting implemented
This commit is contained in:
parent
6e55579fb8
commit
78dfa176f0
@ -10,6 +10,7 @@ use UtilityModule\Hydrator\DoctrineObject;
|
||||
|
||||
class AwardeeManager
|
||||
{
|
||||
const SORT_LOCALE = 'hu_HU.UTF8';
|
||||
const IMAGE_DIRECTORY = 'data/user-data/images/awardee';
|
||||
|
||||
/** @var EntityManager */
|
||||
@ -31,9 +32,11 @@ class AwardeeManager
|
||||
*/
|
||||
public function getAwardees(): ?array
|
||||
{
|
||||
return $this->entityManager->getRepository(Awardee::class)->findBy([], [
|
||||
$result = $this->entityManager->getRepository(Awardee::class)->findBy([], [
|
||||
'year' => 'DESC',
|
||||
'name' => 'ASC',
|
||||
]);
|
||||
return $this->sortAwardeesResult($result);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -42,9 +45,25 @@ class AwardeeManager
|
||||
*/
|
||||
public function getAwardeesByYear(int $year): ?array
|
||||
{
|
||||
return $this->entityManager->getRepository(Awardee::class)->findBy([
|
||||
$result = $this->entityManager->getRepository(Awardee::class)->findBy([
|
||||
'year' => $year,
|
||||
], [
|
||||
'name' => 'ASC',
|
||||
]);
|
||||
return $this->sortAwardeesResult($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Awardee[] $awardees
|
||||
* @return Awardee[]
|
||||
*/
|
||||
private function sortAwardeesResult(array $awardees): array
|
||||
{
|
||||
setlocale(LC_COLLATE, self::SORT_LOCALE);
|
||||
usort($awardees, function (Awardee $a, Awardee $b) {
|
||||
return strcoll($a->getName(), $b->getName());
|
||||
});
|
||||
return $awardees;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -10,6 +10,7 @@ use UtilityModule\Hydrator\DoctrineObject;
|
||||
|
||||
class JudgeManager
|
||||
{
|
||||
const SORT_LOCALE = 'hu_HU.UTF8';
|
||||
const IMAGE_DIRECTORY = 'data/user-data/images/judge';
|
||||
|
||||
/** @var EntityManager */
|
||||
@ -32,12 +33,14 @@ class JudgeManager
|
||||
public function getJudges(): ?array
|
||||
{
|
||||
$qb = $this->entityManager->createQueryBuilder();
|
||||
return $qb->select('j, t')
|
||||
$result = $qb->select('j, t')
|
||||
->from(Judge::class, 'j')
|
||||
->leftJoin('j.titles', 't')
|
||||
->orderBy('j.name', 'ASC')
|
||||
->addOrderBy('t.year', 'ASC')
|
||||
->getQuery()
|
||||
->getResult();
|
||||
return $this->sortJudgesResult($result);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -47,7 +50,7 @@ class JudgeManager
|
||||
public function getJudgesByYear(int $year): ?array
|
||||
{
|
||||
$qb = $this->entityManager->createQueryBuilder();
|
||||
return $qb->select('j,t')
|
||||
$result = $qb->select('j,t')
|
||||
->from(Judge::class, 'j')
|
||||
->innerJoin('j.titles', 't')
|
||||
->where('t.year = :year')
|
||||
@ -55,6 +58,16 @@ class JudgeManager
|
||||
->setParameter('year', $year)
|
||||
->getQuery()
|
||||
->getResult();
|
||||
return $this->sortJudgesResult($result);
|
||||
}
|
||||
|
||||
private function sortJudgesResult(array $judges): array
|
||||
{
|
||||
setlocale(LC_COLLATE, self::SORT_LOCALE);
|
||||
usort($judges, function (Judge $a, Judge $b) {
|
||||
return strcoll($a->getName(), $b->getName());
|
||||
});
|
||||
return $judges;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user