Commit d3ac2456 by Julien Jorry

Fix #134 - Liste déroulante pour gestionnaire de prestataire ordonné avec nom prenom (email)

parent a85f7cfd
...@@ -293,8 +293,10 @@ class PrestataireAdmin extends AbstractAdmin ...@@ -293,8 +293,10 @@ class PrestataireAdmin extends AbstractAdmin
'multiple' => true, 'multiple' => true,
'required' => false, 'required' => false,
'label' => 'Associer à un(des) utilisateur(s) existant :', 'label' => 'Associer à un(des) utilisateur(s) existant :',
'choices' => $this->getConfigurationPool()->getContainer()->get('doctrine')->getRepository(User::class)->findAll(), 'choices' => $this->getConfigurationPool()->getContainer()->get('doctrine')->getRepository(User::class)->findOrderByName(),
'choice_label' => 'username', 'choice_label' => function ($user) {
return $user->getLastname() . ' ' . $user->getFirstname() . ' (' . $user->getEmail() . ')';
},
'placeholder' => 'Choisir un utilisateur', 'placeholder' => 'Choisir un utilisateur',
]) ])
->add('newusers', CollectionType::class, [ ->add('newusers', CollectionType::class, [
...@@ -317,8 +319,10 @@ class PrestataireAdmin extends AbstractAdmin ...@@ -317,8 +319,10 @@ class PrestataireAdmin extends AbstractAdmin
'multiple' => true, 'multiple' => true,
'required' => false, 'required' => false,
'label' => 'Associer à un(des) utilisateur(s) existant :', 'label' => 'Associer à un(des) utilisateur(s) existant :',
'choices' => $this->getConfigurationPool()->getContainer()->get('doctrine')->getRepository(User::class)->findAll(), 'choices' => $this->getConfigurationPool()->getContainer()->get('doctrine')->getRepository(User::class)->findOrderByName(),
'choice_label' => 'username', 'choice_label' => function ($user) {
return $user->getLastname() . ' ' . $user->getFirstname() . ' (' . $user->getEmail() . ')';
},
'placeholder' => 'Choisir un utilisateur', 'placeholder' => 'Choisir un utilisateur',
]) ])
->add('newcaissiers', CollectionType::class, [ ->add('newcaissiers', CollectionType::class, [
......
...@@ -24,12 +24,16 @@ class UserRepository extends ServiceEntityRepository ...@@ -24,12 +24,16 @@ class UserRepository extends ServiceEntityRepository
*/ */
public function findOrderByName() public function findOrderByName()
{ {
$qb = $this->createQueryBuilder('p'); $qb = $this->createQueryBuilder('u');
return $qb return $qb
->where('u.enabled = :enabled') ->where('u.enabled = :enabled')
->addSelect('CASE WHEN (u.lastname IS NULL OR u.lastname = \'\') THEN 1 ELSE 0 END AS HIDDEN nameIsNull')
->addSelect('CASE WHEN (u.firstname IS NULL OR u.firstname = \'\') THEN 1 ELSE 0 END AS HIDDEN fnameIsNull')
->setParameter('enabled', true) ->setParameter('enabled', true)
->orderBy('u.lastname', 'ASC') ->orderBy('nameIsNull', 'ASC')
->addOrderBy('fnameIsNull', 'ASC')
->addOrderBy('u.lastname', 'ASC')
->addOrderBy('u.firstname', 'ASC') ->addOrderBy('u.firstname', 'ASC')
->addOrderBy('u.username', 'ASC') ->addOrderBy('u.username', 'ASC')
->getQuery() ->getQuery()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment