Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Commit

Permalink
Merge pull request #1 from SURFnet/name-sort
Browse files Browse the repository at this point in the history
Name sort
  • Loading branch information
Tjeerd authored Aug 26, 2016
2 parents b315564 + 684945b commit 847852d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 6 deletions.
1 change: 0 additions & 1 deletion src/AppBundle/Controller/GroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/AppBundle/Controller/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/AppBundle/Controller/UserGroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/AppBundle/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class User
protected $loginName;

/**
* @var string
* @var \DateTime
*
* @ORM\Column(type="datetime", name="UserTimestamp", nullable=true)
* @Expose()
Expand Down
10 changes: 9 additions & 1 deletion src/AppBundle/Manager/MembershipManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
10 changes: 9 additions & 1 deletion src/AppBundle/Manager/UserManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 847852d

Please sign in to comment.