<?php
namespace App\Entity;
use App\Translation\AutoTranslatableTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
#[ORM\Table(name: 'cropcategory')]
#[ORM\Entity(repositoryClass: 'App\Entity\Repository\CropcategoryRepository')]
class Cropcategory implements TranslatableInterface
{
use AutoTranslatableTrait;
#[ORM\Id]
#[ORM\Column(type: 'integer')]
#[ORM\GeneratedValue(strategy: 'AUTO')]
private $id;
#[ORM\Column(type: 'string', unique: true, nullable: false)]
private $name;
#[ORM\Column(type: 'datetime', nullable: false)]
private $date_created;
#[ORM\OneToMany(targetEntity: 'App\Entity\Crop', mappedBy: 'cropcategory')]
private $crop;
#[ORM\ManyToOne(targetEntity: Cropcategory::class, inversedBy: 'cropcategories')]
private $parent;
#[ORM\OneToMany(targetEntity: Cropcategory::class, mappedBy: 'parent')]
private $cropcategories;
public function __construct()
{
$this->crop = new ArrayCollection();
$this->cropcategories = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(bool $skipTranslation = false): ?string
{
if ($skipTranslation || $this->getCurrentLocale() === $this->getDefaultLocale()) {
return $this->name;
}
$translated = $this->translate()->getName();
return !empty($translated) ? $translated : $this->name;
}
public function setName(?string $name): self
{
$this->name = $name;
return $this;
}
public function getDateCreated(): ?\DateTimeInterface
{
return $this->date_created;
}
public function setDateCreated(\DateTimeInterface $date_created): self
{
$this->date_created = $date_created;
return $this;
}
/**
* @return Collection|Crop[]
*/
public function getCrop(): Collection
{
return $this->crop;
}
public function addCrop(Crop $crop): self
{
if (!$this->crop->contains($crop)) {
$this->crop[] = $crop;
$crop->setCropcategory($this);
}
return $this;
}
public function removeCrop(Crop $crop): self
{
if ($this->crop->contains($crop)) {
$this->crop->removeElement($crop);
// set the owning side to null (unless already changed)
if ($crop->getCropcategory() === $this) {
$crop->setCropcategory(null);
}
}
return $this;
}
public function getParent(): ?self
{
return $this->parent;
}
public function setParent(?self $parent): self
{
$this->parent = $parent;
return $this;
}
/**
* @return Collection<int, self>
*/
public function getCropcategories(): Collection
{
return $this->cropcategories;
}
public function addCropcategory(self $cropcategory): self
{
if (!$this->cropcategories->contains($cropcategory)) {
$this->cropcategories[] = $cropcategory;
$cropcategory->setParent($this);
}
return $this;
}
public function removeCropcategory(self $cropcategory): self
{
if ($this->cropcategories->removeElement($cropcategory)) {
// set the owning side to null (unless already changed)
if ($cropcategory->getParent() === $this) {
$cropcategory->setParent(null);
}
}
return $this;
}
}