order scopes alphabetically

This commit is contained in:
2024-02-26 14:39:10 +01:00
parent bbb167bb85
commit 5b714f17be
6 changed files with 23 additions and 11 deletions

View File

@@ -12,6 +12,7 @@ declare(strict_types=1);
namespace Chill\MainBundle\Repository;
use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;
@@ -20,7 +21,7 @@ final class ScopeRepository implements ScopeRepositoryInterface
{
private readonly EntityRepository $repository;
public function __construct(EntityManagerInterface $entityManager)
public function __construct(EntityManagerInterface $entityManager, private readonly TranslatableStringHelperInterface $translatableStringHelper)
{
$this->repository = $entityManager->getRepository(Scope::class);
}
@@ -45,11 +46,11 @@ final class ScopeRepository implements ScopeRepositoryInterface
public function findAllActive(): array
{
$qb = $this->repository->createQueryBuilder('s');
$scopes = $this->repository->findBy(['active' => true]);
$qb->where('s.active = \'TRUE\'');
usort($scopes, fn (Scope $a, Scope $b) => $this->translatableStringHelper->localize($a->getName()) <=> $this->translatableStringHelper->localize($b->getName()));
return $qb->getQuery()->getResult();
return $scopes;
}
/**