X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FRepository%2FEntryRepository.php;h=cd2b47b9f7c32b737d35910effe1cf53398adac8;hb=e4cf672ccf61689ba28c2e89fc55f83167800b18;hp=86bce545e07ed7b14cfb037a2f23992ab4971274;hpb=0b0233b1ec8208be47c76856a4e317673927b21e;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index 86bce545..cd2b47b9 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php @@ -85,6 +85,22 @@ class EntryRepository extends EntityRepository ; } + /** + * Retrieves untagged entries for a user. + * + * @param int $userId + * + * @return QueryBuilder + */ + public function getBuilderForUntaggedByUser($userId) + { + return $this + ->getBuilderByUser($userId) + ->leftJoin('e.tags', 't') + ->groupBy('e.id') + ->having('count(t.id) = 0'); + } + /** * Find Entries. * @@ -112,7 +128,7 @@ class EntryRepository extends EntityRepository $qb->andWhere('e.isStarred =:isStarred')->setParameter('isStarred', (bool) $isStarred); } - if ($since >= 0) { + if ($since > 0) { $qb->andWhere('e.updatedAt > :since')->setParameter('since', new \DateTime(date('Y-m-d H:i:s', $since))); } @@ -223,6 +239,19 @@ class EntryRepository extends EntityRepository $this->getEntityManager()->flush(); } + /** + * Remove tags from all user entries. + * + * @param int $userId + * @param Array $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. * @@ -252,7 +281,7 @@ class EntryRepository extends EntityRepository public function findByUrlAndUserId($url, $userId) { $res = $this->createQueryBuilder('e') - ->where('e.url = :url')->setParameter('url', $url) + ->where('e.url = :url')->setParameter('url', urldecode($url)) ->andWhere('e.user = :user_id')->setParameter('user_id', $userId) ->getQuery() ->getResult(); @@ -282,18 +311,22 @@ class EntryRepository extends EntityRepository } /** - * Enable cache for a query + * Count all entries for a tag and a user. * - * @param Query $query + * @param int $userId + * @param int $tagId * - * @return Query + * @return int */ - public function enableCache(Query $query) + public function countAllEntriesByUserIdAndTagId($userId, $tagId) { - $query->useQueryCache(true); - $query->useResultCache(true); - $query->setResultCacheLifetime(5); + $qb = $this->createQueryBuilder('e') + ->select('count(e.id)') + ->leftJoin('e.tags', 't') + ->where('e.user=:userId')->setParameter('userId', $userId) + ->andWhere('t.id=:tagId')->setParameter('tagId', $tagId) + ; - return $query; + return $qb->getQuery()->getSingleScalarResult(); } }