From bbbc8f7e0268f15ebde3ca0e21cfe39c7892ca23 Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Wed, 5 Mar 2014 14:47:29 +0100 Subject: [PATCH] Add some application repository function --- .../Repositories/ApiApplicationRepository.php | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/lib/Alchemy/Phrasea/Model/Repositories/ApiApplicationRepository.php b/lib/Alchemy/Phrasea/Model/Repositories/ApiApplicationRepository.php index 3e622dd792..792a7b102f 100644 --- a/lib/Alchemy/Phrasea/Model/Repositories/ApiApplicationRepository.php +++ b/lib/Alchemy/Phrasea/Model/Repositories/ApiApplicationRepository.php @@ -2,7 +2,10 @@ namespace Alchemy\Phrasea\Model\Repositories; +use Alchemy\Phrasea\Model\Entities\User; +use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\EntityRepository; +use Doctrine\ORM\Query\Expr; /** * ApiApplicationRepository @@ -12,4 +15,40 @@ use Doctrine\ORM\EntityRepository; */ class ApiApplicationRepository extends EntityRepository { + public function findByClientId($clientId) + { + $qb = $this->createQueryBuilder('app'); + $qb->where($qb->expr()->eq('app.clientId', ':clientId')); + $qb->setParameter(':clientId', $clientId); + + return $qb->getQuery()->getSingleResult(); + } + + public function findByCreator(User $user) + { + $qb = $this->createQueryBuilder('app'); + $qb->where($qb->expr()->eq('app.creator', ':creator')); + $qb->setParameter(':creator', $user); + + return $qb->getQuery()->getResult(); + } + + public function findByUser(User $user) + { + $qb = $this->createQueryBuilder('app'); + $qb->innerJoin('app.accounts', 'acc', Expr\Join::WITH, $qb->expr()->eq('acc.user', ':user')); + $qb->setParameter(':user', $user); + + return $qb->getQuery()->getResult(); + } + + public function findAuthorizedAppsByUser(User $user) + { + $qb = $this->createQueryBuilder('app'); + $qb->innerJoin('app.accounts', 'acc', Expr\Join::WITH, $qb->expr()->eq('acc.user', ':user')); + $qb->andWhere($qb->expr()->eq('acc.revoked', $qb->expr()->literal(false))); + $qb->setParameter(':user', $user); + + return $qb->getQuery()->getResult(); + } }