99 lines
2.5 KiB
PHP
99 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Repository;
|
|
|
|
use App\Entity\Demande;
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
|
use Doctrine\Persistence\ManagerRegistry;
|
|
|
|
/**
|
|
* @extends ServiceEntityRepository<Demande>
|
|
*/
|
|
class DemandeRepository extends ServiceEntityRepository
|
|
{
|
|
public function __construct(ManagerRegistry $registry)
|
|
{
|
|
parent::__construct($registry, Demande::class);
|
|
}
|
|
|
|
/**
|
|
* Find the most recent Demande by query (business name)
|
|
*/
|
|
public function findMostRecentByQuery(string $query): ?Demande
|
|
{
|
|
return $this->createQueryBuilder('d')
|
|
->andWhere('d.query = :query')
|
|
->setParameter('query', $query)
|
|
->orderBy('d.createdAt', 'DESC')
|
|
->setMaxResults(1)
|
|
->getQuery()
|
|
->getOneOrNullResult()
|
|
;
|
|
}
|
|
|
|
/**
|
|
* Find Demandes without an email
|
|
*/
|
|
public function findWithoutEmail(): array
|
|
{
|
|
return $this->createQueryBuilder('d')
|
|
->andWhere('d.email IS NULL')
|
|
->orderBy('d.createdAt', 'DESC')
|
|
->getQuery()
|
|
->getResult()
|
|
;
|
|
}
|
|
|
|
/**
|
|
* Find Demandes by status
|
|
*/
|
|
public function findByStatus(string $status): array
|
|
{
|
|
return $this->createQueryBuilder('d')
|
|
->andWhere('d.status = :status')
|
|
->setParameter('status', $status)
|
|
->orderBy('d.createdAt', 'DESC')
|
|
->getQuery()
|
|
->getResult()
|
|
;
|
|
}
|
|
|
|
/**
|
|
* Find Demandes with a Place UUID
|
|
*/
|
|
public function findWithPlaceUuid(): array
|
|
{
|
|
return $this->createQueryBuilder('d')
|
|
->andWhere('d.placeUuid IS NOT NULL')
|
|
->orderBy('d.createdAt', 'DESC')
|
|
->getQuery()
|
|
->getResult()
|
|
;
|
|
}
|
|
|
|
/**
|
|
* Find all Demandes in reverse chronological order
|
|
*/
|
|
public function findAllOrderedByCreatedAt(): array
|
|
{
|
|
return $this->createQueryBuilder('d')
|
|
->orderBy('d.createdAt', 'DESC')
|
|
->getQuery()
|
|
->getResult()
|
|
;
|
|
}
|
|
|
|
/**
|
|
* Find Places that have been contacted, ordered by last contact attempt
|
|
*/
|
|
public function findPlacesWithContactAttempt(): array
|
|
{
|
|
return $this->createQueryBuilder('d')
|
|
->andWhere('d.lastContactAttempt IS NOT NULL')
|
|
->andWhere('d.place IS NOT NULL')
|
|
->orderBy('d.lastContactAttempt', 'DESC')
|
|
->getQuery()
|
|
->getResult()
|
|
;
|
|
}
|
|
}
|