src/Entity/Event.php line 18

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