WIP: create and edit calendar

This commit is contained in:
2022-05-11 17:47:33 +02:00
parent f4b1a25a67
commit c60a54eb39
11 changed files with 217 additions and 69 deletions

View File

@@ -13,6 +13,10 @@ namespace Chill\CalendarBundle\Entity;
use Chill\ActivityBundle\Entity\Activity;
use Chill\CalendarBundle\Repository\CalendarRepository;
use Chill\MainBundle\Doctrine\Model\TrackCreationInterface;
use Chill\MainBundle\Doctrine\Model\TrackCreationTrait;
use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
use Chill\MainBundle\Doctrine\Model\TrackUpdateTrait;
use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
use Chill\MainBundle\Entity\Location;
use Chill\MainBundle\Entity\User;
@@ -35,8 +39,12 @@ use function in_array;
* @ORM\Table(name="chill_calendar.calendar")
* @ORM\Entity(repositoryClass=CalendarRepository::class)
*/
class Calendar
class Calendar implements TrackCreationInterface, TrackUpdateInterface
{
use TrackCreationTrait;
use TrackUpdateTrait;
public const STATUS_CANCELED = 'canceled';
public const STATUS_MOVED = 'moved';
@@ -82,12 +90,15 @@ class Calendar
* @ORM\Column(type="integer")
* @Serializer\Groups({"calendar:read"})
*/
private ?int $id;
private ?int $id = null;
/**
* @ORM\ManyToMany(
* targetEntity="Invite",
* cascade={"persist", "remove", "merge", "detach"})
* @ORM\OneToMany(
* targetEntity=Invite::class,
* mappedBy="calendar",
* orphanRemoval=true,
* cascade={"persist", "remove", "merge", "detach"}
* )
* @ORM\JoinTable(name="chill_calendar.calendar_to_invites")
* @Groups({"read"})
*/
@@ -137,16 +148,9 @@ class Calendar
private ?DateTimeImmutable $startDate = null;
/**
* @ORM\Column(type="string", length=255)
* @ORM\Column(type="string", length=255, nullable=false, options={"default": "valid"})
*/
private ?string $status = null;
/**
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\User")
* @Groups({"read"})
* @Serializer\Groups({"calendar:read"})
*/
private ?User $user = null;
private string $status = self::STATUS_VALID;
public function __construct()
{
@@ -156,29 +160,28 @@ class Calendar
$this->invites = new ArrayCollection();
}
public function addInvite(?Invite $invite): self
public function addInvite(Invite $invite): self
{
if (null !== $invite) {
$this->invites[] = $invite;
if ($invite->getCalendar() instanceof Calendar && $this !== $invite->getCalendar()) {
throw new \LogicException('Not allowed to move an invitation to another Calendar');
}
$this->invites[] = $invite;
$invite->setCalendar($this);
return $this;
}
public function addPerson(?Person $person): self
public function addPerson(Person $person): self
{
if (null !== $person) {
$this->persons[] = $person;
}
$this->persons[] = $person;
return $this;
}
public function addProfessional(?ThirdParty $professional): self
public function addProfessional(ThirdParty $professional): self
{
if (null !== $professional) {
$this->professionals[] = $professional;
}
$this->professionals[] = $professional;
return $this;
}
@@ -428,10 +431,5 @@ class Calendar
return $this;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
}