mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 15:03:25 +00:00
Fix neutron's comment
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* RegistrationRepository
|
||||
*
|
||||
* This class was generated by the Doctrine ORM. Add your own custom
|
||||
* repository methods below.
|
||||
*/
|
||||
class RegistrationRepository extends EntityRepository
|
||||
{
|
||||
/**
|
||||
* Displays registrations for user on provided collection.
|
||||
*
|
||||
* @param \User_Adapter $user
|
||||
* @param array $baseList
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getRegistrationsForUser(\User_Adapter $user, array $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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets registration registrations for a user.
|
||||
*
|
||||
* @param $usrId
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getRegistrationsSummaryForUser($usrId)
|
||||
{
|
||||
$data = [];
|
||||
$rsm = $this->createResultSetMappingBuilder('d');
|
||||
$rsm->addScalarResult('sbas_id','sbas_id');
|
||||
$rsm->addScalarResult('bas_id','bas_id');
|
||||
$rsm->addScalarResult('dbname','dbname');
|
||||
$rsm->addScalarResult('time_limited', 'time_limited');
|
||||
$rsm->addScalarResult('limited_from', 'limited_from');
|
||||
$rsm->addScalarResult('limited_to', 'limited_to');
|
||||
$rsm->addScalarResult('actif', 'actif');
|
||||
|
||||
$sql = "
|
||||
SELECT dbname, sbas.sbas_id, time_limited,
|
||||
UNIX_TIMESTAMP( limited_from ) AS limited_from,
|
||||
UNIX_TIMESTAMP( limited_to ) AS limited_to,
|
||||
bas.server_coll_id, usr.usr_id, basusr.actif,
|
||||
bas.base_id AS bas_id , " . $rsm->generateSelectClause(['d' => 'd',]) . "
|
||||
FROM (usr, bas, sbas)
|
||||
LEFT JOIN basusr ON ( usr.usr_id = basusr.usr_id AND bas.base_id = basusr.base_id )
|
||||
LEFT JOIN Registration d ON ( d.user_id = usr.usr_id AND bas.base_id = d.base_id )
|
||||
WHERE bas.active = 1 AND bas.sbas_id = sbas.sbas_id
|
||||
AND usr.usr_id = ?
|
||||
AND model_of = 0";
|
||||
|
||||
$query = $this->_em->createNativeQuery($sql, $rsm);
|
||||
$query->setParameter(1, $usrId);
|
||||
|
||||
foreach ($query->getResult() as $row) {
|
||||
$registrationEntity = $row[0];
|
||||
|
||||
$data[$row['sbas_id']][$row['bas_id']] = [
|
||||
'base-id' => $row['bas_id'],
|
||||
'db-name' => $row['dbname'],
|
||||
'active' => (Boolean) $row['actif'],
|
||||
'time-limited' => (Boolean) $row['time_limited'],
|
||||
'in-time' => $row['time_limited'] && ! ($row['limited_from'] >= time() && $row['limited_to'] <= time()),
|
||||
'registration' => $registrationEntity
|
||||
];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user