228 lines
5.5 KiB
PHP
228 lines
5.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Entity;
|
|
|
|
use ApiPlatform\Metadata\ApiResource;
|
|
use App\Repository\ComposantRepository;
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
use Doctrine\Common\Collections\Collection;
|
|
use Doctrine\DBAL\Types\Types;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
|
#[ORM\Entity(repositoryClass: ComposantRepository::class)]
|
|
#[ORM\Table(name: 'composants')]
|
|
#[ORM\HasLifecycleCallbacks]
|
|
#[ApiResource]
|
|
class Composant
|
|
{
|
|
#[ORM\Id]
|
|
#[ORM\Column(type: Types::STRING, length: 36)]
|
|
private ?string $id = null;
|
|
|
|
#[ORM\Column(type: Types::STRING, length: 255, unique: true)]
|
|
private string $name;
|
|
|
|
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
|
|
private ?string $reference = null;
|
|
|
|
#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2, nullable: true)]
|
|
private ?string $prix = null;
|
|
|
|
#[ORM\Column(type: Types::JSON, nullable: true)]
|
|
private ?array $structure = null;
|
|
|
|
#[ORM\ManyToOne(targetEntity: ModelType::class, inversedBy: 'composants')]
|
|
#[ORM\JoinColumn(name: 'typeComposantId', referencedColumnName: 'id', nullable: true)]
|
|
private ?ModelType $typeComposant = null;
|
|
|
|
#[ORM\ManyToOne(targetEntity: Product::class, inversedBy: 'composants')]
|
|
#[ORM\JoinColumn(name: 'productId', referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
|
|
private ?Product $product = null;
|
|
|
|
/**
|
|
* @var Collection<int, Constructeur>
|
|
*/
|
|
#[ORM\ManyToMany(targetEntity: Constructeur::class, inversedBy: 'composants')]
|
|
#[ORM\JoinTable(
|
|
name: '_ComposantConstructeurs',
|
|
joinColumns: [new ORM\JoinColumn(name: 'A', referencedColumnName: 'id', onDelete: 'CASCADE')],
|
|
inverseJoinColumns: [new ORM\InverseJoinColumn(name: 'B', referencedColumnName: 'id', onDelete: 'CASCADE')]
|
|
)]
|
|
private Collection $constructeurs;
|
|
|
|
/**
|
|
* @var Collection<int, Document>
|
|
*/
|
|
#[ORM\OneToMany(mappedBy: 'composant', targetEntity: Document::class)]
|
|
private Collection $documents;
|
|
|
|
/**
|
|
* @var Collection<int, CustomFieldValue>
|
|
*/
|
|
#[ORM\OneToMany(mappedBy: 'composant', targetEntity: CustomFieldValue::class)]
|
|
private Collection $customFieldValues;
|
|
|
|
/**
|
|
* @var Collection<int, MachineComponentLink>
|
|
*/
|
|
#[ORM\OneToMany(mappedBy: 'composant', targetEntity: MachineComponentLink::class)]
|
|
private Collection $machineLinks;
|
|
|
|
#[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->constructeurs = new ArrayCollection();
|
|
$this->documents = new ArrayCollection();
|
|
$this->customFieldValues = new ArrayCollection();
|
|
$this->machineLinks = new ArrayCollection();
|
|
}
|
|
|
|
#[ORM\PrePersist]
|
|
public function setCreatedAtValue(): void
|
|
{
|
|
$now = new \DateTimeImmutable();
|
|
$this->createdAt = $now;
|
|
$this->updatedAt = $now;
|
|
|
|
if ($this->id === null) {
|
|
$this->id = $this->generateCuid();
|
|
}
|
|
}
|
|
|
|
#[ORM\PreUpdate]
|
|
public function setUpdatedAtValue(): void
|
|
{
|
|
$this->updatedAt = new \DateTimeImmutable();
|
|
}
|
|
|
|
private function generateCuid(): string
|
|
{
|
|
return 'cl' . bin2hex(random_bytes(12));
|
|
}
|
|
|
|
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 getPrix(): ?string
|
|
{
|
|
return $this->prix;
|
|
}
|
|
|
|
public function setPrix(?string $prix): static
|
|
{
|
|
$this->prix = $prix;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getStructure(): ?array
|
|
{
|
|
return $this->structure;
|
|
}
|
|
|
|
public function setStructure(?array $structure): static
|
|
{
|
|
$this->structure = $structure;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getTypeComposant(): ?ModelType
|
|
{
|
|
return $this->typeComposant;
|
|
}
|
|
|
|
public function setTypeComposant(?ModelType $typeComposant): static
|
|
{
|
|
$this->typeComposant = $typeComposant;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getProduct(): ?Product
|
|
{
|
|
return $this->product;
|
|
}
|
|
|
|
public function setProduct(?Product $product): static
|
|
{
|
|
$this->product = $product;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return Collection<int, Constructeur>
|
|
*/
|
|
public function getConstructeurs(): Collection
|
|
{
|
|
return $this->constructeurs;
|
|
}
|
|
|
|
/**
|
|
* @return Collection<int, Document>
|
|
*/
|
|
public function getDocuments(): Collection
|
|
{
|
|
return $this->documents;
|
|
}
|
|
|
|
/**
|
|
* @return Collection<int, CustomFieldValue>
|
|
*/
|
|
public function getCustomFieldValues(): Collection
|
|
{
|
|
return $this->customFieldValues;
|
|
}
|
|
|
|
public function getCreatedAt(): \DateTimeImmutable
|
|
{
|
|
return $this->createdAt;
|
|
}
|
|
|
|
public function getUpdatedAt(): \DateTimeImmutable
|
|
{
|
|
return $this->updatedAt;
|
|
}
|
|
}
|