mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
fix cs and add EntityToIdTransformer
This commit is contained in:
@@ -27,11 +27,12 @@ use DateTimeImmutable;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use LogicException;
|
||||
use Symfony\Component\Serializer\Annotation as Serializer;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
use Symfony\Component\Validator\Constraints\Range;
|
||||
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
||||
|
||||
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
||||
use function in_array;
|
||||
|
||||
/**
|
||||
@@ -159,8 +160,8 @@ class Calendar implements TrackCreationInterface, TrackUpdateInterface
|
||||
|
||||
public function addInvite(Invite $invite): self
|
||||
{
|
||||
if ($invite->getCalendar() instanceof Calendar && $this !== $invite->getCalendar()) {
|
||||
throw new \LogicException('Not allowed to move an invitation to another Calendar');
|
||||
if ($invite->getCalendar() instanceof Calendar && $invite->getCalendar() !== $this) {
|
||||
throw new LogicException('Not allowed to move an invitation to another Calendar');
|
||||
}
|
||||
|
||||
$this->invites[] = $invite;
|
||||
@@ -169,29 +170,6 @@ 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;
|
||||
@@ -206,6 +184,15 @@ 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 getAccompanyingPeriod(): ?AccompanyingPeriod
|
||||
{
|
||||
return $this->accompanyingPeriod;
|
||||
@@ -334,7 +321,7 @@ class Calendar implements TrackCreationInterface, TrackUpdateInterface
|
||||
*/
|
||||
public function getUsers(): Collection
|
||||
{
|
||||
return $this->getInvites()->map(function (Invite $i) { return $i->getUser(); });
|
||||
return $this->getInvites()->map(static function (Invite $i) { return $i->getUser(); });
|
||||
}
|
||||
|
||||
public static function loadValidatorMetadata(ClassMetadata $metadata): void
|
||||
@@ -374,6 +361,20 @@ class Calendar implements TrackCreationInterface, TrackUpdateInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeUser(User $user): self
|
||||
{
|
||||
if (!$this->getUsers()->contains($user)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$invite = $this->invites
|
||||
->filter(static function (Invite $invite) use ($user) { return $invite->getUser() === $user; })
|
||||
->first();
|
||||
$this->removeInvite($invite);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setAccompanyingPeriod(?AccompanyingPeriod $accompanyingPeriod): self
|
||||
{
|
||||
$this->accompanyingPeriod = $accompanyingPeriod;
|
||||
@@ -450,6 +451,4 @@ class Calendar implements TrackCreationInterface, TrackUpdateInterface
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user