suivi/src/Entity/Project.php
2022-12-19 18:35:10 +01:00

207 lines
4.4 KiB
PHP

<?php
namespace App\Entity;
use App\Core\Entity\EntityInterface;
use App\Repository\ProjectRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: ProjectRepository::class)]
class Project implements EntityInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
protected $id;
#[ORM\Column(type: 'string', length: 255)]
protected $label;
#[ORM\ManyToMany(targetEntity: Establishment::class, inversedBy: 'projects')]
protected $establishments;
#[ORM\Column(type: 'text', nullable: true)]
protected $description;
#[ORM\Column(type: 'text', nullable: true)]
protected $client;
#[ORM\Column(type: 'array')]
protected $files = [];
#[ORM\ManyToMany(targetEntity: Debriefing::class, mappedBy: 'projects')]
protected $debriefings;
#[ORM\ManyToMany(targetEntity: Event::class, mappedBy: 'projects')]
protected $events;
#[ORM\Column(type: 'float', nullable: true)]
protected $price;
public function __construct()
{
$this->establishments = new ArrayCollection();
$this->debriefings = new ArrayCollection();
$this->events = new ArrayCollection();
}
public function __toString()
{
return (string) $this->getLabel();
}
public function getId(): ?int
{
return $this->id;
}
public function getLabel(): ?string
{
return $this->label;
}
public function setLabel(string $label): self
{
$this->label = $label;
return $this;
}
/**
* @return Collection<int, Establishment>
*/
public function getEstablishments(): Collection
{
return $this->establishments;
}
public function addEstablishment(Establishment $establishment): self
{
if (!$this->establishments->contains($establishment)) {
$this->establishments[] = $establishment;
}
return $this;
}
public function removeEstablishment(Establishment $establishment): self
{
$this->establishments->removeElement($establishment);
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getClient(): ?string
{
return $this->client;
}
public function setClient(?string $client): self
{
$this->client = $client;
return $this;
}
public function getFiles(): ?array
{
usort($this->files, function ($a, $b) {
return $a['position'] <=> $b['position'];
});
return $this->files;
}
public function setFiles(array $files): self
{
$this->files = $files;
return $this;
}
/**
* @return Collection<int, Debriefing>
*/
public function getDebriefings(): Collection
{
return $this->debriefings;
}
public function addDebriefing(Debriefing $debriefing): self
{
if (!$this->debriefings->contains($debriefing)) {
$this->debriefings[] = $debriefing;
$debriefing->addProject($this);
}
return $this;
}
public function removeDebriefing(Debriefing $debriefing): self
{
if ($this->debriefings->removeElement($debriefing)) {
$debriefing->removeProject($this);
}
return $this;
}
public function getCaldavEventTag(): string
{
return sprintf('#{project:%d}', $this->getId());
}
/**
* @return Collection<int, Event>
*/
public function getEvents(): Collection
{
return $this->events;
}
public function addEvent(Event $event): self
{
if (!$this->events->contains($event)) {
$this->events[] = $event;
$event->addProject($this);
}
return $this;
}
public function removeEvent(Event $event): self
{
if ($this->events->removeElement($event)) {
$event->removeProject($this);
}
return $this;
}
public function getPrice(): ?float
{
return $this->price;
}
public function setPrice(?float $price): self
{
$this->price = $price;
return $this;
}
}