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