mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-15 05:53:13 +00:00
99 lines
2.6 KiB
PHP
99 lines
2.6 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of Phraseanet
|
|
*
|
|
* (c) 2005-2014 Alchemy
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Alchemy\Phrasea\Model\Repositories;
|
|
|
|
use Doctrine\ORM\EntityRepository;
|
|
|
|
/**
|
|
* RegistrationDemandRepository
|
|
*
|
|
* This class was generated by the Doctrine ORM. Add your own custom
|
|
* repository methods below.
|
|
*/
|
|
class RegistrationDemandRepository extends EntityRepository
|
|
{
|
|
/**
|
|
* Displays demands for user on provided collection.
|
|
*
|
|
* @param \User_Adapter $user
|
|
* @param array $baseList
|
|
*
|
|
* @return array
|
|
*/
|
|
public function getDemandsForUser(\User_Adapter $user, $baseList = [])
|
|
{
|
|
$qb = $this->createQueryBuilder('d');
|
|
$qb->where($qb->expr()->eq('d.user', ':user'));
|
|
$qb->setParameter(':user', $user->get_id());
|
|
|
|
if (count($baseList) > 0) {
|
|
$qb->andWhere('d.baseId IN (:bases)');
|
|
$qb->setParameter(':bases', $baseList);
|
|
}
|
|
|
|
$qb->orderBy('d.created', 'DESC');
|
|
|
|
return $qb->getQuery()->getResult();
|
|
}
|
|
|
|
/**
|
|
* Deletes demands for user on collection.
|
|
*
|
|
* @param \User_Adapter $user
|
|
* @param array $baseList
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function deleteUserDemands(\User_Adapter $user, $baseList = [])
|
|
{
|
|
$qb = $this->createQueryBuilder('d');
|
|
$qb->delete('Alchemy\Phrasea\Model\Entities\RegistrationDemand', 'd');
|
|
$qb->where($qb->expr()->eq('d.user', ':user'));
|
|
$qb->setParameter(':user', $user->get_id());
|
|
|
|
if (count($baseList) > 0) {
|
|
$qb->andWhere('d.baseId IN (:bases)');
|
|
$qb->setParameter(':bases', $baseList);
|
|
}
|
|
|
|
return $qb->getQuery()->execute();
|
|
}
|
|
|
|
/**
|
|
* Deletes outdated demands.
|
|
*
|
|
* @param string $limit
|
|
*/
|
|
public function deleteDemandsOldestThan($limit = '-1 month')
|
|
{
|
|
$qb = $this->createQueryBuilder('d');
|
|
$qb->delete('Alchemy\Phrasea\Model\Entities\RegistrationDemand', 'd');
|
|
$qb->where($qb->expr()->lt('d.created', ':date'));
|
|
$qb->setParameter(':date', new \DateTime($limit));
|
|
$qb->getQuery()->execute();
|
|
}
|
|
|
|
/**
|
|
* Deletes demands on collection.
|
|
*
|
|
* @param $baseId
|
|
*/
|
|
public function deleteDemandsOnCollection($baseId)
|
|
{
|
|
$qb = $this->createQueryBuilder('d');
|
|
$qb->delete('Alchemy\Phrasea\Model\Entities\RegistrationDemand', 'd');
|
|
$qb->where($qb->expr()->eq('d.baseId', ':base'));
|
|
$qb->setParameter(':base', $baseId);
|
|
$qb->getQuery()->execute();
|
|
}
|
|
}
|