<?php namespace App\Entity; use App\Repository\CustomProductTemplateRepository; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; use JMS\Serializer\Annotation as Serializer; use JMS\Serializer\Annotation\Expose; use JMS\Serializer\Annotation\Groups; use Symfony\Component\Validator\Constraints as Assert; /** * Template de formulaire pour un type de produit * * @ORM\Entity(repositoryClass=CustomProductTemplateRepository::class) * * @Serializer\ExclusionPolicy("ALL") */ class CustomProductTemplate { /** * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") * * @Expose * @Groups({"customProductTemplate:list"}) */ private ?int $id = NULL; /** * @ORM\ManyToOne(targetEntity=CustomProductType::class, inversedBy="templates") * @ORM\JoinColumn(nullable=false, name="type", referencedColumnName="slug") * * @Expose * @Groups({"customProductTemplate:list"}) */ private ?CustomProductType $type = NULL; /** * @ORM\OneToMany(targetEntity=CustomProductField::class, mappedBy="template", cascade={"persist"}) */ private $fields; /** * @ORM\Column(type="string", length=255) * @Assert\NotBlank() * * @Expose * @Groups({"customProductTemplate:list"}) */ private ?string $name = NULL; public function __construct() { $this->fields = new ArrayCollection(); } public function getId(): ?int { return $this->id; } public function getType(): ?CustomProductType { return $this->type; } public function setType(?CustomProductType $type): self { $this->type = $type; return $this; } /** * @return Collection<int, CustomProductField> */ public function getFields(): Collection { return $this->fields; } public function addField(CustomProductField $field): self { if (!$this->fields->contains($field)) { $this->fields[] = $field; $field->setTemplate($this); } return $this; } public function removeField(CustomProductField $field): self { if ($this->fields->removeElement($field)) { // set the owning side to null (unless already changed) if ($field->getTemplate() === $this) { $field->setTemplate(NULL); } } return $this; } public function getName(): ?string { return $this->name; } public function setName(string $name): self { $this->name = $name; return $this; } }