mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
WIP: create and edit calendar
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -12,6 +12,10 @@ declare(strict_types=1);
|
||||
namespace Chill\CalendarBundle\Entity;
|
||||
|
||||
use Chill\CalendarBundle\Repository\InviteRepository;
|
||||
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\User;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
@@ -19,31 +23,54 @@ use Doctrine\ORM\Mapping as ORM;
|
||||
* @ORM\Table(name="chill_calendar.invite")
|
||||
* @ORM\Entity(repositoryClass=InviteRepository::class)
|
||||
*/
|
||||
class Invite
|
||||
class Invite implements TrackUpdateInterface, TrackCreationInterface
|
||||
{
|
||||
use TrackCreationTrait;
|
||||
|
||||
use TrackUpdateTrait;
|
||||
|
||||
public const ACCEPTED = 'accepted';
|
||||
|
||||
public const DECLINED = 'declined';
|
||||
|
||||
public const PENDING = 'pending';
|
||||
|
||||
public const TENTATIVELY_ACCEPTED = 'tentative';
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity=Calendar::class, inversedBy="invites")
|
||||
*/
|
||||
private ?Calendar $calendar;
|
||||
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue
|
||||
* @ORM\Column(type="integer")
|
||||
*/
|
||||
private $id;
|
||||
private ?int $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="json")
|
||||
* @ORM\Column(type="text", nullable=false, options={"default": "pending"})
|
||||
*/
|
||||
private array $status = [];
|
||||
private string $status = self::PENDING;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\User")
|
||||
* @ORM\JoinColumn(nullable=false)
|
||||
*/
|
||||
private User $user;
|
||||
private ?User $user;
|
||||
|
||||
public function getCalendar(): ?Calendar
|
||||
{
|
||||
return $this->calendar;
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getStatus(): ?array
|
||||
public function getStatus(): string
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
@@ -53,7 +80,17 @@ class Invite
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
public function setStatus(array $status): self
|
||||
/**
|
||||
* @internal use Calendar::addInvite instead
|
||||
* @param Calendar|null $calendar
|
||||
* @return void
|
||||
*/
|
||||
public function setCalendar(?Calendar $calendar): void
|
||||
{
|
||||
$this->calendar = $calendar;
|
||||
}
|
||||
|
||||
public function setStatus(string $status): self
|
||||
{
|
||||
$this->status = $status;
|
||||
|
||||
|
Reference in New Issue
Block a user