I have coded a page which displays all administrators of the system. What I want to do is customize my query so that it would exclude the currently authenticated user from the list.
Now I know I can get the user_id
from the controller and pass it to the entity repository, but I was wondering if there is a way to access that directly through the Entity Repository?
For example:
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\NoResultException;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
class AdminUserRepository extends EntityRepository implements UserProviderInterface
{
public function getAdmins($int = 10, $offset = 0, array $orderBy = array('admin_id', 'asc')){
$admin_id = fetch the admin id ?;
$query = $this->createQueryBuilder('admins')
->where("admins.admin_id != '".$admin_id."'")
->orderBy('admins.'.$orderBy[0], $orderBy[1])
->setFirstResult($offset)
->setMaxResults($int)
->getQuery()
->getResult();
return $query;
}
}
EntityRepository
itself. – Pederast