src/Repository/UserRepository.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Repository;
  3. use App\Entity\User;
  4. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  5. use Doctrine\Persistence\ManagerRegistry;
  6. use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
  7. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  8. use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;
  9. /**
  10.  * @method User|null find($id, $lockMode = null, $lockVersion = null)
  11.  * @method User|null findOneBy(array $criteria, array $orderBy = null)
  12.  * @method User[]    findAll()
  13.  * @method User[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  14.  */
  15. class UserRepository extends ServiceEntityRepository implements PasswordUpgraderInterface
  16. {
  17.     public function __construct(ManagerRegistry $registry)
  18.     {
  19.         parent::__construct($registryUser::class);
  20.     }
  21.     /**
  22.      * Used to upgrade (rehash) the user's password automatically over time.
  23.      */
  24.     public function upgradePassword(PasswordAuthenticatedUserInterface $userstring $newHashedPassword): void
  25.     {
  26.         if (!$user instanceof User) {
  27.             throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.'\get_class($user)));
  28.         }
  29.         $user->setPassword($newHashedPassword);
  30.         $this->_em->persist($user);
  31.         $this->_em->flush();
  32.     }
  33.     public function findNotAdmin($type null)
  34.     {
  35.         $query $this->createQueryBuilder('u');
  36.         if($type !== null && in_array($type, ['freelance','society'])) {
  37.             $query->andWhere('u.type = :type')
  38.                 ->setParameter('type'$type);
  39.         } else {
  40.             $query->where('u.type != :type')
  41.                 ->setParameter('type''admin');
  42.         }
  43.         return $query
  44.             ->orderBy('u.createdAt''desc')
  45.             ->getQuery()
  46.             ->getResult();
  47.     }
  48.     public function countUserNotVerify()
  49.     {
  50.         return $this->createQueryBuilder('u')
  51.             ->select('count(u.id)')
  52.             ->where('u.isVerified = :is_verified' )
  53.             ->andWhere('u.type = :type')
  54.             ->setParameters([
  55.                 'type' => 'society',
  56.                 'is_verified' => false
  57.             ])
  58.             ->getQuery()
  59.             ->getSingleScalarResult();
  60.     }
  61.     // /**
  62.     //  * @return User[] Returns an array of User objects
  63.     //  */
  64.     /*
  65.     public function findByExampleField($value)
  66.     {
  67.         return $this->createQueryBuilder('u')
  68.             ->andWhere('u.exampleField = :val')
  69.             ->setParameter('val', $value)
  70.             ->orderBy('u.id', 'ASC')
  71.             ->setMaxResults(10)
  72.             ->getQuery()
  73.             ->getResult()
  74.         ;
  75.     }
  76.     */
  77.     /*
  78.     public function findOneBySomeField($value): ?User
  79.     {
  80.         return $this->createQueryBuilder('u')
  81.             ->andWhere('u.exampleField = :val')
  82.             ->setParameter('val', $value)
  83.             ->getQuery()
  84.             ->getOneOrNullResult()
  85.         ;
  86.     }
  87.     */
  88. }