'ipartial', 'reference' => 'ipartial', 'typeProduct' => 'exact'])] #[ApiFilter(OrderFilter::class, properties: ['name', 'createdAt'])] #[ApiResource( normalizationContext: ['groups' => ['product:read']], paginationClientItemsPerPage: true, paginationMaximumItemsPerPage: 200 )] class Product { #[ORM\Id] #[ORM\Column(type: Types::STRING, length: 36)] #[Groups(['product:read', 'document:list'])] private ?string $id = null; #[ORM\Column(type: Types::STRING, length: 255, unique: true)] #[Groups(['product:read', 'document:list'])] private string $name; #[ORM\Column(type: Types::STRING, length: 255, nullable: true)] #[Groups(['product:read'])] private ?string $reference = null; #[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2, nullable: true, name: 'supplierPrice')] #[Groups(['product:read'])] private ?string $supplierPrice = null; #[ORM\ManyToOne(targetEntity: ModelType::class, inversedBy: 'products')] #[ORM\JoinColumn(name: 'typeProductId', referencedColumnName: 'id', nullable: true)] #[Groups(['product:read'])] private ?ModelType $typeProduct = null; /** * @var Collection */ #[ORM\ManyToMany(targetEntity: Constructeur::class, inversedBy: 'products')] #[ORM\JoinTable( name: '_ProductConstructeurs', joinColumns: [new ORM\JoinColumn(name: 'A', referencedColumnName: 'id', onDelete: 'CASCADE')], inverseJoinColumns: [new ORM\InverseJoinColumn(name: 'B', referencedColumnName: 'id', onDelete: 'CASCADE')] )] #[Groups(['product:read'])] private Collection $constructeurs; /** * @var Collection */ #[ORM\OneToMany(mappedBy: 'product', targetEntity: Document::class)] #[Groups(['product:read'])] private Collection $documents; /** * @var Collection */ #[ORM\OneToMany(mappedBy: 'product', targetEntity: CustomFieldValue::class)] #[Groups(['product:read'])] private Collection $customFieldValues; /** * @var Collection */ #[ORM\OneToMany(mappedBy: 'product', targetEntity: Piece::class)] private Collection $pieces; /** * @var Collection */ #[ORM\OneToMany(mappedBy: 'product', targetEntity: Composant::class)] private Collection $composants; /** * @var Collection */ #[ORM\OneToMany(mappedBy: 'product', targetEntity: MachineProductLink::class)] private Collection $machineLinks; #[ORM\Column(type: Types::DATETIME_IMMUTABLE, name: 'createdAt')] #[Groups(['product:read'])] private DateTimeImmutable $createdAt; #[ORM\Column(type: Types::DATETIME_IMMUTABLE, name: 'updatedAt')] #[Groups(['product:read'])] private DateTimeImmutable $updatedAt; public function __construct() { $this->constructeurs = new ArrayCollection(); $this->documents = new ArrayCollection(); $this->customFieldValues = new ArrayCollection(); $this->pieces = new ArrayCollection(); $this->composants = new ArrayCollection(); $this->machineLinks = new ArrayCollection(); } #[ORM\PrePersist] public function setCreatedAtValue(): void { $now = new DateTimeImmutable(); $this->createdAt = $now; $this->updatedAt = $now; if (null === $this->id) { $this->id = $this->generateCuid(); } } #[ORM\PreUpdate] public function setUpdatedAtValue(): void { $this->updatedAt = new DateTimeImmutable(); } public function getId(): ?string { return $this->id; } public function setId(string $id): static { $this->id = $id; return $this; } public function getName(): string { return $this->name; } public function setName(string $name): static { $this->name = $name; return $this; } public function getReference(): ?string { return $this->reference; } public function setReference(?string $reference): static { $this->reference = $reference; return $this; } public function getSupplierPrice(): ?string { return $this->supplierPrice; } public function setSupplierPrice(?string $supplierPrice): static { $this->supplierPrice = $supplierPrice; return $this; } public function getTypeProduct(): ?ModelType { return $this->typeProduct; } public function setTypeProduct(?ModelType $typeProduct): static { $this->typeProduct = $typeProduct; return $this; } /** * @return Collection */ public function getConstructeurs(): Collection { return $this->constructeurs; } public function addConstructeur(Constructeur $constructeur): static { if (!$this->constructeurs->contains($constructeur)) { $this->constructeurs->add($constructeur); } return $this; } public function removeConstructeur(Constructeur $constructeur): static { $this->constructeurs->removeElement($constructeur); return $this; } /** * @return Collection */ public function getDocuments(): Collection { return $this->documents; } /** * @return Collection */ public function getCustomFieldValues(): Collection { return $this->customFieldValues; } public function getCreatedAt(): DateTimeImmutable { return $this->createdAt; } public function getUpdatedAt(): DateTimeImmutable { return $this->updatedAt; } private function generateCuid(): string { return 'cl'.bin2hex(random_bytes(12)); } }