work on create calendar

This commit is contained in:
2022-05-13 13:49:24 +02:00
parent 7859439f0b
commit 4be3efc619
10 changed files with 128 additions and 44 deletions

View File

@@ -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;
}