false])] #[Groups(['composant:read', 'piece:read', 'product:read', 'machine:read'])] private bool $required = false; #[ORM\Column(type: Types::STRING, length: 255, nullable: true, name: 'defaultValue')] private ?string $defaultValue = null; #[ORM\Column(type: Types::JSON, nullable: true)] #[Groups(['composant:read', 'piece:read', 'product:read', 'machine:read'])] private ?array $options = null; #[ORM\Column(type: Types::INTEGER, options: ['default' => 0], name: 'orderIndex')] #[Groups(['composant:read', 'piece:read', 'product:read', 'machine:read'])] private int $orderIndex = 0; #[ORM\ManyToOne(targetEntity: TypeMachine::class, inversedBy: 'customFields')] #[ORM\JoinColumn(name: 'typeMachineId', referencedColumnName: 'id', nullable: true, onDelete: 'CASCADE')] private ?TypeMachine $typeMachine = null; #[ORM\ManyToOne(targetEntity: ModelType::class, inversedBy: 'customFields')] #[ORM\JoinColumn(name: 'typeComposantId', referencedColumnName: 'id', nullable: true, onDelete: 'CASCADE')] private ?ModelType $typeComposant = null; #[ORM\ManyToOne(targetEntity: ModelType::class, inversedBy: 'pieceCustomFields')] #[ORM\JoinColumn(name: 'typePieceId', referencedColumnName: 'id', nullable: true, onDelete: 'CASCADE')] private ?ModelType $typePiece = null; #[ORM\ManyToOne(targetEntity: ModelType::class, inversedBy: 'productCustomFields')] #[ORM\JoinColumn(name: 'typeProductId', referencedColumnName: 'id', nullable: true, onDelete: 'CASCADE')] private ?ModelType $typeProduct = null; /** * @var Collection */ #[ORM\OneToMany(mappedBy: 'customField', targetEntity: CustomFieldValue::class)] private Collection $customFieldValues; #[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->customFieldValues = 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 getType(): string { return $this->type; } public function setType(string $type): static { $this->type = $type; return $this; } public function isRequired(): bool { return $this->required; } public function setRequired(bool $required): static { $this->required = $required; return $this; } public function getDefaultValue(): ?string { return $this->defaultValue; } public function setDefaultValue(?string $defaultValue): static { $this->defaultValue = $defaultValue; return $this; } public function getOptions(): ?array { return $this->options; } public function setOptions(?array $options): static { $this->options = $options; return $this; } public function getOrderIndex(): int { return $this->orderIndex; } public function setOrderIndex(int $orderIndex): static { $this->orderIndex = $orderIndex; return $this; } public function getTypeMachine(): ?TypeMachine { return $this->typeMachine; } public function setTypeMachine(?TypeMachine $typeMachine): static { $this->typeMachine = $typeMachine; return $this; } public function getCreatedAt(): DateTimeImmutable { return $this->createdAt; } public function getUpdatedAt(): DateTimeImmutable { return $this->updatedAt; } private function generateCuid(): string { return 'cl'.bin2hex(random_bytes(12)); } }