namespace Wallabag\CoreBundle\Repository;
use Doctrine\ORM\EntityRepository;
+use Doctrine\ORM\Query;
use Pagerfanta\Adapter\DoctrineORMAdapter;
use Pagerfanta\Pagerfanta;
use Wallabag\CoreBundle\Entity\Tag;
class EntryRepository extends EntityRepository
{
+ private $lifeTime;
+
/**
* Return a query builder to used by other getBuilderFor* method.
*
;
}
+ /**
+ * 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.
*
}
/**
- * Remove tags from all user entries
+ * Remove tags from all user entries.
*
- * @param int $userId
+ * @param int $userId
* @param Array<Tag> $tags
*/
-
- public function removeTags($userId, $tags) {
+ public function removeTags($userId, $tags)
+ {
foreach ($tags as $tag) {
$this->removeTag($userId, $tag);
}
return $qb->getQuery()->getSingleScalarResult();
}
+
+ public function setLifeTime($lifeTime)
+ {
+ $this->lifeTime = $lifeTime;
+ }
+
+ /**
+ * Enable cache for a query.
+ *
+ * @param Query $query
+ *
+ * @return Query
+ */
+ public function enableCache(Query $query)
+ {
+ $query->useQueryCache(true);
+ $query->useResultCache(true);
+ $query->setResultCacheLifetime($this->lifeTime);
+
+ return $query;
+ }
}