]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Repository/EntryRepository.php
Fixed repository to retrieve articles
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Repository / EntryRepository.php
index bfd079377ac783bdd4c2e0e2f84cb3f2e9d0496b..23d1e37e2deda7aa25a53823a417ece9741edf5f 100644 (file)
@@ -39,7 +39,34 @@ class EntryRepository extends EntityRepository
         return $this
             ->getSortedQueryBuilderByUser($userId)
             ->andWhere('e.isArchived = false')
-        ;
+            ;
+    }
+
+    /**
+     * Retrieves entries with the same domain.
+     *
+     * @param int $userId
+     * @param int $entryId
+     *
+     * @return QueryBuilder
+     */
+    public function getBuilderForSameDomainByUser($userId, $entryId)
+    {
+        $queryBuilder = $this->createQueryBuilder('e');
+
+        return $this
+            ->getSortedQueryBuilderByUser($userId)
+            ->andWhere('e.id <> :entryId')->setParameter('entryId', $entryId)
+            ->andWhere(
+                $queryBuilder->expr()->in(
+                    'e.domainName',
+                    $this
+                        ->createQueryBuilder('e2')
+                        ->select('e2.domainName')
+                        ->where('e2.id = :entryId')->setParameter('entryId', $entryId)
+                        ->getDQL()
+                )
+            );
     }
 
     /**