mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-12 12:33:26 +00:00
82 lines
2.0 KiB
PHP
82 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace Repositories;
|
|
|
|
use Alchemy\Phrasea\Application;
|
|
use Doctrine\ORM\EntityRepository;
|
|
|
|
/**
|
|
* SessionRepository
|
|
*
|
|
* This class was generated by the Doctrine ORM. Add your own custom
|
|
* repository methods below.
|
|
*/
|
|
class SessionRepository extends EntityRepository
|
|
{
|
|
|
|
/**
|
|
*
|
|
* @param User_Adapter $user
|
|
* @return \Doctrine\Common\Collections\Collection
|
|
*/
|
|
public function getAllForUser(\User_Adapter $user)
|
|
{
|
|
$base_ids = array_keys($user->ACL()->get_granted_base());
|
|
|
|
$dql = 'SELECT f FROM Entities\Feed f
|
|
WHERE f.base_id IS NULL ';
|
|
|
|
if (count($base_ids) > 0) {
|
|
$dql .= ' OR f.base_id
|
|
IN (' . implode(', ', $base_ids) . ') ';
|
|
}
|
|
|
|
$dql .= ' OR f.public = true
|
|
ORDER BY f.updated_on DESC';
|
|
|
|
$query = $this->_em->createQuery($dql);
|
|
$feeds = $query->getResult();
|
|
|
|
return $feeds;
|
|
}
|
|
|
|
public function findAllPublic()
|
|
{
|
|
$dql = 'SELECT f FROM Entities\Feed f
|
|
WHERE f.public = true
|
|
ORDER BY f.updated_on DESC';
|
|
|
|
$query = $this->_em->createQuery($dql);
|
|
$feeds = $query->getResult();
|
|
|
|
return $feeds;
|
|
}
|
|
|
|
public function loadWithUser(Application $app, \User_Adapter $user, $id)
|
|
{
|
|
$feed = $this->find($id);
|
|
if ($feed) {
|
|
$coll = $feed->getCollection($app);
|
|
if ($feed->isPublic()
|
|
|| $coll === null
|
|
|| in_array($coll->get_base_id(), array_keys($user->ACL()->get_granted_base()))) {
|
|
return $feed;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public function findByIdArray(array $feed_id)
|
|
{
|
|
$dql = 'SELECT f FROM Entities\Feed f
|
|
ORDER BY f.created_on DESC
|
|
WHERE f.id IN (' . implode(",", $feed_id) . ')';
|
|
|
|
$query = $this->_em->createQuery($dql);
|
|
$feeds = $query->getResult();
|
|
|
|
return $feeds;
|
|
}
|
|
}
|