src/Entity/Event.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\TimestampableTrait;
  4. use App\Repository\EventRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\HttpFoundation\File\File;
  9. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. #[ORM\Entity(repositoryClassEventRepository::class)]
  12. #[ORM\UniqueConstraint(name'unique_slug_per_cabinet'columns: ['slug''FK_cabinet'])]
  13. /**
  14. * @Vich\Uploadable
  15. */
  16. class Event
  17. {
  18.     use TimestampableTrait;
  19.     #[ORM\Id]
  20.     #[ORM\GeneratedValue]
  21.     #[ORM\Column(type'integer')]
  22.     private $id;
  23.     #[ORM\Column(type'string'length255)]
  24.     private $title;
  25.     #[ORM\Column(type'string'length20)]
  26.     private $type// 'presentiel', 'webinaire', 'hybride'
  27.     #[ORM\Column(type'datetime')]
  28.     private $startDate;
  29.     #[ORM\Column(type'datetime'nullabletrue)]
  30.     private $endDate;
  31.     #[ORM\Column(type'string'length255nullabletrue)]
  32.     private $location;
  33.     #[ORM\Column(type'string'length255nullabletrue)]
  34.     private $visioLink;
  35.     #[ORM\Column(type'text')]
  36.     private $shortDescription;
  37.     #[ORM\Column(type'string'length255nullabletrue)]
  38.     private $coverImage;
  39.     /**
  40.      * @Vich\UploadableField(mapping="event_images", fileNameProperty="coverImage")
  41.      * @var File|null
  42.      */
  43.     #[Assert\Image(
  44.         maxSize'2M',
  45.         maxSizeMessage'L\'image ne doit pas dépasser 2 Mo.',
  46.         mimeTypesMessage'Veuillez uploader une image valide (JPG, PNG, etc.).'
  47.     )]
  48.     private ?File $coverImageFile null;
  49.     #[ORM\Column(type'string'length255nullabletrue)]
  50.     private ?string $brochurePdf null;
  51.     /**
  52.      * @Vich\UploadableField(mapping="event_pdfs", fileNameProperty="brochurePdf")
  53.      * @var File|null
  54.      */
  55.     #[Assert\File(
  56.         maxSize'10M',
  57.         mimeTypes: ['application/pdf'],
  58.         mimeTypesMessage'Veuillez uploader un fichier PDF valide.',
  59.         maxSizeMessage'Le PDF ne doit pas dépasser 10 Mo.'
  60.     )]
  61.     private ?File $brochurePdfFile null;
  62.     #[ORM\Column(type'integer'nullabletrue)]
  63.     private $maxAttendees;
  64.     #[ORM\Column(type'string'length255)]
  65.     private $slug;
  66.     #[ORM\Column(type'boolean')]
  67.     private $isActive true;
  68.     #[ORM\ManyToOne(targetEntityAccountingFirm::class, inversedBy'events')]
  69.     #[ORM\JoinColumn(name'FK_cabinet'referencedColumnName'id'nullablefalse)]
  70.     private $accountingFirm;
  71.     #[ORM\OneToMany(mappedBy'event'targetEntityEventRegistration::class, orphanRemovaltrue)]
  72.     private $registrations;
  73.     #[ORM\Column(type'boolean')]
  74.     private $allowCompanions false;
  75.     #[ORM\Column(type'array')]
  76.     private $formFields = ['nom''prenom''email''telephone']; // Champs par défaut
  77.     #[ORM\Column(type'text'nullabletrue)]
  78.     private $programPoint1Description;
  79.     #[ORM\Column(type'text'nullabletrue)]
  80.     private $programPoint2Description;
  81.     #[ORM\Column(type'text'nullabletrue)]
  82.     private $programPoint3Description;
  83.     #[ORM\Column(type'text'nullabletrue)]
  84.     private $programPoint4Description;
  85.     #[ORM\Column(type'text'nullabletrue)]
  86.     private $programPoint5Description;
  87.     #[ORM\ManyToOne(targetEntityEmailingClientCampaign::class)]
  88.     private $emailing;
  89.     public function __construct()
  90.     {
  91.         $this->registrations = new ArrayCollection();
  92.     }
  93.     // Getters and Setters...
  94.     public function getId(): ?int
  95.     {
  96.         return $this->id;
  97.     }
  98.     public function getTitle(): ?string
  99.     {
  100.         return $this->title;
  101.     }
  102.     public function setTitle(string $title): self
  103.     {
  104.         $this->title $title;
  105.         return $this;
  106.     }
  107.     public function getType(): ?string
  108.     {
  109.         return $this->type;
  110.     }
  111.     public function setType(string $type): self
  112.     {
  113.         $this->type $type;
  114.         return $this;
  115.     }
  116.     public function getStartDate(): ?\DateTimeInterface
  117.     {
  118.         return $this->startDate;
  119.     }
  120.     public function setStartDate(\DateTimeInterface $startDate): self
  121.     {
  122.         $this->startDate $startDate;
  123.         return $this;
  124.     }
  125.     public function getEndDate(): ?\DateTimeInterface
  126.     {
  127.         return $this->endDate;
  128.     }
  129.     public function setEndDate(?\DateTimeInterface $endDate): self
  130.     {
  131.         $this->endDate $endDate;
  132.         return $this;
  133.     }
  134.     public function getLocation(): ?string
  135.     {
  136.         return $this->location;
  137.     }
  138.     public function setLocation(?string $location): self
  139.     {
  140.         $this->location $location;
  141.         return $this;
  142.     }
  143.     public function getVisioLink(): ?string
  144.     {
  145.         return $this->visioLink;
  146.     }
  147.     public function setVisioLink(?string $visioLink): self
  148.     {
  149.         $this->visioLink $visioLink;
  150.         return $this;
  151.     }
  152.     public function getShortDescription(): ?string
  153.     {
  154.         return $this->shortDescription;
  155.     }
  156.     public function setShortDescription(string $shortDescription): self
  157.     {
  158.         $this->shortDescription $shortDescription;
  159.         return $this;
  160.     }
  161.     public function getCoverImage(): ?string
  162.     {
  163.         return $this->coverImage;
  164.     }
  165.     public function setCoverImage(?string $coverImage): self
  166.     {
  167.         $this->coverImage $coverImage;
  168.         return $this;
  169.     }
  170.     public function getMaxAttendees(): ?int
  171.     {
  172.         return $this->maxAttendees;
  173.     }
  174.     public function setMaxAttendees(?int $maxAttendees): self
  175.     {
  176.         $this->maxAttendees $maxAttendees;
  177.         return $this;
  178.     }
  179.     public function getSlug(): ?string
  180.     {
  181.         return $this->slug;
  182.     }
  183.     public function setSlug(string $slug): self
  184.     {
  185.         $this->slug $slug;
  186.         return $this;
  187.     }
  188.     public function isActive(): ?bool
  189.     {
  190.         return $this->isActive;
  191.     }
  192.     public function setIsActive(bool $isActive): self
  193.     {
  194.         $this->isActive $isActive;
  195.         return $this;
  196.     }
  197.     public function getAccountingFirm(): ?AccountingFirm
  198.     {
  199.         return $this->accountingFirm;
  200.     }
  201.     public function setAccountingFirm(?AccountingFirm $accountingFirm): self
  202.     {
  203.         $this->accountingFirm $accountingFirm;
  204.         return $this;
  205.     }
  206.     /**
  207.      * @return Collection<int, EventRegistration>
  208.      */
  209.     public function getRegistrations(): Collection
  210.     {
  211.         return $this->registrations;
  212.     }
  213.     public function addRegistration(EventRegistration $registration): self
  214.     {
  215.         if (!$this->registrations->contains($registration)) {
  216.             $this->registrations[] = $registration;
  217.             $registration->setEvent($this);
  218.         }
  219.         return $this;
  220.     }
  221.     public function removeRegistration(EventRegistration $registration): self
  222.     {
  223.         if ($this->registrations->removeElement($registration)) {
  224.             // set the owning side to null (unless already changed)
  225.             if ($registration->getEvent() === $this) {
  226.                 $registration->setEvent(null);
  227.             }
  228.         }
  229.         return $this;
  230.     }
  231.     public function getAllowCompanions(): ?bool
  232.     {
  233.         return $this->allowCompanions;
  234.     }
  235.     public function setAllowCompanions(bool $allowCompanions): self
  236.     {
  237.         $this->allowCompanions $allowCompanions;
  238.         return $this;
  239.     }
  240.     public function getFormFields(): array
  241.     {
  242.         return $this->formFields;
  243.     }
  244.     public function setFormFields(array $formFields): self
  245.     {
  246.         $this->formFields $formFields;
  247.         return $this;
  248.     }
  249.     
  250.     /**
  251.      * Get remaining available spots
  252.      */
  253.     public function getRemainingSpots(): ?int
  254.     {
  255.         if ($this->maxAttendees === null) {
  256.             return null// unlimited
  257.         }
  258.         $totalRegistrations 0;
  259.         foreach ($this->registrations as $registration) {
  260.             $totalRegistrations += $registration->getCompanionsCount();
  261.         }
  262.         return max(0$this->maxAttendees $totalRegistrations);
  263.     }
  264.     /**
  265.      * Check if event is full
  266.      */
  267.     public function isFull(): bool
  268.     {
  269.         if ($this->maxAttendees === null) {
  270.             return false;
  271.         }
  272.         return $this->getRemainingSpots() <= 0;
  273.     }
  274.     public function setCoverImageFile(?File $coverImageFile null): self
  275.     {
  276.         $this->coverImageFile $coverImageFile;
  277.         if (null !== $coverImageFile) {
  278.             $this->updatedAt = new \DateTime();
  279.         }
  280.         return $this;
  281.     }
  282.     public function getCoverImageFile(): ?File
  283.     {
  284.         return $this->coverImageFile;
  285.     }
  286.     public function getBrochurePdf(): ?string
  287.     {
  288.         return $this->brochurePdf;
  289.     }
  290.     public function setBrochurePdf(?string $brochurePdf): self
  291.     {
  292.         $this->brochurePdf $brochurePdf;
  293.         return $this;
  294.     }
  295.     public function getBrochurePdfFile(): ?File
  296.     {
  297.         return $this->brochurePdfFile;
  298.     }
  299.     public function setBrochurePdfFile(?File $brochurePdfFile null): self
  300.     {
  301.         $this->brochurePdfFile $brochurePdfFile;
  302.         if (null !== $brochurePdfFile) {
  303.             $this->updatedAt = new \DateTime();
  304.         }
  305.         return $this;
  306.     }
  307.     public function getProgramPoint1Description(): ?string
  308.     {
  309.         return $this->programPoint1Description;
  310.     }
  311.     public function setProgramPoint1Description(?string $programPoint1Description): self
  312.     {
  313.         $this->programPoint1Description $programPoint1Description;
  314.         return $this;
  315.     }
  316.     public function getProgramPoint2Description(): ?string
  317.     {
  318.         return $this->programPoint2Description;
  319.     }
  320.     public function setProgramPoint2Description(?string $programPoint2Description): self
  321.     {
  322.         $this->programPoint2Description $programPoint2Description;
  323.         return $this;
  324.     }
  325.     public function getProgramPoint3Description(): ?string
  326.     {
  327.         return $this->programPoint3Description;
  328.     }
  329.     public function setProgramPoint3Description(?string $programPoint3Description): self
  330.     {
  331.         $this->programPoint3Description $programPoint3Description;
  332.         return $this;
  333.     }
  334.     public function getProgramPoint4Description(): ?string
  335.     {
  336.         return $this->programPoint4Description;
  337.     }
  338.     public function setProgramPoint4Description(?string $programPoint4Description): self
  339.     {
  340.         $this->programPoint4Description $programPoint4Description;
  341.         return $this;
  342.     }
  343.     public function getProgramPoint5Description(): ?string
  344.     {
  345.         return $this->programPoint5Description;
  346.     }
  347.     public function setProgramPoint5Description(?string $programPoint5Description): self
  348.     {
  349.         $this->programPoint5Description $programPoint5Description;
  350.         return $this;
  351.     }
  352.     /**
  353.      * Check if event is finished
  354.      */
  355.     public function isFinished(): bool
  356.     {
  357.         $now = new \DateTime();
  358.         $eventEndDate $this->endDate ?: $this->startDate;
  359.         return $eventEndDate $now;
  360.     }
  361.     public function getEmailing(): ?EmailingClientCampaign
  362.     {
  363.         return $this->emailing;
  364.     }
  365.     public function setEmailing(?EmailingClientCampaign $emailing): self
  366.     {
  367.         $this->emailing $emailing;
  368.         return $this;
  369.     }
  370. }