src/Entity/CustomProductTemplate.php line 21

Open in your IDE?
  1. <?php
  2.     namespace App\Entity;
  3.     use App\Repository\CustomProductTemplateRepository;
  4.     use Doctrine\Common\Collections\ArrayCollection;
  5.     use Doctrine\Common\Collections\Collection;
  6.     use Doctrine\ORM\Mapping as ORM;
  7.     use JMS\Serializer\Annotation as Serializer;
  8.     use JMS\Serializer\Annotation\Expose;
  9.     use JMS\Serializer\Annotation\Groups;
  10.     use Symfony\Component\Validator\Constraints as Assert;
  11.     /**
  12.      * Template de formulaire pour un type de produit
  13.      *
  14.      * @ORM\Entity(repositoryClass=CustomProductTemplateRepository::class)
  15.      *
  16.      * @Serializer\ExclusionPolicy("ALL")
  17.      */
  18.     class CustomProductTemplate
  19.     {
  20.         /**
  21.          * @ORM\Id
  22.          * @ORM\GeneratedValue
  23.          * @ORM\Column(type="integer")
  24.          *
  25.          * @Expose
  26.          * @Groups({"customProductTemplate:list"})
  27.          */
  28.         private ?int $id NULL;
  29.         /**
  30.          * @ORM\ManyToOne(targetEntity=CustomProductType::class, inversedBy="templates")
  31.          * @ORM\JoinColumn(nullable=false, name="type", referencedColumnName="slug")
  32.          *
  33.          * @Expose
  34.          * @Groups({"customProductTemplate:list"})
  35.          */
  36.         private ?CustomProductType $type NULL;
  37.         /**
  38.          * @ORM\OneToMany(targetEntity=CustomProductField::class, mappedBy="template", cascade={"persist"})
  39.          */
  40.         private $fields;
  41.         /**
  42.          * @ORM\Column(type="string", length=255)
  43.          * @Assert\NotBlank()
  44.          *
  45.          * @Expose
  46.          * @Groups({"customProductTemplate:list"})
  47.          */
  48.         private ?string $name NULL;
  49.         public function __construct()
  50.         {
  51.             $this->fields = new ArrayCollection();
  52.         }
  53.         public function getId(): ?int
  54.         {
  55.             return $this->id;
  56.         }
  57.         public function getType(): ?CustomProductType
  58.         {
  59.             return $this->type;
  60.         }
  61.         public function setType(?CustomProductType $type): self
  62.         {
  63.             $this->type $type;
  64.             return $this;
  65.         }
  66.         /**
  67.          * @return Collection<int, CustomProductField>
  68.          */
  69.         public function getFields(): Collection
  70.         {
  71.             return $this->fields;
  72.         }
  73.         public function addField(CustomProductField $field): self
  74.         {
  75.             if (!$this->fields->contains($field)) {
  76.                 $this->fields[] = $field;
  77.                 $field->setTemplate($this);
  78.             }
  79.             return $this;
  80.         }
  81.         public function removeField(CustomProductField $field): self
  82.         {
  83.             if ($this->fields->removeElement($field)) {
  84.                 // set the owning side to null (unless already changed)
  85.                 if ($field->getTemplate() === $this) {
  86.                     $field->setTemplate(NULL);
  87.                 }
  88.             }
  89.             return $this;
  90.         }
  91.         public function getName(): ?string
  92.         {
  93.             return $this->name;
  94.         }
  95.         public function setName(string $name): self
  96.         {
  97.             $this->name $name;
  98.             return $this;
  99.         }
  100.     }