src/Repository/UserRepository.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Repository;
  3. use App\Entity\OrderWarehouse;
  4. use App\Entity\Service;
  5. use App\Entity\User;
  6. use App\Entity\Warehouse;
  7. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  8. use Doctrine\ORM\QueryBuilder;
  9. use Doctrine\Persistence\ManagerRegistry;
  10. use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
  11. use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;
  12. use Symfony\Component\Security\Core\User\UserInterface;
  13. /**
  14.  * @method User|null find($id, $lockMode = null, $lockVersion = null)
  15.  * @method User|null findOneBy(array $criteria, array $orderBy = null)
  16.  * @method User[]    findAll()
  17.  * @method User[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  18.  */
  19. class UserRepository extends ServiceEntityRepository implements PasswordUpgraderInterface
  20. {
  21.     public function __construct(ManagerRegistry $registry)
  22.     {
  23.         parent::__construct($registryUser::class);
  24.     }
  25.     /**
  26.      * Used to upgrade (rehash) the user's password automatically over time.
  27.      */
  28.     public function upgradePassword(UserInterface $userstring $newEncodedPassword): void
  29.     {
  30.         if (!$user instanceof User) {
  31.             throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', \get_class($user)));
  32.         }
  33.         $user->setPassword($newEncodedPassword);
  34.         $this->_em->persist($user);
  35.         $this->_em->flush();
  36.     }
  37.     public function getQueryBuilderUserByOrderWarehouse(OrderWarehouse $orderWarehouse): QueryBuilder
  38.     {
  39.         return $this->createQueryBuilder('user')
  40.             ->innerJoin('user.create_orders''ordersWarehouse')
  41.             ->andWhere('ordersWarehouse = :orderWarehouse')
  42.             ->setParameter('orderWarehouse'$orderWarehouse);
  43.     }
  44.     public function findUsersEmailByWarehouse(Warehouse $orderWarehouse): array
  45.     {
  46.         $qb $this->createQueryBuilder('user')
  47.             ->innerJoin('user.warehouses''ordersWarehouse')
  48.             ->andWhere('ordersWarehouse = :orderWarehouse')
  49.             ->setParameter('orderWarehouse'$orderWarehouse);
  50.         return $qb->getQuery()->execute();
  51.     }
  52.     public function findUsersByRole(string $role): array
  53.     {
  54.         $qb $this->createQueryBuilder('user')
  55.             ->where('user.roles LIKE :role')
  56.             ->setParameter('role''%'.$role.'%');
  57.         return $qb->getQuery()->execute();
  58.     }
  59.     public function findUsersEmailByService(?Service $service): array
  60.     {
  61.         $qb $this->createQueryBuilder('user')
  62.             ->innerJoin('user.services''services')
  63.             ->andWhere('services IN (:service)')
  64.             ->setParameter('service'$service);
  65.         return $qb->getQuery()->execute();
  66.     }
  67.     public function findUserByEmail(string $email): ?User
  68.     {
  69.         return $this->createQueryBuilder('user')
  70.             ->where('user.email = :email')
  71.             ->setParameter('email'$email)
  72.             ->getQuery()
  73.             ->getOneOrNullResult();
  74.     }
  75.     public function persist(User $user): void
  76.     {
  77.         $this->getEntityManager()->persist($user);
  78.         $this->getEntityManager()->flush();
  79.     }
  80. }