add user management
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Security\ApplicationRoles;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
@@ -16,28 +17,42 @@ class UserRepository extends ServiceEntityRepository
|
||||
parent::__construct($registry, User::class);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return User[] Returns an array of User objects
|
||||
// */
|
||||
// public function findByExampleField($value): array
|
||||
// {
|
||||
// return $this->createQueryBuilder('u')
|
||||
// ->andWhere('u.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->orderBy('u.id', 'ASC')
|
||||
// ->setMaxResults(10)
|
||||
// ->getQuery()
|
||||
// ->getResult()
|
||||
// ;
|
||||
// }
|
||||
/**
|
||||
* @return list<User>
|
||||
*/
|
||||
public function findForAdminList(): array
|
||||
{
|
||||
return $this->createQueryBuilder('u')
|
||||
->orderBy('u.email', 'ASC')
|
||||
->getQuery()
|
||||
->getResult();
|
||||
}
|
||||
|
||||
// public function findOneBySomeField($value): ?User
|
||||
// {
|
||||
// return $this->createQueryBuilder('u')
|
||||
// ->andWhere('u.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->getQuery()
|
||||
// ->getOneOrNullResult()
|
||||
// ;
|
||||
// }
|
||||
public function findOneByNormalizedEmail(string $email): ?User
|
||||
{
|
||||
$normalizedEmail = strtolower(trim($email));
|
||||
|
||||
if ($normalizedEmail === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->findOneBy(['email' => $normalizedEmail]);
|
||||
}
|
||||
|
||||
public function countActiveSuperAdmins(?User $exclude = null): int
|
||||
{
|
||||
$count = 0;
|
||||
|
||||
foreach ($this->findBy(['isActive' => true]) as $user) {
|
||||
if ($exclude instanceof User && (string) $user->getId() === (string) $exclude->getId()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (in_array(ApplicationRoles::ROLE_SUPER_ADMIN, $user->getRoles(), true)) {
|
||||
++$count;
|
||||
}
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user