feat(sync) : add version field and PieceProductSlot entity
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -130,6 +130,10 @@ class Composant
|
|||||||
#[ORM\OrderBy(['position' => 'ASC'])]
|
#[ORM\OrderBy(['position' => 'ASC'])]
|
||||||
private Collection $productSlots;
|
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')]
|
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, name: 'createdAt')]
|
||||||
#[Groups(['composant:read'])]
|
#[Groups(['composant:read'])]
|
||||||
private DateTimeImmutable $createdAt;
|
private DateTimeImmutable $createdAt;
|
||||||
@@ -406,4 +410,16 @@ class Composant
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getVersion(): int
|
||||||
|
{
|
||||||
|
return $this->version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function incrementVersion(): static
|
||||||
|
{
|
||||||
|
++$this->version;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,12 +114,23 @@ class Piece
|
|||||||
#[ORM\InverseJoinColumn(name: 'product_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
|
#[ORM\InverseJoinColumn(name: 'product_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
|
||||||
private Collection $products;
|
private Collection $products;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Collection<int, PieceProductSlot>
|
||||||
|
*/
|
||||||
|
#[ORM\OneToMany(targetEntity: PieceProductSlot::class, mappedBy: 'piece', cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||||
|
#[ORM\OrderBy(['position' => 'ASC'])]
|
||||||
|
private Collection $productSlots;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Collection<int, MachinePieceLink>
|
* @var Collection<int, MachinePieceLink>
|
||||||
*/
|
*/
|
||||||
#[ORM\OneToMany(mappedBy: 'piece', targetEntity: MachinePieceLink::class)]
|
#[ORM\OneToMany(mappedBy: 'piece', targetEntity: MachinePieceLink::class)]
|
||||||
private Collection $machineLinks;
|
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')]
|
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, name: 'createdAt')]
|
||||||
#[Groups(['piece:read'])]
|
#[Groups(['piece:read'])]
|
||||||
private DateTimeImmutable $createdAt;
|
private DateTimeImmutable $createdAt;
|
||||||
@@ -136,6 +147,7 @@ class Piece
|
|||||||
$this->documents = new ArrayCollection();
|
$this->documents = new ArrayCollection();
|
||||||
$this->customFieldValues = new ArrayCollection();
|
$this->customFieldValues = new ArrayCollection();
|
||||||
$this->products = new ArrayCollection();
|
$this->products = new ArrayCollection();
|
||||||
|
$this->productSlots = new ArrayCollection();
|
||||||
$this->machineLinks = new ArrayCollection();
|
$this->machineLinks = new ArrayCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -287,4 +299,41 @@ class Piece
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Collection<int, PieceProductSlot>
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
112
src/Entity/PieceProductSlot.php
Normal file
112
src/Entity/PieceProductSlot.php
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Entity;
|
||||||
|
|
||||||
|
use App\Entity\Trait\CuidEntityTrait;
|
||||||
|
use DateTimeImmutable;
|
||||||
|
use Doctrine\DBAL\Types\Types;
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
|
||||||
|
#[ORM\Entity]
|
||||||
|
#[ORM\Table(name: 'piece_product_slots')]
|
||||||
|
#[ORM\HasLifecycleCallbacks]
|
||||||
|
class PieceProductSlot
|
||||||
|
{
|
||||||
|
use CuidEntityTrait;
|
||||||
|
|
||||||
|
#[ORM\Id]
|
||||||
|
#[ORM\Column(type: Types::STRING, length: 36)]
|
||||||
|
private ?string $id = null;
|
||||||
|
|
||||||
|
#[ORM\ManyToOne(targetEntity: Piece::class, inversedBy: 'productSlots')]
|
||||||
|
#[ORM\JoinColumn(name: 'pieceId', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
|
||||||
|
private Piece $piece;
|
||||||
|
|
||||||
|
#[ORM\ManyToOne(targetEntity: ModelType::class)]
|
||||||
|
#[ORM\JoinColumn(name: 'typeProductId', referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
|
||||||
|
private ?ModelType $typeProduct = null;
|
||||||
|
|
||||||
|
#[ORM\ManyToOne(targetEntity: Product::class)]
|
||||||
|
#[ORM\JoinColumn(name: 'selectedProductId', referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
|
||||||
|
private ?Product $selectedProduct = null;
|
||||||
|
|
||||||
|
#[ORM\Column(type: Types::STRING, length: 255, nullable: true, name: 'familyCode')]
|
||||||
|
private ?string $familyCode = null;
|
||||||
|
|
||||||
|
#[ORM\Column(type: Types::INTEGER, options: ['default' => 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -118,6 +118,10 @@ class Product
|
|||||||
#[ORM\OneToMany(mappedBy: 'product', targetEntity: MachineProductLink::class)]
|
#[ORM\OneToMany(mappedBy: 'product', targetEntity: MachineProductLink::class)]
|
||||||
private Collection $machineLinks;
|
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')]
|
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, name: 'createdAt')]
|
||||||
#[Groups(['product:read'])]
|
#[Groups(['product:read'])]
|
||||||
private DateTimeImmutable $createdAt;
|
private DateTimeImmutable $createdAt;
|
||||||
@@ -234,4 +238,16 @@ class Product
|
|||||||
{
|
{
|
||||||
return $this->linkedPieces;
|
return $this->linkedPieces;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getVersion(): int
|
||||||
|
{
|
||||||
|
return $this->version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function incrementVersion(): static
|
||||||
|
{
|
||||||
|
++$this->version;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user