mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
work on create calendar
This commit is contained in:
@@ -172,6 +172,29 @@ class Calendar implements TrackCreationInterface, TrackUpdateInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addUser(User $user): self
|
||||
{
|
||||
if (!$this->getUsers()->contains($user)) {
|
||||
$this->addInvite((new Invite())->setUser($user));
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeUser(User $user): self
|
||||
{
|
||||
if (!$this->getUsers()->contains($user)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$invite = $this->invites
|
||||
->filter(function (Invite $invite) use ($user) { return $invite->getUser() === $user; })
|
||||
->first();
|
||||
$this->removeInvite($invite);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addPerson(Person $person): self
|
||||
{
|
||||
$this->persons[] = $person;
|
||||
@@ -309,14 +332,12 @@ class Calendar implements TrackCreationInterface, TrackUpdateInterface
|
||||
return $this->getProfessionals();
|
||||
}
|
||||
|
||||
public function getUser(): ?User
|
||||
/**
|
||||
* @return Collection|User[]
|
||||
*/
|
||||
public function getUsers(): Collection
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
public function getusers(): Collection
|
||||
{
|
||||
return $this->getInvites(); //TODO get users of the invite
|
||||
return $this->getInvites()->map(function (Invite $i) { return $i->getUser(); });
|
||||
}
|
||||
|
||||
public static function loadValidatorMetadata(ClassMetadata $metadata): void
|
||||
@@ -335,7 +356,9 @@ class Calendar implements TrackCreationInterface, TrackUpdateInterface
|
||||
|
||||
public function removeInvite(Invite $invite): self
|
||||
{
|
||||
$this->invites->removeElement($invite);
|
||||
if ($this->invites->removeElement($invite)) {
|
||||
$invite->setCalendar(null);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@@ -40,14 +40,14 @@ class Invite implements TrackUpdateInterface, TrackCreationInterface
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity=Calendar::class, inversedBy="invites")
|
||||
*/
|
||||
private ?Calendar $calendar;
|
||||
private ?Calendar $calendar = null;
|
||||
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue
|
||||
* @ORM\Column(type="integer")
|
||||
*/
|
||||
private ?int $id;
|
||||
private ?int $id = null;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="text", nullable=false, options={"default": "pending"})
|
||||
@@ -58,7 +58,7 @@ class Invite implements TrackUpdateInterface, TrackCreationInterface
|
||||
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\User")
|
||||
* @ORM\JoinColumn(nullable=false)
|
||||
*/
|
||||
private ?User $user;
|
||||
private ?User $user = null;
|
||||
|
||||
public function getCalendar(): ?Calendar
|
||||
{
|
||||
@@ -82,8 +82,6 @@ class Invite implements TrackUpdateInterface, TrackCreationInterface
|
||||
|
||||
/**
|
||||
* @internal use Calendar::addInvite instead
|
||||
* @param Calendar|null $calendar
|
||||
* @return void
|
||||
*/
|
||||
public function setCalendar(?Calendar $calendar): void
|
||||
{
|
||||
@@ -99,6 +97,10 @@ class Invite implements TrackUpdateInterface, TrackCreationInterface
|
||||
|
||||
public function setUser(?User $user): self
|
||||
{
|
||||
if ($user instanceof User && $this->user instanceof User && $user !== $this->user) {
|
||||
throw new \LogicException("Not allowed to associate an invite to a different user");
|
||||
}
|
||||
|
||||
$this->user = $user;
|
||||
|
||||
return $this;
|
||||
|
Reference in New Issue
Block a user