56 lines
1.5 KiB
PHP
56 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Repository;
|
|
|
|
use App\Entity\BookingEditDraft;
|
|
use App\Entity\User;
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
|
use Doctrine\Persistence\ManagerRegistry;
|
|
|
|
/**
|
|
* @extends ServiceEntityRepository<BookingEditDraft>
|
|
*/
|
|
class BookingEditDraftRepository extends ServiceEntityRepository
|
|
{
|
|
public function __construct(ManagerRegistry $registry)
|
|
{
|
|
parent::__construct($registry, BookingEditDraft::class);
|
|
}
|
|
|
|
/**
|
|
* Finds a draft for a specific user and booking combination.
|
|
*
|
|
* @param User $user The user who owns the draft
|
|
* @param int $bookingId The BusProNet booking ID
|
|
*
|
|
* @return BookingEditDraft|null The draft if found, null otherwise
|
|
*/
|
|
public function findByUserAndBooking(User $user, int $bookingId): ?BookingEditDraft
|
|
{
|
|
return $this->findOneBy([
|
|
'user' => $user,
|
|
'bookingId' => $bookingId,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Deletes a draft for a specific user and booking combination.
|
|
*
|
|
* @param User $user The user who owns the draft
|
|
* @param int $bookingId The BusProNet booking ID
|
|
*/
|
|
public function deleteByUserAndBooking(User $user, int $bookingId): void
|
|
{
|
|
$this->createQueryBuilder('d')
|
|
->delete()
|
|
->where('d.user = :user')
|
|
->andWhere('d.bookingId = :bookingId')
|
|
->setParameter('user', $user)
|
|
->setParameter('bookingId', $bookingId)
|
|
->getQuery()
|
|
->execute();
|
|
}
|
|
}
|