From 5210e53d73213c6bcb46b62b7254f9dd13637518 Mon Sep 17 00:00:00 2001 From: Matthieu Date: Fri, 13 Mar 2026 13:38:13 +0100 Subject: [PATCH] feat(sync) : add version field and PieceProductSlot entity Co-Authored-By: Claude Opus 4.6 --- src/Entity/Composant.php | 16 +++++ src/Entity/Piece.php | 49 ++++++++++++++ src/Entity/PieceProductSlot.php | 112 ++++++++++++++++++++++++++++++++ src/Entity/Product.php | 16 +++++ 4 files changed, 193 insertions(+) create mode 100644 src/Entity/PieceProductSlot.php diff --git a/src/Entity/Composant.php b/src/Entity/Composant.php index 5762c80..4435b86 100644 --- a/src/Entity/Composant.php +++ b/src/Entity/Composant.php @@ -130,6 +130,10 @@ class Composant #[ORM\OrderBy(['position' => 'ASC'])] private Collection $productSlots; + #[ORM\Column(type: Types::INTEGER, options: ['default' => 1])] + #[Groups(['composant:read'])] + private int $version = 1; + #[ORM\Column(type: Types::DATETIME_IMMUTABLE, name: 'createdAt')] #[Groups(['composant:read'])] private DateTimeImmutable $createdAt; @@ -406,4 +410,16 @@ class Composant return $this; } + + public function getVersion(): int + { + return $this->version; + } + + public function incrementVersion(): static + { + ++$this->version; + + return $this; + } } diff --git a/src/Entity/Piece.php b/src/Entity/Piece.php index 9514ac9..17f5b73 100644 --- a/src/Entity/Piece.php +++ b/src/Entity/Piece.php @@ -114,12 +114,23 @@ class Piece #[ORM\InverseJoinColumn(name: 'product_id', referencedColumnName: 'id', onDelete: 'CASCADE')] private Collection $products; + /** + * @var Collection + */ + #[ORM\OneToMany(targetEntity: PieceProductSlot::class, mappedBy: 'piece', cascade: ['persist', 'remove'], orphanRemoval: true)] + #[ORM\OrderBy(['position' => 'ASC'])] + private Collection $productSlots; + /** * @var Collection */ #[ORM\OneToMany(mappedBy: 'piece', targetEntity: MachinePieceLink::class)] private Collection $machineLinks; + #[ORM\Column(type: Types::INTEGER, options: ['default' => 1])] + #[Groups(['piece:read'])] + private int $version = 1; + #[ORM\Column(type: Types::DATETIME_IMMUTABLE, name: 'createdAt')] #[Groups(['piece:read'])] private DateTimeImmutable $createdAt; @@ -136,6 +147,7 @@ class Piece $this->documents = new ArrayCollection(); $this->customFieldValues = new ArrayCollection(); $this->products = new ArrayCollection(); + $this->productSlots = new ArrayCollection(); $this->machineLinks = new ArrayCollection(); } @@ -287,4 +299,41 @@ class Piece return $this; } + + /** + * @return Collection + */ + public function getProductSlots(): Collection + { + return $this->productSlots; + } + + public function addProductSlot(PieceProductSlot $slot): static + { + if (!$this->productSlots->contains($slot)) { + $this->productSlots->add($slot); + $slot->setPiece($this); + } + + return $this; + } + + public function removeProductSlot(PieceProductSlot $slot): static + { + $this->productSlots->removeElement($slot); + + return $this; + } + + public function getVersion(): int + { + return $this->version; + } + + public function incrementVersion(): static + { + ++$this->version; + + return $this; + } } diff --git a/src/Entity/PieceProductSlot.php b/src/Entity/PieceProductSlot.php new file mode 100644 index 0000000..76a199a --- /dev/null +++ b/src/Entity/PieceProductSlot.php @@ -0,0 +1,112 @@ + 0])] + private int $position = 0; + + #[ORM\Column(type: Types::DATETIME_IMMUTABLE, name: 'createdAt')] + private DateTimeImmutable $createdAt; + + #[ORM\Column(type: Types::DATETIME_IMMUTABLE, name: 'updatedAt')] + private DateTimeImmutable $updatedAt; + + public function __construct() + { + $this->createdAt = new DateTimeImmutable(); + $this->updatedAt = new DateTimeImmutable(); + } + + public function getPiece(): Piece + { + return $this->piece; + } + + public function setPiece(Piece $piece): static + { + $this->piece = $piece; + + return $this; + } + + public function getTypeProduct(): ?ModelType + { + return $this->typeProduct; + } + + public function setTypeProduct(?ModelType $typeProduct): static + { + $this->typeProduct = $typeProduct; + + return $this; + } + + public function getSelectedProduct(): ?Product + { + return $this->selectedProduct; + } + + public function setSelectedProduct(?Product $selectedProduct): static + { + $this->selectedProduct = $selectedProduct; + + return $this; + } + + public function getFamilyCode(): ?string + { + return $this->familyCode; + } + + public function setFamilyCode(?string $familyCode): static + { + $this->familyCode = $familyCode; + + return $this; + } + + public function getPosition(): int + { + return $this->position; + } + + public function setPosition(int $position): static + { + $this->position = $position; + + return $this; + } +} diff --git a/src/Entity/Product.php b/src/Entity/Product.php index 0699548..5abf881 100644 --- a/src/Entity/Product.php +++ b/src/Entity/Product.php @@ -118,6 +118,10 @@ class Product #[ORM\OneToMany(mappedBy: 'product', targetEntity: MachineProductLink::class)] private Collection $machineLinks; + #[ORM\Column(type: Types::INTEGER, options: ['default' => 1])] + #[Groups(['product:read'])] + private int $version = 1; + #[ORM\Column(type: Types::DATETIME_IMMUTABLE, name: 'createdAt')] #[Groups(['product:read'])] private DateTimeImmutable $createdAt; @@ -234,4 +238,16 @@ class Product { return $this->linkedPieces; } + + public function getVersion(): int + { + return $this->version; + } + + public function incrementVersion(): static + { + ++$this->version; + + return $this; + } }