src/Entity/DynData.php line 16

Open in your IDE?
  1. <?php
  2. // src/Entity/DynData.php
  3. namespace App\Entity;
  4. use App\Repository\DynDataRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use InvalidArgumentException;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. #[ORM\Entity(repositoryClassDynDataRepository::class)]
  11. class DynData
  12. {
  13.     #[ORM\Id]
  14.     #[ORM\GeneratedValue]
  15.     #[ORM\Column(type'integer')]
  16.     private $id;
  17.     #[Assert\NotBlank]
  18.     #[ORM\Column(type'text')]
  19.     private $name;
  20.     #[ORM\Column(type'text'nullabletrue)]
  21.     private $data;
  22.     #[Assert\Choice(choices: ["TEXT""ARRAY"])]
  23.     #[ORM\Column(type'string'length10)]
  24.     private $type;
  25.     #[ORM\OneToMany(targetEntityDynDataCollection::class, mappedBy'DynData'orphanRemoval'true'cascade: ["persist"])]
  26.     private $dataItems;
  27.     public function __construct()
  28.     {
  29.         $this->dataItems = new ArrayCollection();
  30.     }
  31.     public function getId(): ?int
  32.     {
  33.         return $this->id;
  34.     }
  35.     public function getName(): ?string
  36.     {
  37.         return $this->name;
  38.     }
  39.     public function setName(string $name): self
  40.     {
  41.         $this->name $name;
  42.         return $this;
  43.     }
  44.     public function getType(): ?string
  45.     {
  46.         return $this->type;
  47.     }
  48.     public function setType(string $type): self
  49.     {
  50.         $this->type $type;
  51.         return $this;
  52.     }
  53.     public function getData()
  54.     {
  55.         return json_decode($this->datatrue);
  56.     }
  57.     public function setData($data): self
  58.     {
  59.         $this->data json_encode($data);
  60.         return $this;
  61.     }
  62.     /**
  63.      * @return Collection|DynDataCollection[]
  64.      */
  65.     public function getDataItems(): Collection
  66.     {
  67.         return $this->dataItems;
  68.     }
  69.     public function addDataItem(DynDataCollection $dataItem): self
  70.     {
  71.         if (!$this->dataItems->contains($dataItem)) {
  72.             $this->dataItems[] = $dataItem;
  73.             $dataItem->setDynData($this);
  74.         }
  75.         return $this;
  76.     }
  77.     public function removeDataItem(DynDataCollection $dataItem): self
  78.     {
  79.         if ($this->dataItems->contains($dataItem)) {
  80.             $this->dataItems->removeElement($dataItem);
  81.             // set the owning side to null (unless already changed)
  82.             if ($dataItem->getDynData() === $this) {
  83.                 $dataItem->setDynData(null);
  84.             }
  85.         }
  86.         return $this;
  87.     }
  88.     public function isNew(): bool
  89.     {
  90.         return null === $this->id;
  91.     }
  92. }