55 lines
1.4 KiB
PHP
55 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Repository\Groups;
|
|
|
|
use App\Entity\Groups\ContingentSyncState;
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
|
use Doctrine\Persistence\ManagerRegistry;
|
|
|
|
/**
|
|
* @extends ServiceEntityRepository<ContingentSyncState>
|
|
*/
|
|
class ContingentSyncStateRepository extends ServiceEntityRepository
|
|
{
|
|
public function __construct(ManagerRegistry $registry)
|
|
{
|
|
parent::__construct($registry, ContingentSyncState::class);
|
|
}
|
|
|
|
public function findOneByHotelCode(string $hotelCode): ?ContingentSyncState
|
|
{
|
|
return $this->findOneBy(['hotelCode' => $hotelCode]);
|
|
}
|
|
|
|
/**
|
|
* @return array<string, ContingentSyncState>
|
|
*/
|
|
public function findAllIndexedByHotelCode(): array
|
|
{
|
|
$indexed = [];
|
|
|
|
foreach ($this->findAll() as $state) {
|
|
$indexed[(string) $state->getHotelCode()] = $state;
|
|
}
|
|
|
|
return $indexed;
|
|
}
|
|
|
|
/**
|
|
* Drops the sync state of every hotel code that is no longer synced.
|
|
*
|
|
* @param non-empty-list<string> $hotelCodes the codes that are still synced
|
|
*/
|
|
public function deleteExceptHotelCodes(array $hotelCodes): int
|
|
{
|
|
return (int) $this->createQueryBuilder('s')
|
|
->delete()
|
|
->where('s.hotelCode NOT IN (:hotelCodes)')
|
|
->setParameter('hotelCodes', $hotelCodes)
|
|
->getQuery()
|
|
->execute();
|
|
}
|
|
}
|