UserRepository.php 1.35 KB
Newer Older
1 2 3
<?php

namespace PotageBundle\Repository;
4 5
use Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface;
use Symfony\Component\Security\Core\User\UserInterface;
6 7 8 9 10 11 12

/**
 * UserRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
13
class UserRepository extends \Doctrine\ORM\EntityRepository implements UserLoaderInterface
14
{
15 16 17 18
    
    /**
     * Dans security, je ne peux me référer à une propriété, puisque token_key est un array sérialisé
     * cfr. https://symfony.com/doc/3.4/security/entity_provider.html#using-a-custom-query-to-load-the-user
Mat's avatar
Mat committed
19
     * TODO vérifier si y a pas mieux que le LIKE
20 21 22 23 24 25 26 27 28 29 30 31 32 33
     *
     * @param $tokenkey
     * @return UserInterface|null
     * @throws \Doctrine\ORM\NonUniqueResultException
     */
    public function loadUserByUsername($tokenkey)
    {
        return $this->createQueryBuilder('u')
            ->where('u.tokenKey LIKE :tokenkey')
            ->setParameter('tokenkey', '%'.$tokenkey.'%')
            ->getQuery()
            ->getOneOrNullResult();
    }
    
34 35 36 37 38 39 40 41 42 43 44 45 46 47
    
    /**
     * Retourne la colonne des token_keys de tous les users
     * @return array
     */
    public function findAllTokenKeys()
    {
        return $this->createQueryBuilder('u')
            ->select('u.id', 'u.tokenKey')
            ->getQuery()
            ->getResult();
        
    }
    
48
}