diff --git a/src/AppBundle/Controller/GroupController.php b/src/AppBundle/Controller/GroupController.php index 529f24d..4323339 100644 --- a/src/AppBundle/Controller/GroupController.php +++ b/src/AppBundle/Controller/GroupController.php @@ -9,7 +9,6 @@ use AppBundle\Form\UserGroupType; use AppBundle\Form\UserInGroupType; use AppBundle\Form\UserInGroupUpdateType; -use FOS\RestBundle\Controller\Annotations; use FOS\RestBundle\Controller\FOSRestController; use Nelmio\ApiDocBundle\Annotation\ApiDoc; use Symfony\Component\HttpFoundation\Request; diff --git a/src/AppBundle/Controller/UserController.php b/src/AppBundle/Controller/UserController.php index c88d210..2145093 100644 --- a/src/AppBundle/Controller/UserController.php +++ b/src/AppBundle/Controller/UserController.php @@ -4,7 +4,6 @@ use AppBundle\Entity\User; use AppBundle\Form\UserType; -use FOS\RestBundle\Controller\Annotations; use FOS\RestBundle\Controller\FOSRestController; use Nelmio\ApiDocBundle\Annotation\ApiDoc; use Symfony\Component\HttpFoundation\Request; diff --git a/src/AppBundle/Controller/UserGroupController.php b/src/AppBundle/Controller/UserGroupController.php index b727ba2..083503c 100644 --- a/src/AppBundle/Controller/UserGroupController.php +++ b/src/AppBundle/Controller/UserGroupController.php @@ -3,7 +3,6 @@ namespace AppBundle\Controller; use AppBundle\Entity\UserInGroup; -use FOS\RestBundle\Controller\Annotations; use FOS\RestBundle\Controller\FOSRestController; use Nelmio\ApiDocBundle\Annotation\ApiDoc; use Symfony\Component\HttpFoundation\Request; diff --git a/src/AppBundle/Entity/User.php b/src/AppBundle/Entity/User.php index e52bee4..ab3b942 100644 --- a/src/AppBundle/Entity/User.php +++ b/src/AppBundle/Entity/User.php @@ -62,7 +62,7 @@ class User protected $loginName; /** - * @var string + * @var \DateTime * * @ORM\Column(type="datetime", name="UserTimestamp", nullable=true) * @Expose() diff --git a/src/AppBundle/Manager/MembershipManager.php b/src/AppBundle/Manager/MembershipManager.php index ae012a8..0fa2005 100644 --- a/src/AppBundle/Manager/MembershipManager.php +++ b/src/AppBundle/Manager/MembershipManager.php @@ -5,6 +5,7 @@ use AppBundle\Entity\UserInGroup; use AppBundle\Event\GroupEvent; use Doctrine\Bundle\DoctrineBundle\Registry; +use Doctrine\ORM\Query\Expr; use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\Tools\Pagination\Paginator; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -98,11 +99,18 @@ public function findMemberships( $qb->andWhere('ug.role = :role')->setParameter('role', $role); } + if ($sort === 'name') { + $sort = new Expr\OrderBy('u.lastName'); + $sort->add('u.firstName'); + } else { + $sort = new Expr\OrderBy('u.' . $sort); + } + $qb ->andWhere('ug.group = :id') ->setParameter('id', $groupId) ->join('ug.user', 'u') - ->orderBy('u.' . $sort, 'ASC') + ->orderBy($sort) ->setFirstResult($offset) ->setMaxResults($limit); diff --git a/src/AppBundle/Manager/UserManager.php b/src/AppBundle/Manager/UserManager.php index 580f42f..540d82d 100644 --- a/src/AppBundle/Manager/UserManager.php +++ b/src/AppBundle/Manager/UserManager.php @@ -5,6 +5,7 @@ use AppBundle\Entity\User; use AppBundle\Event\UserEvent; use Doctrine\Bundle\DoctrineBundle\Registry; +use Doctrine\ORM\Query\Expr; use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\Tools\Pagination\Paginator; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -65,7 +66,14 @@ public function findUsers( /** @var QueryBuilder $qb */ $qb = $this->doctrine->getRepository('AppBundle:User')->createQueryBuilder('u'); - $qb->where('u.type = \'ldap\'')->orderBy('u.' . $sort, 'ASC')->setFirstResult($offset)->setMaxResults($limit); + if ($sort === 'name') { + $sort = new Expr\OrderBy('u.lastName'); + $sort->add('u.firstName'); + } else { + $sort = new Expr\OrderBy('u.' . $sort); + } + + $qb->where('u.type = \'ldap\'')->orderBy($sort)->setFirstResult($offset)->setMaxResults($limit); if ($reference !== null) { $qb->andWhere('u.reference = :reference')->setParameter('reference', $reference);