]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Repository/EntryRepository.php
Delete tag or tags by label
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Repository / EntryRepository.php
index 87e34dc997c50fbea9d7864290f554d3d236983f..63c4c3be9f0f21f021a2c9d010f9fb3085499439 100644 (file)
@@ -92,12 +92,15 @@ class EntryRepository extends EntityRepository
      * @param bool   $isStarred
      * @param string $sort
      * @param string $order
+     * @param int    $since
+     * @param string $tags
      *
      * @return array
      */
-    public function findEntries($userId, $isArchived = null, $isStarred = null, $sort = 'created', $order = 'ASC')
+    public function findEntries($userId, $isArchived = null, $isStarred = null, $sort = 'created', $order = 'ASC', $since = 0, $tags = '')
     {
         $qb = $this->createQueryBuilder('e')
+            ->leftJoin('e.tags', 't')
             ->where('e.user =:userId')->setParameter('userId', $userId);
 
         if (null !== $isArchived) {
@@ -108,6 +111,16 @@ class EntryRepository extends EntityRepository
             $qb->andWhere('e.isStarred =:isStarred')->setParameter('isStarred', (bool) $isStarred);
         }
 
+        if ($since >= 0) {
+            $qb->andWhere('e.updatedAt > :since')->setParameter('since', new \DateTime(date('Y-m-d H:i:s', $since)));
+        }
+
+        if ('' !== $tags) {
+            foreach (explode(',', $tags) as $tag) {
+                $qb->andWhere('t.label = :label')->setParameter('label', $tag);
+            }
+        }
+
         if ('created' === $sort) {
             $qb->orderBy('e.id', $order);
         } elseif ('updated' === $sort) {
@@ -157,7 +170,7 @@ class EntryRepository extends EntityRepository
             ->getQuery()
             ->getResult();
 
-        $languages = array();
+        $languages = [];
         foreach ($results as $result) {
             $languages[$result['language']] = $result['language'];
         }
@@ -209,6 +222,19 @@ class EntryRepository extends EntityRepository
         $this->getEntityManager()->flush();
     }
 
+    /**
+     * Remove tags from all user entries
+     *
+     * @param int $userId
+     * @param Array<Tag> $tags
+     */
+
+    public function removeTags($userId, $tags) {
+        foreach ($tags as $tag) {
+            $this->removeTag($userId, $tag);
+        }
+    }
+
     /**
      * Find all entries that are attached to a give tag id.
      *
@@ -233,7 +259,7 @@ class EntryRepository extends EntityRepository
      * @param $url
      * @param $userId
      *
-     * @return array|bool
+     * @return Entry|bool
      */
     public function findByUrlAndUserId($url, $userId)
     {