refactor(machines) : update structure controller to use ConstructeurLinks
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -9,6 +9,7 @@ use App\Entity\CustomField;
|
||||
use App\Entity\CustomFieldValue;
|
||||
use App\Entity\Machine;
|
||||
use App\Entity\MachineComponentLink;
|
||||
use App\Entity\MachineConstructeurLink;
|
||||
use App\Entity\MachinePieceLink;
|
||||
use App\Entity\MachineProductLink;
|
||||
use App\Entity\ModelType;
|
||||
@@ -138,9 +139,13 @@ class MachineStructureController extends AbstractController
|
||||
}
|
||||
$newMachine->setPrix($source->getPrix());
|
||||
|
||||
// Copy constructeurs
|
||||
foreach ($source->getConstructeurs() as $constructeur) {
|
||||
$newMachine->getConstructeurs()->add($constructeur);
|
||||
// Copy constructeur links
|
||||
foreach ($source->getConstructeurLinks() as $link) {
|
||||
$newLink = new MachineConstructeurLink();
|
||||
$newLink->setMachine($newMachine);
|
||||
$newLink->setConstructeur($link->getConstructeur());
|
||||
$newLink->setSupplierReference($link->getSupplierReference());
|
||||
$this->entityManager->persist($newLink);
|
||||
}
|
||||
|
||||
$this->entityManager->persist($newMachine);
|
||||
@@ -586,7 +591,7 @@ class MachineStructureController extends AbstractController
|
||||
'id' => $site->getId(),
|
||||
'name' => $site->getName(),
|
||||
],
|
||||
'constructeurs' => $this->normalizeConstructeurs($machine->getConstructeurs()),
|
||||
'constructeurs' => $this->normalizeConstructeurLinks($machine->getConstructeurLinks()),
|
||||
'customFields' => $this->normalizeCustomFields($machine->getCustomFields()),
|
||||
'documents' => null,
|
||||
'customFieldValues' => $this->normalizeCustomFieldValues($machine->getCustomFieldValues()),
|
||||
@@ -811,15 +816,19 @@ class MachineStructureController extends AbstractController
|
||||
];
|
||||
}
|
||||
|
||||
private function normalizeConstructeurs(Collection $constructeurs): array
|
||||
private function normalizeConstructeurLinks(Collection $constructeurLinks): array
|
||||
{
|
||||
$items = [];
|
||||
foreach ($constructeurs as $constructeur) {
|
||||
foreach ($constructeurLinks as $link) {
|
||||
$items[] = [
|
||||
'id' => $constructeur->getId(),
|
||||
'name' => $constructeur->getName(),
|
||||
'email' => $constructeur->getEmail(),
|
||||
'phone' => $constructeur->getPhone(),
|
||||
'id' => $link->getId(),
|
||||
'constructeur' => [
|
||||
'id' => $link->getConstructeur()->getId(),
|
||||
'name' => $link->getConstructeur()->getName(),
|
||||
'email' => $link->getConstructeur()->getEmail(),
|
||||
'phone' => $link->getConstructeur()->getPhone(),
|
||||
],
|
||||
'supplierReference' => $link->getSupplierReference(),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user