fix
Some checks failed
/ ls (pull_request) Has been cancelled

This commit is contained in:
lubiana 2025-01-25 03:17:07 +01:00
parent 7b95ed44ee
commit b0f945f275
Signed by: lubiana
SSH key fingerprint: SHA256:vW1EA0fRR3Fw+dD/sM0K+x3Il2gSry6YRYHqOeQwrfk

View file

@ -12,8 +12,11 @@ use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;
use function assert;
final class MenuItemType extends AbstractType final class MenuItemType extends AbstractType
{ {
#[Override]
public function buildForm(FormBuilderInterface $builder, array $options): void public function buildForm(FormBuilderInterface $builder, array $options): void
{ {
$item = $options['data']; $item = $options['data'];
@ -22,35 +25,38 @@ final class MenuItemType extends AbstractType
$builder->add('name'); // Basic field $builder->add('name'); // Basic field
$builder->add('aliases', EntityType::class, [ $builder->add('aliases', EntityType::class, [
'class' => MenuItem::class, 'class' => MenuItem::class,
'choice_label' => 'name', 'choice_label' => 'name',
'multiple' => true, 'multiple' => true,
'expanded' => true, 'expanded' => true,
'query_builder' => static function (MenuItemRepository $repository) use ($item, $vendorId): QueryBuilder { 'query_builder' => static function (MenuItemRepository $repository) use ($item, $vendorId): QueryBuilder {
$qb = $repository->createQueryBuilder('m'); $qb = $repository->createQueryBuilder('m');
// Build the main query with a NOT EXISTS constraint // Build the main query with a NOT EXISTS constraint
$qb $qb
->where('m.foodVendor = :vendorId') ->where('m.foodVendor = :vendorId')
->andWhere('m.deletedAt IS NULL') ->andWhere('m.deletedAt IS NULL')
->andWhere('m.id != :id') ->andWhere('m.id != :id')
->andWhere( ->andWhere(
$qb->expr()->notIn('m.id', $qb->expr()
$repository->createQueryBuilder('m2') ->notIn(
->select('m2.id') 'm.id',
->where('m2.aliasOf != m.id') // Reference m.id in the inner query $repository->createQueryBuilder('m2')
->orWhere('m2.aliasOf IS NOT NULL') ->select('m2.id')
->getDQL() // The subquery's DQL string ->where('m2.aliasOf != m.id') // Reference m.id in the inner query
) ->orWhere('m2.aliasOf IS NOT NULL')
) ->getDQL() // The subquery's DQL string
->orderBy('m.name', 'ASC') )
->setParameter('vendorId', $vendorId, UlidType::NAME) // ULID or appropriate type )
->setParameter('id', $item->getId(), UlidType::NAME); // ULID or appropriate type ->orderBy('m.name', 'ASC')
->setParameter('vendorId', $vendorId, UlidType::NAME) // ULID or appropriate type
->setParameter('id', $item->getId(), UlidType::NAME); // ULID or appropriate type
return $qb; return $qb;
}, },
]); ]);
} }
#[Override] #[Override]
public function configureOptions(OptionsResolver $resolver): void public function configureOptions(OptionsResolver $resolver): void
{ {