mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-07-18 14:56:13 +00:00
128 lines
3.0 KiB
PHP
128 lines
3.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/*
|
|
* Chill is a software for social workers
|
|
*
|
|
* For the full copyright and license information, please view
|
|
* the LICENSE file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Chill\EventBundle\Entity;
|
|
|
|
use Chill\MainBundle\Entity\User;
|
|
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
|
use Doctrine\DBAL\Types\Types;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
|
use Symfony\Component\Serializer\Annotation as Serializer;
|
|
|
|
/**
|
|
* Represents an animator that can be either a User or a ThirdParty.
|
|
*/
|
|
#[ORM\Entity]
|
|
#[ORM\Table(name: 'chill_event_animator')]
|
|
#[Assert\Expression(
|
|
'this.getUser() !== null or this.getThirdparty() !== null',
|
|
message: 'An animator must be either a User or a ThirdParty'
|
|
)]
|
|
class Animator
|
|
{
|
|
#[ORM\Id]
|
|
#[ORM\Column(type: Types::INTEGER)]
|
|
#[ORM\GeneratedValue(strategy: 'AUTO')]
|
|
private ?int $id = null;
|
|
|
|
#[ORM\ManyToOne(targetEntity: ThirdParty::class)]
|
|
#[ORM\JoinColumn(name: 'thirdparty_id', referencedColumnName: 'id', nullable: true)]
|
|
#[Serializer\Groups(['read'])]
|
|
private ?ThirdParty $thirdparty = null;
|
|
|
|
#[ORM\ManyToOne(targetEntity: User::class)]
|
|
#[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id', nullable: true)]
|
|
#[Serializer\Groups(['read'])]
|
|
private ?User $user = null;
|
|
|
|
#[ORM\ManyToOne(targetEntity: Event::class, inversedBy: 'animators')]
|
|
#[ORM\JoinColumn(name: 'event_id', referencedColumnName: 'id', nullable: false)]
|
|
private ?Event $event = null;
|
|
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getThirdparty(): ?ThirdParty
|
|
{
|
|
return $this->thirdparty;
|
|
}
|
|
|
|
public function setThirdparty(?ThirdParty $thirdparty): self
|
|
{
|
|
$this->thirdparty = $thirdparty;
|
|
|
|
if (null !== $thirdparty) {
|
|
$this->user = null;
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getUser(): ?User
|
|
{
|
|
return $this->user;
|
|
}
|
|
|
|
public function setUser(?User $user): self
|
|
{
|
|
$this->user = $user;
|
|
|
|
if (null !== $user) {
|
|
$this->thirdparty = null;
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getEvent(): ?Event
|
|
{
|
|
return $this->event;
|
|
}
|
|
|
|
public function setEvent(?Event $event): self
|
|
{
|
|
$this->event = $event;
|
|
return $this;
|
|
}
|
|
|
|
public function getAnimator(): User|ThirdParty|null
|
|
{
|
|
return $this->user ?? $this->thirdparty;
|
|
}
|
|
|
|
public function setAnimator(User|ThirdParty|null $animator): self
|
|
{
|
|
if ($animator instanceof User) {
|
|
$this->setUser($animator);
|
|
} elseif ($animator instanceof ThirdParty) {
|
|
$this->setThirdparty($animator);
|
|
} else {
|
|
$this->user = null;
|
|
$this->thirdparty = null;
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function isUser(): bool
|
|
{
|
|
return null !== $this->user;
|
|
}
|
|
|
|
public function isThirdParty(): bool
|
|
{
|
|
return null !== $this->thirdparty;
|
|
}
|
|
}
|