71 lines
2.1 KiB
PHP
71 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Repository;
|
|
|
|
use App\Entity\Bucket;
|
|
use App\Entity\Scenario;
|
|
use App\Enum\BucketType;
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
|
use Doctrine\Persistence\ManagerRegistry;
|
|
use Symfony\Component\Uid\UuidV7;
|
|
|
|
/**
|
|
* @extends ServiceEntityRepository<Bucket>
|
|
*/
|
|
class BucketRepository extends ServiceEntityRepository
|
|
{
|
|
public function __construct(ManagerRegistry $registry)
|
|
{
|
|
parent::__construct($registry, Bucket::class);
|
|
}
|
|
|
|
public function countOverflowBucketsForScenario(Scenario $scenario, ?UuidV7 $excludeId = null): int
|
|
{
|
|
$qb = $this->createQueryBuilder('b')
|
|
->select('COUNT(b.id)')
|
|
->andWhere('b.scenario = :scenario')
|
|
->andWhere('b.type = :overflow')
|
|
->setParameter('scenario', $scenario)
|
|
->setParameter('overflow', BucketType::OVERFLOW);
|
|
|
|
if (null !== $excludeId) {
|
|
$qb->andWhere('b.id != :excludeId')
|
|
->setParameter('excludeId', $excludeId, 'uuid');
|
|
}
|
|
|
|
return (int) $qb->getQuery()->getSingleScalarResult();
|
|
}
|
|
|
|
/**
|
|
* @return array<int, Bucket>
|
|
*/
|
|
public function findByScenarioOrderedByPriority(Scenario $scenario): array
|
|
{
|
|
return $this->createQueryBuilder('b')
|
|
->where('b.scenario = :scenario')
|
|
->setParameter('scenario', $scenario)
|
|
->orderBy('b.priority', 'ASC')
|
|
->getQuery()
|
|
->execute();
|
|
}
|
|
|
|
public function countBucketsWithPriorityForScenario(
|
|
Scenario $scenario,
|
|
int $priority,
|
|
?UuidV7 $excludeId = null,
|
|
): int {
|
|
$qb = $this->createQueryBuilder('b')
|
|
->select('COUNT(b.id)')
|
|
->andWhere('b.scenario = :scenario')
|
|
->andWhere('b.priority = :priority')
|
|
->setParameter('scenario', $scenario)
|
|
->setParameter('priority', $priority);
|
|
|
|
if (null !== $excludeId) {
|
|
$qb->andWhere('b.id != :excludeId')
|
|
->setParameter('excludeId', $excludeId, 'uuid');
|
|
}
|
|
|
|
return (int) $qb->getQuery()->getSingleScalarResult();
|
|
}
|
|
}
|