]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php
Retrieve username/password from database
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Repository / SiteCredentialRepository.php
index 88aee6d583da41fa777e6987365c7e176937aea5..316ecc75020e5400ef272a7e97664a50b6aa8910 100644 (file)
@@ -7,4 +7,22 @@ namespace Wallabag\CoreBundle\Repository;
  */
 class SiteCredentialRepository extends \Doctrine\ORM\EntityRepository
 {
+    /**
+     * Retrieve one username/password for the given host and userId.
+     *
+     * @param string $host
+     * @param int    $userId
+     *
+     * @return null|array
+     */
+    public function findOneByHostAndUser($host, $userId)
+    {
+        return $this->createQueryBuilder('s')
+            ->select('s.username', 's.password')
+            ->where('s.host = :hostname')->setParameter('hostname', $host)
+            ->andWhere('s.user = :userId')->setParameter('userId', $userId)
+            ->setMaxResults(1)
+            ->getQuery()
+            ->getOneOrNullResult();
+    }
 }