<?php
namespace App\Entity;
use App\Repository\PropertyRepository;
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\Entity(repositoryClass: PropertyRepository::class)]
class Property implements TranslatableInterface
{
use AutoTranslatableTrait;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 255)]
private $name;
#[ORM\Column(type: 'datetime')]
private $created_at;
#[ORM\Column(type: 'datetime', nullable: true)]
private $updated_at;
#[ORM\ManyToOne(targetEntity: Propertygroup::class, inversedBy: 'properties')]
private $propertygroup;
#[ORM\OneToMany(targetEntity: CropProperty::class, mappedBy: 'property')]
private $cropProperties;
public function __construct()
{
$this->created_at = new \DateTime();
$this->cropProperties = 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 getCreatedAt(): ?\DateTimeInterface
{
return $this->created_at;
}
public function setCreatedAt(\DateTimeInterface $created_at): self
{
$this->created_at = $created_at;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updated_at;
}
public function setUpdatedAt(?\DateTimeInterface $updated_at): self
{
$this->updated_at = $updated_at;
return $this;
}
public function getPropertygroup(): ?Propertygroup
{
return $this->propertygroup;
}
public function setPropertygroup(?Propertygroup $propertygroup): self
{
$this->propertygroup = $propertygroup;
return $this;
}
/**
* @return Collection<int, CropProperty>
*/
public function getCropProperties(): Collection
{
return $this->cropProperties;
}
public function addCropProperty(CropProperty $cropProperty): self
{
if (!$this->cropProperties->contains($cropProperty)) {
$this->cropProperties[] = $cropProperty;
$cropProperty->setProperty($this);
}
return $this;
}
public function removeCropProperty(CropProperty $cropProperty): self
{
if ($this->cropProperties->removeElement($cropProperty)) {
// set the owning side to null (unless already changed)
if ($cropProperty->getProperty() === $this) {
$cropProperty->setProperty(null);
}
}
return $this;
}
}