mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 15:03:25 +00:00
Add FeedRepository method to filter Feeds by ACL
This commit is contained in:
@@ -25,6 +25,9 @@ class FeedRepository extends EntityRepository
|
||||
/**
|
||||
* Returns all the feeds a user can access.
|
||||
*
|
||||
* @param \ACL $userACL
|
||||
* @param array $restrictions
|
||||
*
|
||||
* @return Feed[]
|
||||
*/
|
||||
public function getAllForUser(\ACL $userACL, array $restrictions = [])
|
||||
@@ -58,7 +61,7 @@ class FeedRepository extends EntityRepository
|
||||
* Returns all the feeds from a given array containing their id.
|
||||
*
|
||||
* @param array $feedIds
|
||||
* @return Collection
|
||||
* @return Feed[]
|
||||
*/
|
||||
public function findByIds(array $feedIds)
|
||||
{
|
||||
@@ -72,4 +75,39 @@ class FeedRepository extends EntityRepository
|
||||
|
||||
return $qb->getQuery()->getResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all the feeds from a given array containing their id.
|
||||
*
|
||||
* @param \ACL $userACL
|
||||
* @param array $feedIds
|
||||
*
|
||||
* @return Feed[]
|
||||
*/
|
||||
public function filterUserAccessibleByIds(\ACL $userACL, array $feedIds)
|
||||
{
|
||||
$qb = $this->createQueryBuilder('f');
|
||||
|
||||
// is public feed?
|
||||
$orx = $qb->expr()->orX(
|
||||
$qb->expr()->isNull('f.baseId'),
|
||||
$qb->expr()->eq('f.public', $qb->expr()->literal(true))
|
||||
);
|
||||
|
||||
// is granted base?
|
||||
$grantedBases = array_keys($userACL->get_granted_base());
|
||||
if ($grantedBases) {
|
||||
$orx->add($qb->expr()->in('f.baseId', $grantedBases));
|
||||
}
|
||||
|
||||
if (empty($feedIds)) {
|
||||
throw new \LogicException('At least one feed id should be provided');
|
||||
}
|
||||
|
||||
$qb->where($qb->expr()->in('f.id', $feedIds), $orx);
|
||||
|
||||
$qb->orderBy('f.updatedOn', 'DESC');
|
||||
|
||||
return $qb->getQuery()->getResult();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user