aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/FederationBundle/Repository/AccountRepository.php
blob: e39bc582e82edf2634005cc67e298416e78cda35 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php

namespace Wallabag\FederationBundle\Repository;

use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;

class AccountRepository extends EntityRepository
{
    /**
     * @param $accountId
     * @return QueryBuilder
     */
    public function getBuilderForFollowingsByAccount($accountId)
    {
        return $this->createQueryBuilder('a')
            ->select('f.id, f.username')
            ->innerJoin('a.following', 'f')
            ->where('a.id = :accountId')->setParameter('accountId', $accountId)
            ;
    }

    /**
     * @param $accountId
     * @return QueryBuilder
     */
    public function getBuilderForFollowersByAccount($accountId)
    {
        return $this->createQueryBuilder('a')
            ->innerJoin('a.followers', 'f')
            ->where('a.id = :accountId')->setParameter('accountId', $accountId)
            ;
    }

    /**
     * @param $username
     * @return QueryBuilder
     * @throws \Doctrine\ORM\NonUniqueResultException
     */
    public function findAccountByUsername($username)
    {
        return $this->createQueryBuilder('a')
            ->where('a.username = :username')->setParameter('username', $username)
            ->andWhere('a.server = null')
            ->getQuery()
            ->getOneOrNullResult();
    }
}