| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 | <?phpnamespace App\Repository;use App\Entity\User;use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;use Doctrine\Persistence\ManagerRegistry;use Symfony\Component\Security\Core\Exception\UnsupportedUserException;use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;/** * @extends ServiceEntityRepository<User> */class UserRepository extends ServiceEntityRepository implements PasswordUpgraderInterface{    public function __construct(ManagerRegistry $registry)    {        parent::__construct($registry, User::class);    }    /**     * Used to upgrade (rehash) the user's password automatically over time.     */    public function upgradePassword(PasswordAuthenticatedUserInterface $user, string $newHashedPassword): void    {        if (!$user instanceof User) {            throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', $user::class));        }        $user->setPassword($newHashedPassword);        $this->getEntityManager()->persist($user);        $this->getEntityManager()->flush();    }    /**     * Who's online     * = dernière action réalisée il y a moins de 5 minutes     */    public function findWhoIsOnline(): array    {        $qb = $this->createQueryBuilder('u')            ->where('u.lastAction > :lastAction')            ->setParameter('lastAction', new \DateTime('-5 minutes'))            ->getQuery();        return $qb->getResult();    }    //    /**    //     * @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()    //        ;    //    }    //    public function findOneBySomeField($value): ?User    //    {    //        return $this->createQueryBuilder('u')    //            ->andWhere('u.exampleField = :val')    //            ->setParameter('val', $value)    //            ->getQuery()    //            ->getOneOrNullResult()    //        ;    //    }}
 |