src/Entity/Cropcategory.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Translation\AutoTranslatableTrait;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
  8. #[ORM\Table(name'cropcategory')]
  9. #[ORM\Entity(repositoryClass'App\Entity\Repository\CropcategoryRepository')]
  10. class Cropcategory implements TranslatableInterface
  11. {
  12.     use AutoTranslatableTrait;
  13.     #[ORM\Id]
  14.     #[ORM\Column(type'integer')]
  15.     #[ORM\GeneratedValue(strategy'AUTO')]
  16.     private $id;
  17.     #[ORM\Column(type'string'uniquetruenullablefalse)]
  18.     private $name;
  19.     #[ORM\Column(type'datetime'nullablefalse)]
  20.     private $date_created;
  21.     #[ORM\OneToMany(targetEntity'App\Entity\Crop'mappedBy'cropcategory')]
  22.     private $crop;
  23.     #[ORM\ManyToOne(targetEntityCropcategory::class, inversedBy'cropcategories')]
  24.     private $parent;
  25.     #[ORM\OneToMany(targetEntityCropcategory::class, mappedBy'parent')]
  26.     private $cropcategories;
  27.     public function __construct()
  28.     {
  29.         $this->crop = new ArrayCollection();
  30.         $this->cropcategories = new ArrayCollection();
  31.     }
  32.     public function getId(): ?int
  33.     {
  34.         return $this->id;
  35.     }
  36.     public function getName(bool $skipTranslation false): ?string
  37.     {
  38.         if ($skipTranslation || $this->getCurrentLocale() === $this->getDefaultLocale()) {
  39.             return $this->name;
  40.         }
  41.         $translated $this->translate()->getName();
  42.         return !empty($translated) ? $translated $this->name;
  43.     }
  44.     public function setName(?string $name): self
  45.     {
  46.         $this->name $name;
  47.         return $this;
  48.     }
  49.     public function getDateCreated(): ?\DateTimeInterface
  50.     {
  51.         return $this->date_created;
  52.     }
  53.     public function setDateCreated(\DateTimeInterface $date_created): self
  54.     {
  55.         $this->date_created $date_created;
  56.         return $this;
  57.     }
  58.     /**
  59.      * @return Collection|Crop[]
  60.      */
  61.     public function getCrop(): Collection
  62.     {
  63.         return $this->crop;
  64.     }
  65.     public function addCrop(Crop $crop): self
  66.     {
  67.         if (!$this->crop->contains($crop)) {
  68.             $this->crop[] = $crop;
  69.             $crop->setCropcategory($this);
  70.         }
  71.         return $this;
  72.     }
  73.     public function removeCrop(Crop $crop): self
  74.     {
  75.         if ($this->crop->contains($crop)) {
  76.             $this->crop->removeElement($crop);
  77.             // set the owning side to null (unless already changed)
  78.             if ($crop->getCropcategory() === $this) {
  79.                 $crop->setCropcategory(null);
  80.             }
  81.         }
  82.         return $this;
  83.     }
  84.     public function getParent(): ?self
  85.     {
  86.         return $this->parent;
  87.     }
  88.     public function setParent(?self $parent): self
  89.     {
  90.         $this->parent $parent;
  91.         return $this;
  92.     }
  93.     /**
  94.      * @return Collection<int, self>
  95.      */
  96.     public function getCropcategories(): Collection
  97.     {
  98.         return $this->cropcategories;
  99.     }
  100.     public function addCropcategory(self $cropcategory): self
  101.     {
  102.         if (!$this->cropcategories->contains($cropcategory)) {
  103.             $this->cropcategories[] = $cropcategory;
  104.             $cropcategory->setParent($this);
  105.         }
  106.         return $this;
  107.     }
  108.     public function removeCropcategory(self $cropcategory): self
  109.     {
  110.         if ($this->cropcategories->removeElement($cropcategory)) {
  111.             // set the owning side to null (unless already changed)
  112.             if ($cropcategory->getParent() === $this) {
  113.                 $cropcategory->setParent(null);
  114.             }
  115.         }
  116.         return $this;
  117.     }
  118. }