mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-11 20:13:28 +00:00
111 lines
2.6 KiB
PHP
111 lines
2.6 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of Phraseanet
|
|
*
|
|
* (c) 2005-2013 Alchemy
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Repositories;
|
|
|
|
use Doctrine\ORM\EntityRepository;
|
|
use Entities\User;
|
|
|
|
/**
|
|
* User
|
|
*
|
|
* This class was generated by the Doctrine ORM. Add your own custom
|
|
* repository methods below.
|
|
*/
|
|
class UserRepository extends EntityRepository
|
|
{
|
|
/**
|
|
* Finds admins
|
|
*
|
|
* @return array
|
|
*/
|
|
public function findAdmins()
|
|
{
|
|
$qb = $this->createQueryBuilder('u');
|
|
|
|
$qb->where($qb->expr()->eq('u.admin', $qb->expr()->literal(true)))
|
|
->andWhere($qb->expr()->isNull('u.modelOf'))
|
|
->andWhere($qb->expr()->eq('u.deleted', $qb->expr()->literal(false)));
|
|
|
|
return $qb->getQuery()->getResult();
|
|
}
|
|
|
|
/**
|
|
* Sets a selection of user
|
|
*
|
|
* @param array $users An array of user
|
|
*
|
|
* @return integer The number of processed rows
|
|
*/
|
|
public function setAdmins(array $users)
|
|
{
|
|
$qb = $this->createQueryBuilder('u');
|
|
|
|
$qb->update('Entities\User', 'u')
|
|
->set('u.admin', $qb->expr()->literal(true))
|
|
->where($qb->expr()->in('u.id', array_map(function($value) {
|
|
if ($value instanceof User) {
|
|
return $value->getId();
|
|
}
|
|
|
|
return (int) $value;
|
|
}, $users)));
|
|
|
|
return $qb->getQuery()->execute();
|
|
}
|
|
|
|
/**
|
|
* Resets all admins
|
|
*
|
|
* @return integer The number of processed rows
|
|
*/
|
|
public function resetAdmins()
|
|
{
|
|
$qb = $this->createQueryBuilder('u');
|
|
|
|
$qb->update('Entities\User', 'u')
|
|
->set('u.admin', $qb->expr()->literal(false))
|
|
->where($qb->expr()->eq('u.admin', $qb->expr()->literal(true)));
|
|
|
|
return $qb->getQuery()->execute();
|
|
}
|
|
|
|
/**
|
|
* Finds a user by login
|
|
*
|
|
* @param string $login
|
|
*
|
|
* @return null|User
|
|
*/
|
|
public function findByLogin($login)
|
|
{
|
|
return $this->findOneBy(array('login' => $login));
|
|
}
|
|
|
|
/**
|
|
* Finds a user by email
|
|
*
|
|
* @param string $email
|
|
*
|
|
* @return null|User
|
|
*/
|
|
public function findByEmail($email)
|
|
{
|
|
$qb = $this->createQueryBuilder('u');
|
|
|
|
$qb->where($qb->expr()->eq('u.email', $email))
|
|
->andWhere($qb->expr()->isNotNull('u.email'))
|
|
->andWhere($qb->expr()->eq('u.deleted', $qb->expr()->literal(false)));
|
|
|
|
return $qb->getQuery()->getOneOrNullResult();
|
|
}
|
|
}
|