fix cs and add EntityToIdTransformer

This commit is contained in:
2022-05-20 15:52:02 +02:00
parent dba0e84781
commit b6e0379583
14 changed files with 308 additions and 97 deletions

View File

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

View File

@@ -11,7 +11,6 @@ declare(strict_types=1);
namespace Chill\CalendarBundle\Entity;
use Chill\CalendarBundle\Repository\CalendarRangeRepository;
use Chill\MainBundle\Doctrine\Model\TrackCreationInterface;
use Chill\MainBundle\Doctrine\Model\TrackCreationTrait;
use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;

View File

@@ -18,6 +18,7 @@ use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
use Chill\MainBundle\Doctrine\Model\TrackUpdateTrait;
use Chill\MainBundle\Entity\User;
use Doctrine\ORM\Mapping as ORM;
use LogicException;
/**
* @ORM\Table(name="chill_calendar.invite")
@@ -98,7 +99,7 @@ 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");
throw new LogicException('Not allowed to associate an invite to a different user');
}
$this->user = $user;