Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

40 lines
1.2KB

  1. <?php
  2. namespace Lc\SovBundle\Repository\User;
  3. use App\Entity\User\User;
  4. use Doctrine\Persistence\ManagerRegistry;
  5. use Lc\SovBundle\Repository\AbstractRepository;
  6. use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
  7. use Symfony\Component\Security\Core\User\UserInterface as SfUserInterface;
  8. class UserRepository extends AbstractRepository
  9. {
  10. public function __construct(ManagerRegistry $registry)
  11. {
  12. parent::__construct($registry, User::class);
  13. }
  14. /**
  15. * Used to upgrade (rehash) the user's password automatically over time.
  16. */
  17. public function upgradePassword(SfUserInterface $user, string $newEncodedPassword): void
  18. {
  19. if (!$user instanceof SfUserInterface) {
  20. throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', \get_class($user)));
  21. }
  22. $user->setPassword($newEncodedPassword);
  23. $this->_em->persist($user);
  24. $this->_em->flush();
  25. }
  26. public function findByRole($role) {
  27. return $this->createQueryBuilder('u')
  28. ->andWhere('u.roles LIKE :role')
  29. ->setParameter('role', '%'.$role.'%')
  30. ->getQuery()
  31. ->getResult();
  32. }
  33. }