<?php
namespace App\Entity;
use App\Repository\CroplistRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: CroplistRepository::class)]
class Croplist
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne(inversedBy: 'cropLists')]
#[ORM\JoinColumn(nullable: false)]
private ?User $user = null;
#[ORM\Column(length: 100, nullable: true)]
private ?string $name = null;
#[ORM\OneToMany(mappedBy: 'croplist', targetEntity: FavoriteCrop::class)]
private Collection $favoriteCrops;
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
private ?\DateTimeInterface $created_at = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $updated_at = null;
public function __construct()
{
$this->favoriteCrops = new ArrayCollection();
$this->created_at = new \DateTime();
}
public function getId(): ?int
{
return $this->id;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): self
{
$this->name = $name;
return $this;
}
/**
* @return Collection<int, FavoriteCrop>
*/
public function getFavoriteCrops(): Collection
{
return $this->favoriteCrops;
}
public function addFavoriteCrop(FavoriteCrop $favoriteCrop): self
{
if (!$this->favoriteCrops->contains($favoriteCrop)) {
$this->favoriteCrops->add($favoriteCrop);
$favoriteCrop->setCroplist($this);
}
return $this;
}
public function removeFavoriteCrop(FavoriteCrop $favoriteCrop): self
{
if ($this->favoriteCrops->removeElement($favoriteCrop)) {
// set the owning side to null (unless already changed)
if ($favoriteCrop->getCroplist() === $this) {
$favoriteCrop->setCroplist(null);
}
}
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;
}
}