]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/FederationBundle/Repository/AccountRepository.php
WIP
[github/wallabag/wallabag.git] / src / Wallabag / FederationBundle / Repository / AccountRepository.php
diff --git a/src/Wallabag/FederationBundle/Repository/AccountRepository.php b/src/Wallabag/FederationBundle/Repository/AccountRepository.php
new file mode 100644 (file)
index 0000000..e39bc58
--- /dev/null
@@ -0,0 +1,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();
+    }
+}