fix available dependances field issue and change constraintes
All checks were successful
Build & Deploy / Validation, build et push (push) Successful in 8m16s
All checks were successful
Build & Deploy / Validation, build et push (push) Successful in 8m16s
This commit is contained in:
parent
ee08bcecf0
commit
c38193dc7f
2 changed files with 28 additions and 3 deletions
|
|
@ -30,13 +30,12 @@ class ModType extends AbstractType
|
||||||
$mods = $this->modRepository->findAvailableDependances($builder->getData());
|
$mods = $this->modRepository->findAvailableDependances($builder->getData());
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$mods = $this->modRepository->findAll();
|
$mods = $this->modRepository->findBy(array(), array('nom' => 'ASC'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$builder
|
$builder
|
||||||
->add('nom', TextType::class, [
|
->add('nom', TextType::class, [
|
||||||
'disabled' => $isEdit,
|
|
||||||
'label' => 'Nom du mod',
|
'label' => 'Nom du mod',
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'attr' => [
|
'attr' => [
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ class ModRepository extends ServiceEntityRepository
|
||||||
{
|
{
|
||||||
$excludedIds = [];
|
$excludedIds = [];
|
||||||
if ($mod !== null) {
|
if ($mod !== null) {
|
||||||
$excludedIds = $this->collectDependencyIds($mod, []);
|
$excludedIds = $this->collectDependentIds($mod, []);
|
||||||
$excludedIds[] = $mod->getId();
|
$excludedIds[] = $mod->getId();
|
||||||
}
|
}
|
||||||
$qb = $this->createQueryBuilder('m');
|
$qb = $this->createQueryBuilder('m');
|
||||||
|
|
@ -63,6 +63,32 @@ class ModRepository extends ServiceEntityRepository
|
||||||
return $ids;
|
return $ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collecte récursivement les IDs de tous les mods qui dépendent du mod donné
|
||||||
|
* (dépendances inverses, directes ou indirectes), via la relation `soumis`.
|
||||||
|
*
|
||||||
|
* @param int[] $visited IDs déjà visités (évite les boucles infinies)
|
||||||
|
* @return int[]
|
||||||
|
*/
|
||||||
|
private function collectDependentIds(Mod $mod, array $visited): array
|
||||||
|
{
|
||||||
|
$ids = [];
|
||||||
|
|
||||||
|
foreach ($mod->getSoumis() as $dependent) {
|
||||||
|
$depId = $dependent->getId();
|
||||||
|
|
||||||
|
// Evite les boucles infinies en cas de dépendants cycliques
|
||||||
|
if (in_array($depId, $visited, true)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$visited[] = $depId;
|
||||||
|
$ids[] = $depId;
|
||||||
|
$ids = array_merge($ids, $this->collectDependentIds($dependent, $visited));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ids;
|
||||||
|
}
|
||||||
|
|
||||||
// /**
|
// /**
|
||||||
// * @return Mod[] Returns an array of Mod objects
|
// * @return Mod[] Returns an array of Mod objects
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue