<?php 
 
namespace App\Repository\System; 
 
use App\Entity\System\User; 
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; 
use Doctrine\Persistence\ManagerRegistry; 
use Symfony\Component\Security\Core\Exception\UnsupportedUserException; 
use Symfony\Component\Security\Core\User\PasswordUpgraderInterface; 
use Symfony\Component\Security\Core\User\UserInterface; 
use Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface; 
 
/** 
 * @method User|null find($id, $lockMode = null, $lockVersion = null) 
 * @method User|null findOneBy(array $criteria, array $orderBy = null) 
 * @method User[]    findAll() 
 * @method User[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) 
 */ 
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(UserInterface $user, string $newEncodedPassword): void 
    { 
        if (!$user instanceof User) { 
            throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', \get_class($user))); 
        } 
 
        $user->setPassword($newEncodedPassword); 
        $this->_em->persist($user); 
        $this->_em->flush(); 
    } 
 
    public function findAllMost() { 
        return $this->createQueryBuilder('f') 
            ->addSelect('f.id, f.uuid, f.task_id, f.test_group, f.keyword, f.searchengine, f.device, f.location, f.type, f.language, f.regular, f.advanced, f.html, f.created') 
            ->orderBy('f.created', 'DESC') 
            ->setMaxResults(100) 
            ->getQuery() 
            ->getResult() 
        ; 
    } 
 
    public function findSafeLeadInfo($leadid) { 
        // Gets information used in campaign not things like passwords, etc. 
        $result = $this->createQueryBuilder('f') 
        ->select('f.id, f.companyname, f.firstname, f.lastname, f.email, f.brand, f.address, f.city, f.state, f.iso, f.zip, f.phone, f.url, f.tagline, f.national, f.local, f.localtarget,  
        f.mr, f.da, f.pa, f.sp, f.keyword1, f.keywordval1, f.keyword2, f.keywordval2, f.keyword3, f.keywordval3, f.keyword4,  
        f.keywordval4, f.keyword5, f.keywordval5, f.keyword6, f.keywordval6, f.keyword7, f.keywordval7, f.keyword8, f.keywordval8,  
        f.keyword9, f.keywordval9, f.keyword10, f.keywordval10') 
        ->andWhere('f.id = :val') 
        ->setParameter('val', $leadid) 
        ->setMaxResults(1) 
        ->getQuery() 
        ->getOneOrNullResult(\Doctrine\ORM\Query::HYDRATE_ARRAY); 
        return $result; 
    } 
 
    // /** 
    //  * @return User[] Returns an array of User objects 
    //  */ 
    /* 
    public function findByExampleField($value) 
    { 
        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() 
        ; 
    } 
    */ 
}