at the end of the day, it was inevitable

This commit is contained in:
Mo Elzubeir
2022-12-09 08:36:26 -06:00
commit 1218570914
1768 changed files with 887087 additions and 0 deletions
@@ -0,0 +1,39 @@
<?php
namespace CacheBundle\Repository;
use CacheBundle\Entity\Analytic\Analytic;
use Doctrine\ORM\EntityRepository;
/**
* Class AnalyticRepository
* @package CacheBundle\Repository
*/
class AnalyticRepository extends EntityRepository
{
/**
* Get array of specified user analytics.
*
* @param integer $user A User entity id.
*
* @return Analytic[]
*/
public function getList($user)
{
$expr = $this->_em->getExpressionBuilder();
return $this->createQueryBuilder('Analytic')
->select(
'partial Analytic.{id,createdAt,updatedAt}',
'partial context.{hash,filters,rawFilters}'
)
->leftJoin('Analytic.context', 'context')
->where($expr->eq('Analytic.owner', ':user'))
->setParameter('user', $user)
->addOrderBy('Analytic.id', 'desc')
->getQuery()
->getResult();
}
}
@@ -0,0 +1,221 @@
<?php
namespace CacheBundle\Repository;
use CacheBundle\Entity\Category;
use Doctrine\DBAL\Driver\Connection;
use Doctrine\ORM\EntityRepository;
/**
* Class CategoryRepository
* @package CacheBundle\Repository
*/
class CategoryRepository extends EntityRepository
{
/**
* Get single entity from repository.
*
* @param integer $id A Entity instance id.
* @param string $method A CRUD method name.
*
* @return Category|null
*/
public function getOne($id, $method)
{
$expr = $this->_em->getExpressionBuilder();
$condition = $expr->andX($expr->eq('Category.id', ':id'));
$parameters = [ 'id' => $id ];
if ($method !== 'get') {
$condition->add($expr->eq('Category.internal', false));
}
return $this->createQueryBuilder('Category')
->addSelect('partial Query.{id, raw, status}')
->where($condition)
->setParameters($parameters)
->getQuery()
->getOneOrNullResult();
}
/**
* Compute feed count in specified category and all childes categories.
*
* @param integer $id A Category entity id.
*
* @return integer
*/
public function computeFeedCounts($id)
{
return (int) $this->_em->getConnection()->fetchColumn("
SELECT COUNT(feeds.id)
FROM feeds
WHERE
category_id in (
SELECT id
FROM (
SELECT *
FROM categories
ORDER BY parent_id, id
) categories_sorted,
(SELECT @pv := '{$id}') initialisation
WHERE
(
FIND_IN_SET(parent_id, @pv) > 0
OR id = {$id}
)
AND @pv := CONCAT(@pv, ',', id)
)
");
}
/**
* Export all feeds inside this category.
*
* @param integer $category A Category entity id.
* @param boolean $export Export all feeds if true and unexport otherwise.
*
* @return void
*/
public function exportFeedsIn($category, $export = true)
{
$this->_em->getConnection()->transactional(function (Connection $conn) use ($category, $export) {
$conn->exec(sprintf("
UPDATE feeds
SET exported = %d
WHERE
category_id in (
SELECT id
FROM (
SELECT *
FROM categories
ORDER BY parent_id, id
) categories_sorted,
(SELECT @pv := '%s') initialisation
WHERE
(
FIND_IN_SET(parent_id, @pv) > 0
OR id = %s
)
AND @pv := CONCAT(@pv, ',', id)
)
", $export, $category, $category));
$conn->exec(sprintf("
UPDATE categories
SET exported = %d
WHERE
id in (
SELECT id
FROM (
SELECT *
FROM categories
ORDER BY parent_id, id
) categories_sorted,
(SELECT @pv := '%s') initialisation
WHERE
(
FIND_IN_SET(parent_id, @pv) > 0
OR id = %s
)
AND @pv := CONCAT(@pv, ',', id)
)
", $export, $category, $category));
});
}
/**
* Get active category.
*
* @param integer $id A Category entity id.
* @param integer $user Filter categories by specified owner if set.
* @param string|array $type Filter by category types.
*
* @return Category|null
*/
public function get($id, $user = null, $type = null)
{
$expr = $this->_em->getExpressionBuilder();
$condition = $expr->andX($expr->eq('Category.id', ':id'));
$parameters = [ 'id' => $id ];
if ($type) {
$type = (array) $type;
$condition->add($expr->in('Category.type', (array) $type));
}
if ($user !== null) {
$condition->add($expr->eq('Category.user', ':user'));
$parameters['user'] = $user;
}
return $this->createQueryBuilder('Category')
->where($condition)
->setParameters($parameters)
->getQuery()
->getOneOrNullResult();
}
/**
* Get array of specified user categories.
*
* @param integer $user A User entity id.
*
* @return Category[]
*/
public function getList($user)
{
$expr = $this->_em->getExpressionBuilder();
return $this->createQueryBuilder('Category')
->select(
'partial Category.{id, name, type}',
'partial Child.{id, name, type}',
'Feed'
)
->leftJoin('Category.parent', 'Parent')
->leftJoin('Category.childes', 'Child')
->leftJoin('Category.feeds', 'Feed')
->where($expr->andX(
$expr->eq('Category.user', ':user'),
$expr->isNull('Category.parent')
))
->setParameter('user', $user)
->getQuery()
->getResult();
}
/**
* Check that specified 'child' category is child of 'parent'.
*
* @param integer $child A Category entity id which may by child.
* @param integer $parent A Category entity id which must by parent of
* specified child.
*
* @return boolean
*/
public function isChildOf($child, $parent)
{
//
// TODO: May be exists more efficient way to do it.
//
$position = (int) $this->_em
->getConnection()
->fetchColumn("
SELECT
FIND_IN_SET({$child}, lvl) AS result
FROM (
SELECT
GROUP_CONCAT(lvl SEPARATOR ',') AS lvl
FROM (
SELECT @parent := (SELECT GROUP_CONCAT(id SEPARATOR ',')
FROM categories
WHERE FIND_IN_SET(parent_id, @parent)
) AS lvl FROM categories JOIN (SELECT @parent := {$parent}) tmp ) a ) b;
");
return $position !== 0;
}
}
@@ -0,0 +1,68 @@
<?php
namespace CacheBundle\Repository;
use CacheBundle\Entity\Category;
use CacheBundle\Entity\Feed\ClipFeed;
use Doctrine\ORM\EntityRepository;
use UserBundle\Entity\User;
/**
* ClipFeedRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class ClipFeedRepository extends EntityRepository
{
/**
* Get read later clip feed.
*
* @param integer $user Owner of read later feed.
*
* @return \CacheBundle\Entity\Feed\AbstractFeed|null
*/
public function getReadLater($user)
{
return $this->createQueryBuilder('Feed')
->where('Feed.user = :user AND Feed.name = :name')
->setParameters([
'user' => $user,
'name' => ClipFeed::READ_LATER,
])
->getQuery()
->getOneOrNullResult();
}
/**
* Create read later feed.
*
* @param integer $user Owner of read later feed.
*
* @return \CacheBundle\Entity\Feed\AbstractFeed
*/
public function createReadLater($user)
{
$mainCategory = $this->_em->createQueryBuilder()
->select('partial Category.{id}')
->from(Category::class, 'Category')
->where('Category.user = :user AND Category.type = :type')
->setParameters([
'user' => $user,
'type' => Category::TYPE_MY_CONTENT,
])
->getQuery()
->getOneOrNullResult();
$feed = ClipFeed::create()
->setName(ClipFeed::READ_LATER)
->setUser($this->_em->getReference(User::class, $user))
->setCategory($mainCategory);
$this->_em->persist($feed);
$this->_em->flush($feed);
return $feed;
}
}
@@ -0,0 +1,79 @@
<?php
namespace CacheBundle\Repository;
use Doctrine\ORM\EntityRepository;
/**
* Class CommentRepository
* @package CacheBundle\Repository
*/
class CommentRepository extends EntityRepository
{
/**
* Get list of comments for documents.
*
* @param integer $document A Document entity id.
* @param array $fields Array of comment fields. Fetch only specified
* fields if set.
* @param integer $count Number of comments.
*
* @return \Doctrine\ORM\QueryBuilder
*/
public function getListForDocument($document, array $fields = [], $count = null)
{
$qb = $this->createQueryBuilder('Comment')
->where('Comment.document = :document')
->addOrderBy('Comment.createdAt', 'desc')
->setParameter('document', $document);
if (count($fields) > 0) {
$authorFields = [];
if (isset($fields['author'])) {
$authorFields = $fields['author'];
unset($fields['author']);
}
$qb->select('partial Comment.{id, '. implode(',', $fields) .'}');
if (count($authorFields) > 0) {
$qb
->join('Comment.author', 'Author')
->addSelect('partial Author.{id, '. implode(',', $authorFields) .'}');
}
} else {
$qb
->join('Comment.author', 'Author')
->addSelect('Author');
}
if ($count !== null) {
$qb->setMaxResults($count);
}
return $qb;
}
/**
* @param integer $documentId A Document entity id.
* @param integer $poolSize Max new comments for specified document.
*
* @return void
*/
public function updateCommentMarks($documentId, $poolSize)
{
$this->_em->getConnection()->executeUpdate(sprintf('
UPDATE comments
SET new = 0
WHERE id IN (
SELECT id
FROM (
SELECT id
FROM comments
WHERE document_id = :document AND new = 1
ORDER BY created_at DESC LIMIT %d, %d
) AS
u)
', $poolSize, 1000), [ 'document' => $documentId ]);
}
}
@@ -0,0 +1,39 @@
<?php
namespace CacheBundle\Repository;
use Doctrine\ORM\EntityRepository;
/**
* Class CommonFeedRepository
* @package CacheBundle\Repository
*/
class CommonFeedRepository extends EntityRepository
{
/**
* Get single feed from repository.
*
* @param integer $id A Feed entity instance id.
* @param integer $user Filter feeds by specified owner if set.
*
* @return \CacheBundle\Entity\Feed\AbstractFeed|null
*/
public function getOne($id, $user)
{
$expr = $this->_em->getExpressionBuilder();
$condition = $expr->andX($expr->eq('Feed.id', ':id'));
$parameters = [ 'id' => $id ];
if ($user !== null) {
$condition->add($expr->eq('Feed.user', ':user'));
$parameters['user'] = $user;
}
return $this->createQueryBuilder('Feed')
->where($condition)
->setParameters($parameters)
->getQuery()
->getOneOrNullResult();
}
}
@@ -0,0 +1,253 @@
<?php
namespace CacheBundle\Repository;
use CacheBundle\Entity\Document;
use Common\Enum\CollectionTypeEnum;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query\Expr\Join;
/**
* Class DocumentRepository
* @package CacheBundle\Repository
*/
class DocumentRepository extends EntityRepository
{
/**
* Get document for specified query.
*
* @param integer $query A Query entity id.
* @param integer $page Request page number.
*
* @return Document[]
*/
public function getForQuery($query, $page)
{
$expr = $this->_em->getExpressionBuilder();
return $this->createQueryBuilder('Document')
->addSelect('Comment, CommentAuthor')
->join('Document.pages', 'Page')
->leftJoin('Document.comments', 'Comment', Join::WITH, $expr->andX(
$expr->eq('Comment.document', 'Document.id'),
$expr->eq('Comment.new', 1)
))
->leftJoin('Comment.author', 'CommentAuthor')
->where($expr->andX(
$expr->eq('Page.number', ':number'),
$expr->eq('Page.query', ':query')
))
->setParameters([
'number' => $page,
'query' => $query,
])
->addOrderBy('Comment.createdAt', 'desc')
->getQuery()
->getResult();
}
/**
* Get documents by given ids for specified query without related pages.
* Result will be ordered depends on specified ids order.
*
* @param integer $collectionId A document collection entity id.
* @param string $collectionType A document collection type.
* @param array $ids Array of document ids.
* @param string[]|array $fields Array of required document fields. Fetch
* all if empty.
*
* @return Document[]
*/
public function getFromCollectionByIds($collectionId, $collectionType, array $ids, array $fields = [])
{
$expr = $this->_em->getExpressionBuilder();
$condition = $expr->andX($expr->in('Document.id', $ids));
switch ($collectionType) {
case CollectionTypeEnum::FEED:
$condition->add($expr->eq('Page.clipFeed', ':collectionId'));
break;
case CollectionTypeEnum::QUERY:
$condition->add($expr->eq('Page.query', ':collectionId'));
break;
default:
throw new \InvalidArgumentException('Invalid collection type.');
}
$select = 'Document';
if (count($fields) > 0) {
$select = 'partial Document.{'. implode(',', $fields). '}';
}
$results = $this->createQueryBuilder('Document')
->select($select)
->addSelect('Comment, CommentAuthor, Page')
->join('Document.pages', 'Page')
->leftJoin('Document.comments', 'Comment', Join::WITH, $expr->andX(
$expr->eq('Comment.document', 'Document.id'),
$expr->eq('Comment.new', 1)
))
->leftJoin('Comment.author', 'CommentAuthor')
->where($condition)
->setParameter('collectionId', $collectionId)
//
// We should clearly say how we want to order because mysql does not
// guarantee what result will be ordered by primary key.
//
->addOrderBy('Document.id', 'asc')
->addOrderBy('Comment.createdAt', 'desc')
->getQuery()
->getResult();
//
// Now we use specified ids as index for fetched documents. Since we got
// ordered result we may use binary search for fetching proper document
// by id.
//
$orderedResult = [];
foreach ($ids as $id) {
$idx = \app\a\binarySearch($results, $id, \nspl\op\methodCaller('getId'));
if ($idx === false) {
continue;
}
$orderedResult[] = $results[$idx];
}
return $orderedResult;
}
/**
* Get documents by given ids for specified query.
*
* @param array $ids Array of document ids.
*
* @return Document[]
*/
public function getByIds(array $ids)
{
$expr = $this->_em->getExpressionBuilder();
return $this->createQueryBuilder('Document')
->addSelect('Comment, CommentAuthor')
->where($expr->in('Document.id', $ids))
->leftJoin('Document.comments', 'Comment', Join::WITH, $expr->andX(
$expr->eq('Comment.document', 'Document.id'),
$expr->eq('Comment.new', 1)
))
->leftJoin('Comment.author', 'CommentAuthor')
->addOrderBy('Comment.createdAt', 'desc')
->getQuery()
->getResult();
}
/**
* @param array $fields Array of required fields names, `id` return
* always.
* @param array $ids Array of document ids.
*
* @return Document[]
*/
public function getWithFieldsByIds(array $fields, array $ids)
{
return $this->createQueryBuilder('Document')
->select('partial Document.{id, '.implode(',', $fields).'}')
->where('Document.id IN (:ids)')
->setParameter('ids', $ids)
->getQuery()
->getResult();
}
/**
* Check whether the documents exists.
*
* @param string[] $checkedIds Array of document ids.
*
* @return string[] Array of not exists ids from passed.
*/
public function checkIds(array $checkedIds)
{
$expr = $this->_em->getExpressionBuilder();
$existsIds = $this->createQueryBuilder('Document')
->select('Document.id')
->where($expr->in('Document.id', array_map(\nspl\op\str, $checkedIds)))
->getQuery()
->getArrayResult();
return array_diff($checkedIds, \nspl\a\flatten($existsIds));
}
/**
* Remove from provided ids whose document id which already exists in specified document collection.
*
* @param string $collectionId A DocumentCollectionInterface entity id.
* @param string $collectionType A DocumentCollectionInterface type.
* @param array $ids Array of document ids.
*
* @return string[] Array of documents which is not exists in specified document collection.
*/
public function sanitizeIds($collectionId, $collectionType, array $ids)
{
$expr = $this->_em->getExpressionBuilder();
$condition = $expr->andX($expr->in('Document.id', array_map(\nspl\op\str, $ids)));
switch ($collectionType) {
case CollectionTypeEnum::FEED:
$condition->add($expr->eq('Page.clipFeed', ':collectionId'));
break;
case CollectionTypeEnum::QUERY:
$condition->add($expr->eq('Page.query', ':collectionId'));
break;
default:
throw new \InvalidArgumentException('Invalid collection type.');
}
$existsIds = $this->createQueryBuilder('Document')
->select('Document.id')
->join('Document.pages', 'Page')
->where($condition)
->setParameter('collectionId', $collectionId)
->getQuery()
->getArrayResult();
return array_diff($ids, \nspl\a\flatten($existsIds));
}
/**
* @param array $queryId
* @return array
*/
public function getByQuery(array $queryId)
{
return $this->createQueryBuilder('Document')
->select('Document.data','Query.id')
->join('Document.pages', 'Page')
->join('Page.query', 'Query')
->where('Query.id IN (:queryId)')
->setParameter('queryId', $queryId)
->getQuery()
->getResult();
}
/**
* @param array $clipFeedId
* @return array
*/
public function getByClip(array $clipFeedId)
{
return $this->createQueryBuilder('Document')
->select('Document.data','IDENTITY(Page.clipFeed) as clipFeedId ')
->join('Document.pages', 'Page')
->where('Page.clipFeed IN (:clipFeedId)')
->setParameter('clipFeedId', $clipFeedId)
->getQuery()
->getResult();
}
}
@@ -0,0 +1,70 @@
<?php
namespace CacheBundle\Repository;
use CacheBundle\Entity\Query\StoredQuery;
use Doctrine\ORM\EntityRepository;
/**
* QueryFeedRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class QueryFeedRepository extends EntityRepository
{
/**
* Get single query feed from repository.
*
* @param integer $id A Feed entity instance id.
* @param integer $user Filter feeds by specified owner if set.
*
* @return \CacheBundle\Entity\Feed\AbstractFeed|null
*/
public function getOne($id, $user)
{
$expr = $this->_em->getExpressionBuilder();
$condition = $expr->andX($expr->eq('Feed.id', ':id'));
$parameters = [ 'id' => $id ];
if ($user !== null) {
$condition->add($expr->eq('Feed.user', ':user'));
$parameters['user'] = $user;
}
return $this->createQueryBuilder('Feed')
->where($condition)
->setParameters($parameters)
->getQuery()
->getOneOrNullResult();
}
/**
* @param integer $user A User entity id.
*
* @return \Doctrine\ORM\QueryBuilder
*/
public function getFeedsForFormQb($user)
{
return $this->createQueryBuilder('ch')
->where('ch.userId = :userId')
->setParameter(':userId', $user);
}
/**
* @param integer $query A stored query instance.
*
* @return StoredQuery[]
*/
public function getWithExcludedDocumentsForQuery($query)
{
return $this->createQueryBuilder('Feed')
->addSelect('partial Document.{id}')
->innerJoin('Feed.excludedDocuments', 'Document')
->where('Feed.query = :query')
->setParameter('query', $query)
->getQuery()
->getResult();
}
}
@@ -0,0 +1,21 @@
<?php
namespace CacheBundle\Repository;
/**
* Interface QueryRepositoryInterface
* @package CacheBundle\Repository
*/
interface QueryRepositoryInterface
{
/**
* Get query entity by internal representation of search query.
*
* @param string $hash A search query hash.
* @param integer $user A User entity id, who made search request.
*
* @return \CacheBundle\Entity\Query\AbstractQuery|null
*/
public function get($hash, $user = null);
}
@@ -0,0 +1,63 @@
<?php
namespace CacheBundle\Repository;
use Doctrine\ORM\EntityRepository;
/**
* Class SimpleQueryRepository
* @package CacheBundle\Repository
*/
class SimpleQueryRepository extends EntityRepository implements
QueryRepositoryInterface
{
/**
* Get query entity by internal representation of search query.
*
* @param string $hash A search query hash.
* @param integer $user A User entity id, who made search request.
*
* @return \CacheBundle\Entity\Query\SimpleQuery|null
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function get($hash, $user = null)
{
$expr = $this->_em->getExpressionBuilder();
return $this->createQueryBuilder('Query')
->select('partial Query.{id, totalCount, expirationDate, raw, rawFilters, rawAdvancedFilters}')
->where($expr->andX(
$expr->eq('Query.hash', ':hash'),
$expr->gt('Query.expirationDate', ':date')
))
->setParameters([
'hash' => $hash,
'date' => date_create(),
])
->getQuery()
->getOneOrNullResult();
}
/**
* Get all old queries.
*
* @return integer[] Old queries ids.
*/
public function getOld()
{
$expr = $this->_em->getExpressionBuilder();
// Get all old queries ids.
$ids = $this->createQueryBuilder('Query')
->select('Query.id')
->where($expr->lte('Query.expirationDate', ':date'))
->setParameter('date', date_create())
->getQuery()
->getArrayResult();
return array_map(function (array $row) {
return $row['id'];
}, $ids);
}
}
@@ -0,0 +1,108 @@
<?php
namespace CacheBundle\Repository;
use CacheBundle\Entity\SourceList;
use Doctrine\ORM\EntityRepository;
/**
* SourceListRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class SourceListRepository extends EntityRepository
{
/**
* Get QueryBuilder for list of sourceLists for the user
*
* @param integer $user A User entity id.
* @param array $order Array of order config where key - is field name
* and value is order direction.
* @param boolean $onlyShared Show only shared source lists if set.
*
* @return \Doctrine\ORM\QueryBuilder
*/
public function getSourcesListsQB($user, array $order = [], $onlyShared = false)
{
$expr = $this->_em->getExpressionBuilder();
$qb = $this->createQueryBuilder('SourceList')
->addSelect('partial User.{id, firstName, lastName}')
->join('SourceList.user', 'User')
->where($expr->eq('SourceList.user', ':user'))
->setParameter(':user', $user);
if ($onlyShared) {
$qb->andWhere($expr->eq('SourceList.isGlobal', 1));
} else {
$qb->orWhere($expr->eq('SourceList.isGlobal', 1));
}
foreach ($order as $field => $direction) {
$qb->addOrderBy("SourceList.{$field}", $direction);
}
return $qb;
}
/**
* Get concrete SourceLists for the user.
*
* @param integer $id A SourceList entity id.
* @param integer $user A User entity id.
*
* @return SourceList|null
*/
public function getSourcesLists($id, $user)
{
$expr = $this->_em->getExpressionBuilder();
return $this->getSourcesListsQB($user)
->andWhere($expr->eq('SourceList.id', ':id'))
->setParameter('id', $id)
->getQuery()
->getOneOrNullResult();
}
/**
* Remove all source list ids which not exists, not global or not owned by
* specified user.
*
* @param array $ids List of requested source list ids.
*
* @param integer $user A User entity id.
*
* @return integer[]
*/
public function sanitizeIds(array $ids, $user)
{
$expr = $this->_em->getExpressionBuilder();
return array_map(function (array $result) {
return $result['id'];
}, $this->getSourcesListsQB($user)
->select('SourceList.id')
->andWhere($expr->in('SourceList', ':ids'))
->setParameter('ids', $ids)
->getQuery()
->getArrayResult());
}
/**
* @param integer $user A User entity id.
*
* @return integer[]
*/
public function getAvailableIdsForUser($user)
{
return \nspl\a\map(
\nspl\op\itemGetter('id'),
$this->getSourcesListsQB($user)
->select('SourceList.id')
->getQuery()
->getArrayResult()
);
}
}
@@ -0,0 +1,80 @@
<?php
namespace CacheBundle\Repository;
use CacheBundle\Entity\Query\StoredQuery;
use Common\Enum\StoredQueryStatusEnum;
use Doctrine\ORM\EntityRepository;
/**
* Class SimpleQueryRepository
* @package CacheBundle\Repository
*/
class StoredQueryRepository extends EntityRepository implements
QueryRepositoryInterface
{
/**
* Get query entity by internal representation of search query.
*
* @param string $hash A search query hash.
* @param integer $user A User entity id, who made search request.
*
* @return \CacheBundle\Entity\Query\StoredQuery|null
*/
public function get($hash, $user = null)
{
$expr = $this->_em->getExpressionBuilder();
$condition = $expr->andX($expr->eq('Query.hash', ':hash'));
$parameters = [ 'hash' => $hash ];
if ($user !== null) {
$condition->add($expr->eq('Query.user', ':user'));
$parameters['user'] = $user;
}
return $this->createQueryBuilder('Query')
->select('partial Query.{id, totalCount}')
->where($condition)
->setParameters($parameters)
->getQuery()
->getOneOrNullResult();
}
/**
* List stored queries ready for updating.
*
* @return \Doctrine\ORM\QueryBuilder
*/
public function getForUpdating()
{
$expr = $this->_em->getExpressionBuilder();
return $this->createQueryBuilder('Query')
->distinct('Query.id')
->join('Query.feeds', 'feeds')
->where($expr->andX(
$expr->neq('Query.status', ':status'),
$expr->eq('Query.limitExceed', 0)
))
->setParameter('status', StoredQueryStatusEnum::INITIALIZE);
}
/**
* Get Query by feed
*
* @param integer $feed A Feed entity id.
*
* @return StoredQuery
*/
public function getByFeed($feed)
{
return $this->createQueryBuilder('Query')
->leftJoin('Query.feeds', 'feeds')
->where('feeds.id = :feedId')
->setParameter(':feedId', $feed)
->getQuery()
->getOneOrNullResult();
}
}
@@ -0,0 +1,13 @@
<?php
namespace CacheBundle\Repository;
/**
* UserStoredQueryRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class UserStoredQueryRepository extends \Doctrine\ORM\EntityRepository
{
}