<?php
namespace App\Entity;
use App\Validator as CustomAssert;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Annotation\ApiSubresource;
use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\ExistsFilter;
use App\Repository\EventRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ApiResource(
* normalizationContext={
* "groups"={"event:read"}
* },
* denormalizationContext={
* "groups"={"event:write"}
* },
* collectionOperations={
* "get"={
* "security"="is_granted('ROLE_USER')"
* }
* },
* itemOperations={
* "get"={
* "security"="is_granted('ROLE_USER')"
* }
* }
* )
* @ApiFilter(DateFilter::class)
* @ApiFilter(SearchFilter::class,
* strategy="exact",
* properties={
* "name":"partial", "status", "company", "isVirtual", "active",
* "registrations.status", "registrations.client"
* }
* )
* @ApiFilter(OrderFilter::class)
* @ApiFilter(ExistsFilter::class, properties={"parent"})
* @ApiFilter(PropertyFilter::class,
* arguments={
* "parameterName"="fields",
* "overrideDefaultProperties"=true
* }
* )
* @ORM\Entity(repositoryClass=EventRepository::class)
*
* @CustomAssert\EventClass
*/
class Event
{
const STATUS_OPEN = 'open'; // the event is open to acquire a specialist
const STATUS_PENDING_SPECIALIST = 'pending_specialist_validation'; // the event is open to acquire a specialist
const STATUS_VALID = 'valid'; // the event has a specialist
const STATUS_CANCELED = 'canceled'; // the event is canceled
const STATUS_FINISHED = 'finished'; // the event is finished
const STATUS_CANCELED_MAIL = 'canceled_mail'; // the event is canceled and send mails
const STATUS_FINISHED_MAIL = 'finished_mail'; // the event is finished and send mails
// CALENDAR TYPE
const CALENDAR_TYPE_MONTHLY = "monthly";
const CALENDAR_TYPE_WEEKLY = "weekly";
const CALENDAR_TYPE_DAILY = "daily";
const CALENDAR_TYPES = [
self::CALENDAR_TYPE_MONTHLY,
self::CALENDAR_TYPE_WEEKLY,
self::CALENDAR_TYPE_DAILY,
];
/**
* Available statuses for the event
*/
const STATUSES = [
self::STATUS_OPEN,
self::STATUS_VALID,
self::STATUS_CANCELED,
self::STATUS_FINISHED,
self::STATUS_CANCELED_MAIL,
self::STATUS_FINISHED_MAIL,
];
const STATUSES_CLOSED = [
self::STATUS_CANCELED,
self::STATUS_FINISHED,
];
const STATUSES_MAILER = [
self::STATUS_CANCELED => self::STATUS_CANCELED_MAIL,
self::STATUS_FINISHED => self::STATUS_FINISHED_MAIL,
];
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @ApiProperty(identifier=true)
* @Groups({"event:read", "event:read:id", "registration:read"})
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
* @Groups({"event:read", "event:read:name", "event:write", "registration:read"})
* @Assert\NotBlank
*/
private $name;
/**
* @ORM\Column(type="text")
* @Groups({"event:read", "event:read:description", "event:write", "registration:read"})
* @Assert\NotBlank
*/
private $description;
/**
* @ORM\Column(type="integer")
* @Groups({"event:read", "event:read:duration", "event:write", "registration:read"})
* @Assert\NotBlank
*/
private $duration;
/**
* @ORM\Column(type="integer")
* @Groups({"event:read", "event:read:capacity", "event:write", "registration:read"})
* @Assert\NotBlank
*/
private $capacity;
/**
* @ORM\Column(type="float")
* @Groups({"event:read", "event:read:price", "event:write", "registration:read"})
*/
private $price = 0;
/**
* @ORM\Column(type="datetime")
* @Groups({"event:read", "event:read:start", "event:write", "registration:read"})
* @Assert\NotBlank
*/
private $start;
/**
* @ORM\Column(type="datetime")
* @Groups({"event:read", "event:read:end", "event:write", "registration:read"})
* @Assert\NotBlank
*/
private $end;
/**
* @ORM\Column(type="float", nullable=true)
* @Groups({"event:read", "event:read:sellingPrice", "event:write", "registration:read"})
*/
private $sellingPrice;
/**
* @ORM\Column(type="float", nullable=true)
* @Groups({"event:read", "event:read:purchasePrice", "event:write"})
*/
private $purchasePrice;
/**
* @ORM\Column(type="float", nullable=true)
* @Groups({"event:read", "event:read:tva", "event:write"})
*/
private $tva;
/**
* @ORM\Column(type="datetime")
* @Gedmo\Timestampable(on="create")
* @Groups({"event:read", "event:read:createdAt", "event:write"})
*/
private $createdAt;
/**
* @ORM\Column(type="datetime", options={"default": "CURRENT_TIMESTAMP"})
* @Gedmo\Timestampable(on="update")
* @Groups({"event:read", "event:read:updatedAt", "event:write"})
*/
private $updatedAt;
/**
* @ORM\ManyToOne(targetEntity=Event::class, inversedBy="children")
* @Groups({"event:read", "event:read:parent", "event:write"})
*/
private $parent;
/**
* @ORM\OneToMany(targetEntity=Event::class, mappedBy="parent", cascade={"all"})
* @Groups({"event:read", "event:read:children", "event:write"})
*/
private $children;
/**
* @ORM\ManyToOne(targetEntity=Workshop::class, inversedBy="events")
* @ORM\JoinColumn(nullable=false)
* @Groups({"event:read", "event:read:workshop", "event:write"})
* @Assert\NotBlank
*/
private $workshop;
/**
* @ORM\ManyToOne(targetEntity=Room::class, inversedBy="events", cascade={"persist"})
* @Groups({"event:read", "event:read:room", "event:write", "registration:read"})
*/
private $room;
/**
* @ORM\ManyToOne(targetEntity=Specialist::class, inversedBy="events")
* @Groups({"event:read", "event:read:specialist", "event:write"})
*/
private $specialist;
/**
* @var Collection|Registration[]
* @ORM\OneToMany(targetEntity=Registration::class, mappedBy="event", orphanRemoval=true)
* @Groups({"event:read", "event:read:registrations", "event:write"})
*/
private $registrations;
/**
* @ORM\ManyToOne(targetEntity=Company::class, inversedBy="events")
* @Groups({"event:read", "event:read:company", "event:write"})
*/
private $company;
/**
* @ORM\Column(type="boolean", options={"default": "1"})
* @Groups({"event:read", "event:read:active", "event:write", "registration:read"})
*/
private $active = true;
/**
* @ORM\Column(type="string", length=255)
* @Groups({"event:read", "event:read:color", "event:write"})
*/
private $color;
/**
* @ORM\OneToMany(targetEntity=SpecialistEventApplication::class, mappedBy="event", orphanRemoval=true)
* @Groups({"event:read", "event:read:applications", "event:write"})
*/
private $applications;
/**
* @ORM\Column(type="string", length=50)
* @Groups({"event:read", "event:read:status", "event:write", "registration:read"})
* @Assert\Choice(choices=self::STATUSES)
*/
private $status = self::STATUS_OPEN;
/**
* If the event is locked it means that a company cannot modify the event
*
* @ORM\Column(type="boolean", options={"default": "0"})
* @Groups({"event:read", "event:read:locked", "event:write"})
*/
private $locked = false;
/**
* @ORM\OneToOne(targetEntity=CancellationParameters::class, mappedBy="event", cascade={"persist", "remove"})
* @Groups({"event:read", "event:read:cancellationParameters", "event:write"})
*/
private $cancellationParameters;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"event:read", "event:read:formLink", "event:write", "registration:read"})
*/
private $formLink;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"event:read", "event:read:statusMail", "event:write"})
*/
private $statusMail;
/**
* @ORM\Column(type="array", nullable=true)
*/
private $statusLogs = [];
/**
* @ORM\OneToMany(targetEntity=CancelEventApplication::class, mappedBy="event", orphanRemoval=true)
* @Groups({"event:read", "event:read:cancelEventApplications", "event:write"})
*/
private $cancelEventApplications;
/**
* Will be filled with a unique id if repeated
* @var string
* @Groups({"event:read", "event:read:repeated"})
*/
private $repeated = null;
/**
* @ORM\Column(type="boolean", options={"default": 0})
* @Groups({"event:read", "event:read:isVirtual", "event:write", "registration:read"})
*/
private $isVirtual = false;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"event:read", "event:read:virtualUrl", "event:write", "registration:read"})
*/
private $virtualUrl;
/**
* @ORM\Column(type="boolean", nullable=true)
* @Groups({"event:read", "event:read:isSpecialistTva", "event:write"})
*/
private $isSpecialistTva;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"event:read", "event:read:updatedBy"})
*/
private $updatedBy;
/**
* @ORM\Column(type="float", nullable=true)
* @Groups({"event:read", "event:read:coefMajoration", "event:write"})
*/
private $coefMajoration;
/**
* @ORM\Column(type="float", nullable=true)
* @Groups({"event:read", "event:read:specialistPrice", "event:write"})
*/
private $specialistPrice;
/**
* @ORM\Column(type="float", nullable=true)
* @Groups({"event:read", "event:read:coefMargin", "event:write"})
*/
private $coefMargin;
/**
* @ORM\OneToMany(targetEntity=AffiliatedEventApplication::class, mappedBy="event", orphanRemoval=true)
* @Groups({"event:read", "event:read:affiliatedEventApplications", "event:write"})
*/
private $affiliatedEventApplications;
/**
* @ORM\OneToOne(targetEntity=MarketplaceReservation::class, mappedBy="event", cascade={"persist", "remove"})
* @Groups({"event:read", "event:read:marketplaceReservation"})
*/
private $marketplaceReservation;
/**
* @ORM\Column(type="boolean", options={"default": 0})
* @Groups({"event:read", "event:read:isMarketplace", "event:write", "registration:read"})
*/
private $isMarketplace = false;
/**
* @ORM\Column(type="boolean", options={"default": 0})
* @Groups({"event:read", "event:read:isFromStats", "event:write", "registration:read"})
*/
private $isFromStats = false;
/**
* @ORM\Column(type="text", nullable=true)
* @Groups({"event:read", "event:read:callsheetComment", "event:write"})
*/
private $callsheetComment;
/**
* @ORM\Column(type="boolean", options={"default": 0})
* @Groups({"event:read", "event:read:overQuota", "event:write"})
*/
private $overQuota = false;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"event:read", "event:read:overQuotaInfo", "event:write"})
*/
private $overQuotaInfo;
/**
* @ORM\Column(type="boolean", options={"default": 0})
* @Groups({"event:read", "event:read:waitingListAssignationAuto", "event:write"})
*/
private $waitingListAssignationAuto = false;
/**
* @ORM\Column(type="boolean", nullable=true, options={"default": 0})
* @Groups({"event:read", "event:read:waitingListDefault", "event:write"})
*/
private $waitingListDefault = false;
/**
* @ORM\ManyToMany(targetEntity=Segmentation::class, inversedBy="events")
* @Groups({"event:read", "event:read:segmentations", "event:write"})
*/
private $segmentations;
/**
* @ORM\Column(type="boolean", options={"default": 0})
* @Groups({"event:read", "event:read:negativeMailSent", "event:write"})
*/
private $negativeMailSent = false;
/**
* Inscriptions disponibles restantes
* @Groups({"event:read", "event:read:remainingAvailableRegistrations", "event:write"})
*/
private $remainingAvailableRegistrations = null;
/**
* @Groups({"event:read", "event:read:isRegistered"})
* @var ?bool
*/
public $isRegistered = null;
public $sendNotification = false;
/**
* @Groups({"event:read", "event:read:imageUrl"})
* @var ?string
*/
private $imageUrl = null;
public function __construct()
{
$this->children = new ArrayCollection();
$this->registrations = new ArrayCollection();
$this->applications = new ArrayCollection();
$this->createdAt = new \DateTime();
$this->updatedAt = new \DateTime();
$this->statusLogs = [];
$this->cancelEventApplications = new ArrayCollection();
$this->affiliatedEventApplications = new ArrayCollection();
$this->segmentations = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description): self
{
$this->description = $description;
return $this;
}
public function getDuration(): ?int
{
return $this->duration;
}
public function setDuration(int $duration): self
{
$this->duration = $duration;
return $this;
}
public function getCapacity(): ?int
{
return $this->capacity;
}
public function setCapacity(int $capacity): self
{
$this->capacity = $capacity;
return $this;
}
public function getPrice(): ?float
{
return $this->price;
}
public function setPrice(?float $price): self
{
$this->price = floatval($price);
return $this;
}
public function getStart(): ?\DateTime
{
return $this->start;
}
public function setStart(\DateTime $start): self
{
$this->start = $start;
return $this;
}
public function getEnd(): ?\DateTime
{
return $this->end;
}
public function setEnd(\DateTime $end): self
{
$this->end = $end;
return $this;
}
public function getCreatedAt(): ?\DateTime
{
return $this->createdAt;
}
public function setCreatedAt(\DateTime $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getParent(): ?self
{
return $this->parent;
}
public function setParent(?self $parent): self
{
$this->parent = $parent;
return $this;
}
/**
* @return Collection|self[]
*/
public function getChildren(): Collection
{
return $this->children;
}
public function addChild(self $child): self
{
if (!$this->children->contains($child)) {
$this->children[] = $child;
$child->setParent($this);
}
return $this;
}
public function removeChild(self $child): self
{
if ($this->children->removeElement($child)) {
// set the owning side to null (unless already changed)
if ($child->getParent() === $this) {
$child->setParent(null);
}
}
return $this;
}
public function getWorkshop(): ?Workshop
{
return $this->workshop;
}
public function setWorkshop(?Workshop $workshop): self
{
$this->workshop = $workshop;
if (empty($this->color)) {
$this->color = $workshop->getColor();
}
return $this;
}
public function getRoom(): ?Room
{
return $this->room;
}
public function setRoom(?Room $room): self
{
$this->room = $room;
$this->setCompany($this->room->getCompany());
return $this;
}
public function getSpecialist(): ?Specialist
{
return $this->specialist;
}
public function setSpecialist(?Specialist $specialist): self
{
$this->specialist = $specialist;
return $this;
}
/**
* @return Collection|Registration[]
*/
public function getRegistrations(): Collection
{
return $this->registrations;
}
public function addRegistration(Registration $registration): self
{
if (!$this->registrations->contains($registration)) {
$this->registrations[] = $registration;
$registration->setEvent($this);
}
return $this;
}
public function removeRegistration(Registration $registration): self
{
if ($this->registrations->removeElement($registration)) {
// set the owning side to null (unless already changed)
if ($registration->getEvent() === $this) {
$registration->setEvent(null);
}
}
return $this;
}
/**
* Permet de récupérer la derniere Registration d'un Client
* @var Client $client
* @return Registration|null
*/
public function getLastClientRegistration(Client $client): ?Registration
{
$lastClientRegistration = null;
if(!empty($this->registrations)) {
foreach($this->registrations as $registration) {
if($registration->getClient() instanceof Client && $registration->getClient()->getId() === $client->getId()
&& (empty($lastClientRegistration) || $registration->getCreatedAt() > $lastClientRegistration->getCreatedAt())) {
$lastClientRegistration = $registration;
}
};
}
return $lastClientRegistration;
}
/**
* @param ArrayCollection $children
* @return Event
*/
public function setChildren(ArrayCollection $children): Event
{
$this->children = $children;
return $this;
}
public function getCompany(): ?Company
{
return $this->company;
}
public function setCompany(?Company $company): self
{
$this->company = $company;
return $this;
}
public function getActive(): ?bool
{
return $this->active;
}
public function setActive(bool $active): self
{
$this->active = $active;
return $this;
}
public function getColor(): ?string
{
return $this->color;
}
public function setColor(?string $color): self
{
if (!empty($color)) {
$this->color = $color;
}
return $this;
}
/**
* @return Collection|SpecialistEventApplication[]
*/
public function getApplications(): Collection
{
return $this->applications;
}
public function addApplication(SpecialistEventApplication $application): self
{
if (!$this->applications->contains($application)) {
$this->applications[] = $application;
$application->setEvent($this);
}
return $this;
}
public function removeApplication(SpecialistEventApplication $application): self
{
if ($this->applications->removeElement($application)) {
// set the owning side to null (unless already changed)
if ($application->getEvent() === $this) {
$application->setEvent(null);
}
}
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(string $status): self
{
$this->status = $status;
return $this;
}
public function getCellColor(): string
{
$now = new \DateTime("now", new \DateTimeZone("Europe/Paris"));
if ($now <= $this->end && $now >= $this->start) {
$result = 'success';
} elseif ($now >= $this->start) {
$result = 'danger';
} else {
$result = 'default';
}
return $result;
}
public function getLocked(): ?bool
{
return $this->locked;
}
public function setLocked(bool $locked): self
{
$this->locked = $locked;
return $this;
}
public function getSellingPrice(): ?float
{
return $this->sellingPrice;
}
public function setSellingPrice(?float $sellingPrice): self
{
$this->sellingPrice = $sellingPrice;
return $this;
}
public function getPurchasePrice(): ?float
{
return $this->purchasePrice;
}
public function setPurchasePrice(?float $purchasePrice): self
{
$this->purchasePrice = $purchasePrice;
return $this;
}
public function getTva(): ?float
{
return $this->tva;
}
public function setTva(?float $tva): self
{
$this->tva = $tva;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getCancellationParameters(): ?CancellationParameters
{
return $this->cancellationParameters;
}
public function setCancellationParameters(?CancellationParameters $cancellationParameters): self
{
// unset the owning side of the relation if necessary
if ($cancellationParameters === null && $this->cancellationParameters !== null) {
$this->cancellationParameters->setEvent(null);
}
// set the owning side of the relation if necessary
if ($cancellationParameters !== null && $cancellationParameters->getEvent() !== $this) {
$cancellationParameters->setEvent($this);
}
$this->cancellationParameters = $cancellationParameters;
return $this;
}
public function getFormLink(): ?string
{
return $this->formLink;
}
public function setFormLink(string $formLink): self
{
$this->formLink = $formLink;
return $this;
}
/**
* Get valid registered participants count
* @return int
*/
public function getRegisteredCount(): int
{
$cnt = 0;
foreach ($this->registrations as $registration) {
if ($registration->isRegistered()) $cnt++;
}
return $cnt;
}
/**
* Get valid registered participants
* @return array
*/
public function getRegistered(): array
{
$registered = [];
foreach ($this->registrations as $registration) {
if ($registration->isRegistered()) $registered[] = $registration;
}
return $registered;
}
public function getStatusMail(): ?string
{
return $this->statusMail;
}
public function setStatusMail(?string $statusMail): self
{
$this->statusMail = $statusMail;
return $this;
}
public function getStatusLogs(): ?array
{
return $this->statusLogs;
}
public function setStatusLogs(?array $statusLogs): self
{
$this->statusLogs = $statusLogs;
return $this;
}
/**
* @return Collection<int, CancelEventApplication>
*/
public function getCancelEventApplications(): Collection
{
return $this->cancelEventApplications;
}
public function addCancelEventApplication(CancelEventApplication $cancelEventApplication): self
{
if (!$this->cancelEventApplications->contains($cancelEventApplication)) {
$this->cancelEventApplications[] = $cancelEventApplication;
$cancelEventApplication->setEvent($this);
}
return $this;
}
public function removeCancelEventApplication(CancelEventApplication $cancelEventApplication): self
{
if ($this->cancelEventApplications->removeElement($cancelEventApplication)) {
// set the owning side to null (unless already changed)
if ($cancelEventApplication->getEvent() === $this) {
$cancelEventApplication->setEvent(null);
}
}
return $this;
}
/**
* Estime le prix d'achat de l'event en fonction un Specialist
*/
public function getEstimatedPurchasePrice($specialist): ?int
{
$estimatedPrice = null;
// Récupérer la catégorie de l'event
$tag = ($this->workshop->getTag() instanceof Tag) ? $this->workshop->getTag() : null;
if($specialist instanceof Specialist) {
$specialistTags = $specialist->getSpecialistTags()->toArray() ?? [];
foreach ($specialistTags as $specialistTag) {
if($specialistTag instanceof SpecialistTag && $specialistTag->getTag() instanceof Tag
&& $specialistTag->getTag()->getId() == $tag->getId()) {
$estimatedPrice = $specialistTag->getPrice();
break;
}
}
}
return $estimatedPrice;
}
/**
* Estime le prix de vente de l'Event en fonction d'un Company
*/
public function getEstimatedSellingPrice($company): ?int
{
$estimatedPrice = null;
if($company instanceof Company) {
}
return $estimatedPrice;
}
/**
* @param string|null $repeated
* @return Event
*/
public function setRepeated(?string $repeated): Event
{
$this->repeated = $repeated;
return $this;
}
/**
* @return string
*/
public function getRepeated(): ?string
{
return $this->repeated;
}
public function isEventRepeated(): bool
{
return !empty($this->repeated);
}
public function getIsVirtual(): ?bool
{
return $this->isVirtual;
}
public function setIsVirtual(bool $isVirtual): self
{
$this->isVirtual = $isVirtual;
return $this;
}
public function getVirtualUrl(): ?string
{
return $this->virtualUrl;
}
public function setVirtualUrl(?string $virtualUrl): self
{
$this->virtualUrl = $virtualUrl;
return $this;
}
public function getIsSpecialistTva(): ?bool
{
return $this->isSpecialistTva;
}
public function setIsSpecialistTva(?bool $isSpecialistTva): self
{
$this->isSpecialistTva = $isSpecialistTva;
return $this;
}
public function getUpdatedBy(): ?string
{
return $this->updatedBy;
}
public function setUpdatedBy(?string $updatedBy): self
{
$this->updatedBy = $updatedBy;
return $this;
}
/**
* Permet de savoir si l'Event est gratuit pour les participants
* @return bool
*/
public function isFree(): bool
{
return ($this->price > 0) ? false : true;
}
/**
* Permet de savoir si l'Event est en cours
* @return bool
*/
public function isInProgress(): bool
{
$now = new \DateTime("now");
return ($now <= $this->end && $now >= $this->start) ? true : false;
}
/**
* Permet de savoir si l'Event est passé
* @return bool
*/
public function isPast(): bool
{
$now = new \DateTime("now");
return ($now > $this->end) ? true : false;
}
/**
* Permet de savoir si l'Event est en attente d'un Specialist
* @return bool
*/
public function isOpen(): bool
{
return ($this->status == $this::STATUS_OPEN) ? true : false;
}
/**
* Permet de savoir si l'Event est a un Specialist
* @return bool
*/
public function isValid(): bool
{
return ($this->status == $this::STATUS_VALID) ? true : false;
}
/**
* Permet de savoir si l'Event est annulé
* @return bool
*/
public function isCanceled(): bool
{
return ($this->status == $this::STATUS_CANCELED) ? true : false;
}
/**
* Permet de savoir si une Demande d'annulation est en cours
* @return bool
*/
public function isCancelEventApplication(): bool
{
foreach($this->cancelEventApplications as $cancelEventApplication) {
if($cancelEventApplication->getStatus() === CancelEventApplication::STATUS_OPEN) {
return true;
}
}
return false;
}
/**
* Permet de récupérer la demande d'annulation en cours
* @return null|CancelEventApplication
*/
public function cancelEventApplicationInProgress(): ?CancelEventApplication
{
foreach($this->cancelEventApplications as $cancelEventApplication) {
if($cancelEventApplication->getStatus() === CancelEventApplication::STATUS_OPEN) {
return $cancelEventApplication;
}
}
return null;
}
/**
* Permet de récupérer la dernière demande d'annulation
* @return null|CancelEventApplication
*/
public function getLastCancelEventApplication(): ?CancelEventApplication
{
$lastCancelEventApplication = null;
if (!empty($this->cancelEventApplications)) {
$lastCancelEventApplication = $this->cancelEventApplications[0];
foreach($this->cancelEventApplications as $cancelEventApplication) {
if($cancelEventApplication->getId() > $lastCancelEventApplication->getId()) {
$lastCancelEventApplication = $cancelEventApplication;
}
}
}
return $lastCancelEventApplication;
}
public function __toString()
{
return $this->getId() . " - " . $this->getName();
}
public function getNotation()
{
// Création variable ou l'on stock la note (default null) et création d'un compteur qui stockera le nombre de registrations valide
$note = null;
$regCount = 0;
// Récup tableau des registrations
$registrations = $this->getRegistrations()->toArray();
// Parcourir le tableau pour valider ou non la présence
// Si present récup workshopNote et ajouter dans la variable qui stock les notes et incrementer le compteur
foreach ($registrations as $registration) {
if ($registration->getWorkshopNote() != null) {
if ($note == null) {
$note = 0;
}
$note += $registration->getWorkshopNote();
$regCount ++;
}
}
// A la fin diviser la variable de note par le compteur si la note n'est pas null
if ($note != null) {
$note /= $regCount;
}
return $note;
}
public function getExpertNotation()
{
// Création variable ou l'on stock la note (default null) et création d'un compteur qui stockera le nombre de registrations valide
$note = null;
$regCount = 0;
// Récup tableau des registrations
$registrations = $this->getRegistrations()->toArray();
// Parcourir le tableau pour valider ou non la présence
// Si present récup expertNote et ajouter dans la variable qui stock les notes et incrementer le compteur
foreach ($registrations as $registration) {
if ($registration->getExpertNote() != null) {
if ($note == null) {
$note = 0;
}
$note += $registration->getExpertNote();
$regCount ++;
}
}
// A la fin diviser la variable de note par le compteur si la note n'est pas null
if ($note != null) {
$note /= $regCount;
}
return $note;
}
public function getNotationVoters()
{
// Création variable ou l'on stock la note (default null) et création d'un compteur qui stockera le nombre de registrations valide
$regCount = 0;
// Récup tableau des registrations
$registrations = $this->getRegistrations()->toArray();
// Parcourir le tableau pour valider ou non la présence
// Si present récup expertNote et ajouter dans la variable qui stock les notes et incrementer le compteur
foreach ($registrations as $registration) {
if ($registration->getPresence() && $registration->getExpertNote() != null && $registration->getWorkshopNote() != null) {
$regCount ++;
}
}
// A la fin diviser la variable de note par le compteur si la note n'est pas null
return $regCount;
}
public function getLimitDateCancellation(): ?\DateTime
{
if($this->getCancellationParameters() instanceof CancellationParameters) {
return $this->getCancellationParameters()->getLimitDate();
}
return null;
}
/**
* Permet de définir si l'event est en warning en fonction d'un certains nombre de jour donné
* et de ses parametres d'annulation
* @var int $limitDays
* @var int $limitHours
*/
public function isWarning(int $limitDays = 0, int $limitHours = 0): bool
{
$minDate = (new \DateTime("now"))->setTime(0,0,1);
$maxDate = (new \DateTime("now"))->setTime(23,59,59);
if($limitDays > 0){
$maxDate->modify("+ {$limitDays} days");
}
if($limitHours > 0){
$maxDate->modify("+ {$limitHours} hours");
}
return (!$this->isPast()
&& $this->getCancellationParameters() instanceof CancellationParameters
&& $this->getLimitDateCancellation() >= $minDate
&& $this->getLimitDateCancellation() <= $maxDate
&& $this->getRegisteredCount() <= $this->getCancellationParameters()->getMinCapacity()
);
}
public function getCoefMajoration(): ?float
{
return $this->coefMajoration;
}
public function setCoefMajoration(?float $coefMajoration): self
{
$this->coefMajoration = $coefMajoration;
return $this;
}
public function getSpecialistPrice(): ?float
{
return $this->specialistPrice;
}
public function setSpecialistPrice(?float $specialistPrice): self
{
$this->specialistPrice = $specialistPrice;
return $this;
}
public function getCoefMargin(): ?float
{
return $this->coefMargin;
}
public function setCoefMargin(?float $coefMargin): self
{
$this->coefMargin = $coefMargin;
return $this;
}
/**
* Permet de savoir si l'event est a venir
*/
public function isInComing(): bool
{
return (!$this->isPast() && $this->status == self::STATUS_VALID);
}
/**
* @return Collection<int, AffiliatedEventApplication>
*/
public function getAffiliatedEventApplications(): Collection
{
return $this->affiliatedEventApplications;
}
public function addAffiliatedEventApplication(AffiliatedEventApplication $affiliatedEventApplication): self
{
if (!$this->affiliatedEventApplications->contains($affiliatedEventApplication)) {
$this->affiliatedEventApplications[] = $affiliatedEventApplication;
$affiliatedEventApplication->setEvent($this);
}
return $this;
}
public function removeAffiliatedEventApplication(AffiliatedEventApplication $affiliatedEventApplication): self
{
if ($this->affiliatedEventApplications->removeElement($affiliatedEventApplication)) {
// set the owning side to null (unless already changed)
if ($affiliatedEventApplication->getEvent() === $this) {
$affiliatedEventApplication->setEvent(null);
}
}
return $this;
}
public function getMarketplaceReservation(): ?MarketplaceReservation
{
return $this->marketplaceReservation;
}
public function setMarketplaceReservation(?MarketplaceReservation $marketplaceReservation): self
{
// unset the owning side of the relation if necessary
if ($marketplaceReservation === null && $this->marketplaceReservation !== null) {
$this->marketplaceReservation->setEvent(null);
}
// set the owning side of the relation if necessary
if ($marketplaceReservation !== null && $marketplaceReservation->getEvent() !== $this) {
$marketplaceReservation->setEvent($this);
}
$this->marketplaceReservation = $marketplaceReservation;
return $this;
}
public function getIsMarketplace(): ?bool
{
return $this->isMarketplace;
}
public function setIsMarketplace(bool $isMarketplace): self
{
$this->isMarketplace = $isMarketplace;
return $this;
}
public function getIsFromStats(): ?bool
{
return $this->isFromStats;
}
public function setIsFromStats(bool $isFromStats): self
{
$this->isFromStats = $isFromStats;
return $this;
}
public function getCallsheetComment(): ?string
{
return $this->callsheetComment;
}
public function setCallsheetComment(?string $callsheetComment): self
{
$this->callsheetComment = $callsheetComment;
return $this;
}
public function getOverQuota(): ?bool
{
return $this->overQuota;
}
public function isOverQuota(): ?bool
{
return $this->overQuota;
}
public function setOverQuota(bool $overQuota): self
{
$this->overQuota = $overQuota;
return $this;
}
public function getOverQuotaInfo(): ?string
{
return $this->overQuotaInfo;
}
public function setOverQuotaInfo(?string $overQuotaInfo): self
{
$this->overQuotaInfo = $overQuotaInfo;
return $this;
}
/**
* Permet de savoir si l'Event est complet (inscriptions)
* @return bool
*/
public function isFull(): bool
{
return ($this->getRegisteredCount() >= $this->getCapacity());
}
/**
* Permet de savoir si l'Event est plus que complet (inscriptions)$
* @return bool
*/
public function isOverFull(): bool
{
return ($this->getRegisteredCount() > $this->getCapacity());
}
/**
* Permet de récupérer les Registration sur liste d'attente
* @return array
*/
public function getWaitingList(): array
{
$waitingList = [];
foreach($this->getRegistrations() as $registration) {
if($registration->isOnWaitingList()) $waitingList[] = $registration;
}
return $waitingList;
}
/**
* Compte le nombre de Registration de la liste d'attente
* @return int
*/
public function getWaitingListCount(): int
{
return count($this->getWaitingList());
}
public function getWaitingListAssignationAuto(): ?bool
{
return $this->waitingListAssignationAuto;
}
public function setWaitingListAssignationAuto(bool $waitingListAssignationAuto): self
{
$this->waitingListAssignationAuto = $waitingListAssignationAuto;
return $this;
}
public function getWaitingListDefault(): ?bool
{
return $this->waitingListDefault;
}
public function setWaitingListDefault(?bool $waitingListDefault): self
{
$this->waitingListDefault = $waitingListDefault;
return $this;
}
/**
* Permet de savoir si c'est un parent
*/
public function isParent(): bool
{
return (!$this->getChildren()->isEmpty());
}
/**
* Permet de savoir si c'est un enfant
*/
public function isChild(): bool
{
return ($this->getParent() instanceof Event);
}
/**
* Permet de savoir si il contient des enfants
*/
public function hasChildren(): bool
{
return (!$this->getChildren()->isEmpty());
}
/**
* @return Collection<int, Segmentation>
*/
public function getSegmentations(): Collection
{
return $this->segmentations;
}
public function addSegmentation(Segmentation $segmentation): self
{
if (!$this->segmentations->contains($segmentation)) {
$this->segmentations[] = $segmentation;
}
return $this;
}
public function removeSegmentation(Segmentation $segmentation): self
{
$this->segmentations->removeElement($segmentation);
return $this;
}
public function getNegativeMailSent(): ?bool
{
return $this->negativeMailSent;
}
public function setNegativeMailSent(bool $negativeMailSent): self
{
$this->negativeMailSent = $negativeMailSent;
return $this;
}
public function getRemainingAvailableRegistrations(): ?int
{
$this->remainingAvailableRegistrations = $this->capacity - $this->getRegisteredCount();
return abs($this->remainingAvailableRegistrations);
}
public function getImageUrl(): ?string
{
if($this->getWorkshop() instanceof Workshop) {
$this->imageUrl = $this->getWorkshop()->getImageUrl();
}
return $this->imageUrl;
}
public function setImageUrl(string $imageUrl): self
{
$this->imageUrl = $imageUrl;
return $this;
}
}