<?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: 'pest')]
#[ORM\Entity(repositoryClass: 'App\Entity\Repository\PestRepository')]
class Pest implements TranslatableInterface
{
use AutoTranslatableTrait;
#[ORM\Id]
#[ORM\Column(type: 'integer')]
#[ORM\GeneratedValue(strategy: 'AUTO')]
private $id;
#[ORM\Column(type: 'string', nullable: false)]
private $name;
#[ORM\Column(type: 'string', nullable: true)]
private $latin_name;
#[ORM\Column(type: 'string', nullable: true)]
private $identifier;
#[ORM\Column(type: 'string', nullable: true)]
private $category;
#[ORM\Column(type: 'text', nullable: true)]
private $description;
#[ORM\Column(type: 'text', nullable: true)]
private $countermeasure;
#[ORM\Column(type: 'datetime', nullable: true)]
private $date_created;
#[ORM\OneToMany(targetEntity: 'App\Entity\CropPest', mappedBy: 'pest')]
private $cropPest;
#[ORM\OneToMany(targetEntity: PestTranslation::class, mappedBy: 'translatable', orphanRemoval: true)]
private $pestTranslation;
#[ORM\Column(type: 'json', nullable: true)]
private $content_blocks = [];
#[ORM\Column(type: 'json', nullable: true)]
private $content_options = [];
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $external_id;
public function __construct()
{
$this->cropPest = 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 getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getCountermeasure(): ?string
{
return $this->countermeasure;
}
public function setCountermeasure(?string $countermeasure): self
{
$this->countermeasure = $countermeasure;
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|CropPest[]
*/
public function getCropPest(): Collection
{
return $this->cropPest;
}
public function addCropPest(CropPest $cropPest): self
{
if (!$this->cropPest->contains($cropPest)) {
$this->cropPest[] = $cropPest;
$cropPest->setPest($this);
}
return $this;
}
public function removeCropPest(CropPest $cropPest): self
{
if ($this->cropPest->contains($cropPest)) {
$this->cropPest->removeElement($cropPest);
// set the owning side to null (unless already changed)
if ($cropPest->getPest() === $this) {
$cropPest->setPest(null);
}
}
return $this;
}
public function getIdentifier(): ?string
{
return $this->identifier;
}
public function setIdentifier(?string $identifier): self
{
$this->identifier = $identifier;
return $this;
}
public function getCategory(): ?string
{
return $this->category;
}
public function setCategory(?string $category): self
{
$this->category = $category;
return $this;
}
public function getLatinName(): ?string
{
return $this->latin_name;
}
public function setLatinName(?string $latin_name): self
{
$this->latin_name = $latin_name;
return $this;
}
public function getContentBlocks(bool $skipTranslation = false): ?array
{
if ($skipTranslation || $this->getCurrentLocale() === $this->getDefaultLocale()) {
return $this->content_blocks;
}
$translated = $this->translate()->getContentBlocks();
return !empty($translated) ? $translated : $this->content_blocks;
}
public function setContentBlocks(?array $content_blocks): self
{
$this->content_blocks = $content_blocks;
return $this;
}
public function getContentOptions(): ?array
{
return $this->content_options;
}
public function setContentOptions(?array $content_options): self
{
$this->content_options = $content_options;
return $this;
}
public function getExternalId(): ?string
{
return $this->external_id;
}
public function setExternalId(?string $external_id): self
{
$this->external_id = $external_id;
return $this;
}
}