suivi/src/Entity/Project.php

219 lines
4.6 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\OneToMany(targetEntity=Event::class, mappedBy="projects", cascade={"persist", "remove"})
*/
protected $events;
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
{
$events = $this->events->toArray();
usort($events, function($a, $b) {
return $a->getStartAt() <=> $a->getFinishAt();
});
return new ArrayCollection($events);
}
public function addEvent(Event $event): self
{
if (!$this->events->contains($event)) {
$this->events[] = $event;
$event->setProjects($this);
}
return $this;
}
public function removeEvent(Event $event): self
{
if ($this->events->removeElement($event)) {
// set the owning side to null (unless already changed)
if ($event->getProjects() === $this) {
$event->setProjects(null);
}
}
return $this;
}
}