<?php
namespace App\Entity;
use App\Repository\GardenRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: GardenRepository::class)]
#[ORM\Index(name: 'ix_public_hash', columns: ['public_hash'])]
class Garden
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'json')]
private $gardenData = [];
#[ORM\Column(type: 'json')]
private $planData = [];
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $imagePath;
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'gardens')]
#[ORM\JoinColumn(nullable: false)]
private $user;
#[ORM\Column(type: 'datetime')]
private $createdAt;
#[ORM\Column(type: 'datetime')]
private $updatedAt;
#[ORM\OneToMany(targetEntity: Patch::class, mappedBy: 'garden')]
private $patches;
#[ORM\Column(type: 'json', nullable: true)]
private $additionalData = [];
#[ORM\Column(type: 'string', length: 100, nullable: true)]
private $hash;
#[ORM\Column(type: 'json', nullable: true)]
private $deviceInformation = [];
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $name;
#[ORM\OneToMany(targetEntity: Todo::class, mappedBy: 'garden')]
private $todos;
#[ORM\Column(nullable: true)]
private ?array $warnings = [];
#[ORM\Column(length: 255, nullable: true)]
private ?string $public_hash = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $dynamic_link = null;
public function __construct()
{
$this->patches = new ArrayCollection();
$this->createdAt = new \DateTime();
$this->todos = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getGardenData(): ?array
{
return $this->gardenData;
}
public function setGardenData(array $gardenData): self
{
$this->gardenData = $gardenData;
return $this;
}
public function getPlanData(): ?array
{
return $this->planData;
}
public function setPlanData(array $planData): self
{
$this->planData = $planData;
return $this;
}
public function getImagePath(): ?string
{
return $this->imagePath;
}
public function setImagePath(?string $imagePath): self
{
$this->imagePath = $imagePath;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* @return Collection|Patch[]
*/
public function getPatches(): Collection
{
return $this->patches;
}
public function addPatch(Patch $patch): self
{
if (!$this->patches->contains($patch)) {
$this->patches[] = $patch;
$patch->setGarden($this);
}
return $this;
}
public function removePatch(Patch $patch): self
{
if ($this->patches->removeElement($patch)) {
// set the owning side to null (unless already changed)
if ($patch->getGarden() === $this) {
$patch->setGarden(null);
}
}
return $this;
}
public function getAdditionalData(): ?array
{
return $this->additionalData;
}
public function setAdditionalData(?array $additionalData): self
{
$this->additionalData = $additionalData;
return $this;
}
public function getHash(): ?string
{
return $this->hash;
}
public function setHash(?string $hash): self
{
$this->hash = $hash;
return $this;
}
public function getDeviceInformation(): ?array
{
return $this->deviceInformation;
}
public function setDeviceInformation(?array $deviceInformation): self
{
$this->deviceInformation = $deviceInformation;
return $this;
}
public function getOccupancy($year, $season = 'main'): float
{
return $this->gardenData['occupancy'][$year][$season] ?? 0;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): self
{
$this->name = $name;
return $this;
}
/**
* @return Collection<int, Todo>
*/
public function getTodos(): Collection
{
return $this->todos;
}
public function addTodo(Todo $todo): self
{
if (!$this->todos->contains($todo)) {
$this->todos[] = $todo;
$todo->setGarden($this);
}
return $this;
}
public function removeTodo(Todo $todo): self
{
if ($this->todos->removeElement($todo)) {
// set the owning side to null (unless already changed)
if ($todo->getGarden() === $this) {
$todo->setGarden(null);
}
}
return $this;
}
public function getWarnings(): ?array
{
return $this->warnings;
}
public function setWarnings(?array $warnings): static
{
$this->warnings = $warnings;
return $this;
}
public function getPublicHash(): ?string
{
return $this->public_hash;
}
public function setPublicHash(?string $public_hash): static
{
$this->public_hash = $public_hash;
return $this;
}
public function getDynamicLink(): ?string
{
return $this->dynamic_link;
}
public function setDynamicLink(?string $dynamic_link): static
{
$this->dynamic_link = $dynamic_link;
return $this;
}
}