- <?php
- namespace AppEntity;
- use AppRepositoryEventTranslationRepository;
- use DoctrineDBALTypesTypes;
- use DoctrineORMMapping as ORM;
- #[ORMEntity(repositoryClass: EventTranslationRepository::class)]
- class EventTranslation
- {
- #[ORMId]
- #[ORMGeneratedValue]
- #[ORMColumn]
- private ?int $id = null;
- #[ORMColumn(length: 2, nullable: true)]
- private ?string $locale = null;
- #[ORMColumn(length: 255, nullable: true)]
- private ?string $title = null;
- #[ORMOneToOne(mappedBy: 'eventTranslationDe', targetEntity: Event::class, cascade: ['persist', 'remove'])]
- private ?Event $eventDe;
- #[ORMOneToOne(mappedBy: 'eventTranslationEn', targetEntity: Event::class, cascade: ['persist', 'remove'])]
- private ?Event $eventEn;
- #[ORMColumn(length: 255, nullable: true)]
- private ?string $location = null;
- #[ORMColumn(type: Types::TEXT, nullable: true)]
- private ?string $teaser = null;
- #[ORMColumn(length: 255, nullable: true)]
- private ?string $registrationButtonText = null;
- #[ORMColumn(nullable: true)]
- private ?int $eventsTemplate = null;
- #[ORMColumn(length: 255, nullable: true)]
- private ?string $templateHeadline = null;
- #[ORMColumn(type: Types::TEXT, nullable: true)]
- private ?string $templateAdditionalInfos = null;
- #[ORMColumn(type: Types::TEXT, nullable: true)]
- private ?string $templateText = null;
- #[ORMColumn(type: Types::TEXT, nullable: true)]
- private ?string $footerText = null;
- public function __toString(): string {
- return $this->getTitle() !== null ? (string) $this->getTitle() : 'Event Translation Id: ' . $this->id;
- }
- public function getId(): ?int
- {
- return $this->id;
- }
- public function getLocale(): ?string
- {
- return $this->locale;
- }
- public function setLocale(string $locale): static
- {
- $this->locale = $locale;
- return $this;
- }
- public function getTitle(): ?string
- {
- return $this->title;
- }
- public function setTitle(?string $title): static
- {
- $this->title = $title;
- return $this;
- }
- public function getEventDe(): ?Event
- {
- return $this->eventDe;
- }
- public function addEventDe(Event $eventDe): static
- {
- if (!$this->eventDe->contains($eventDe)) {
- $this->eventDe->add($eventDe);
- $eventDe->setEventTranslationDe($this);
- }
- return $this;
- }
- public function removeEventDe(Event $eventDe): static
- {
- if ($this->eventDe->removeElement($eventDe)) {
- // set the owning side to null (unless already changed)
- if ($eventDe->getEventTranslationDe() === $this) {
- $eventDe->setEventTranslationDe(null);
- }
- }
- return $this;
- }
- public function getEventEn(): ?Event
- {
- return $this->eventEn;
- }
- public function addEventEn(Event $eventEn): static
- {
- if (!$this->eventEn->contains($eventEn)) {
- $this->eventEn->add($eventEn);
- $eventEn->setEventTranslationEn($this);
- }
- return $this;
- }
- public function removeEventEn(Event $eventEn): static
- {
- if ($this->eventEn->removeElement($eventEn)) {
- // set the owning side to null (unless already changed)
- if ($eventEn->getEventTranslationEn() === $this) {
- $eventEn->setEventTranslationEn(null);
- }
- }
- return $this;
- }
- public function getLocation(): ?string
- {
- return $this->location;
- }
- public function setLocation(?string $location): static
- {
- $this->location = $location;
- return $this;
- }
- public function getTeaser(): ?string
- {
- return $this->teaser;
- }
- public function setTeaser(?string $teaser): static
- {
- $this->teaser = $teaser;
- return $this;
- }
- public function getRegistrationButtonText(): ?string
- {
- return $this->registrationButtonText;
- }
- public function setRegistrationButtonText(?string $registrationButtonText): static
- {
- $this->registrationButtonText = $registrationButtonText;
- return $this;
- }
- public function toArray(): array {
- return [
- 'title' => $this->getTitle(),
- 'location' => $this->getLocation(),
- 'buttonText' => $this->getRegistrationButtonText(),
- 'teaser' => $this->getTeaser(),
- 'templateHeadline' => $this->getTemplateHeadline(),
- 'templateAdditionalInofs' => $this->getTemplateAdditionalInfos(),
- 'templateText' => $this->getTemplateText(),
- 'templateFooterText' => $this->getFooterText(),
- ];
- }
- public function getEventsTemplate(): ?int
- {
- return $this->eventsTemplate;
- }
- public function setEventsTemplate(?int $eventsTemplate): static
- {
- $this->eventsTemplate = $eventsTemplate;
- return $this;
- }
- public function getTemplateHeadline(): ?string
- {
- return $this->templateHeadline;
- }
- public function setTemplateHeadline(?string $templateHeadline): static
- {
- $this->templateHeadline = $templateHeadline;
- return $this;
- }
- public function getTemplateAdditionalInfos(): ?string
- {
- return $this->templateAdditionalInfos;
- }
- public function setTemplateAdditionalInfos(?string $templateAdditionalInfos): static
- {
- $this->templateAdditionalInfos = $templateAdditionalInfos;
- return $this;
- }
- public function getTemplateText(): ?string
- {
- return $this->templateText;
- }
- public function setTemplateText(?string $templateText): static
- {
- $this->templateText = $templateText;
- return $this;
- }
- public function getFooterText(): ?string
- {
- return $this->footerText;
- }
- public function setFooterText(?string $footerText): static
- {
- $this->footerText = $footerText;
- return $this;
- }
- }
- <?php
- namespace AppEntity;
- use AppEventListenerEventEntityListener;
- use AppRepositoryEventRepository;
- use DateTime;
- use DateTimeImmutable;
- use DateTimeInterface;
- use DoctrineCommonCollectionsArrayCollection;
- use DoctrineCommonCollectionsCollection;
- use DoctrineDBALTypesTypes;
- use DoctrineORMEntityManagerInterface;
- use DoctrineORMMapping as ORM;
- use SymfonyComponentSecurityCoreAuthenticationTokenStorageTokenStorageInterface;
- #[ORMEntity(repositoryClass: EventRepository::class)]
- #[ORMEntityListeners([EventEntityListener::class])]
- class Event
- {
- #[ORMId]
- #[ORMGeneratedValue]
- #[ORMColumn]
- private ?int $id = null;
- #[ORMColumn(length: 255, nullable: true)]
- #[AssertFile(mimeTypes: 'image/jpeg, image/jpg', mimeTypesMessage: 'Please upload a valid image (JPEG or JPG Format)', disallowEmptyMessage: 'Please select an image file.')]
- private ?string $image = null;
- #[ORMColumn(type: Types::DATE_MUTABLE)]
- private ?DateTimeInterface $startDate = null;
- #[ORMOneToOne(inversedBy: 'eventDe', cascade: ['persist', 'remove'])]
- #[ORMJoinColumn(nullable: false)]
- private ?EventTranslation $eventTranslationDe = null;
- #[ORMOneToOne(inversedBy: 'eventEn', cascade: ['persist', 'remove'])]
- #[ORMJoinColumn(nullable: false)]
- private ?EventTranslation $eventTranslationEn = null;
- #[ORMColumn(type: Types::DATE_MUTABLE, nullable: true)]
- private ?DateTimeInterface $endDate = null;
- #[ORMColumn(type: Types::DATE_MUTABLE, nullable: true)]
- private ?DateTimeInterface $dateSignUpClose = null;
- #[ORMColumn(nullable: true)]
- private ?float $itemNr = null;
- #[ORMManyToMany(targetEntity: Category::class, inversedBy: 'events', fetch: 'EAGER')]
- private Collection $categories;
- #[ORMColumn(nullable: true)]
- private ?int $maxDrivers = null;
- #[ORMColumn(nullable: true)]
- private ?int $availableBreakpoint = null;
- #[ORMColumn(type: Types::DATETIME_MUTABLE)]
- private ?DateTimeInterface $lastModified = null;
- #[ORMColumn(length: 255, nullable: true)]
- private ?string $lastModifiedBy = null;
- #[ORMColumn(nullable: true)]
- private ?int $bookingStatus = null;
- #[ORMManyToOne(inversedBy: 'events')]
- private ?Organiser $organiser = null;
- #[ORMColumn(nullable: true)]
- private ?int $template = null;
- #[ORMOneToMany(mappedBy: 'event', targetEntity: ImageSlider::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
- private Collection $templateImageSlider;
- #[ORMOneToMany(mappedBy: 'event', targetEntity: EventVarietyCollection::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
- private Collection $eventVarietyCollection;
- #[ORMColumn(nullable: true)]
- private ?int $travelType = null;
- #[ORMColumn(nullable: true)]
- private ?int $status = null;
- #[ORMOneToMany(mappedBy: 'event', targetEntity: Booking::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
- private Collection $booking;
- public function __construct()
- {
- $this->categories = new ArrayCollection();
- $this->templateImageSlider = new ArrayCollection();
- $this->eventVarietyCollection = new ArrayCollection();
- $this->booking = new ArrayCollection();
- }
- public function getId(): ?int
- {
- return $this->id;
- }
- public function getImage(): ?string
- {
- return $this->image;
- }
- public function setImage(?string $image): static
- {
- $this->image = $image;
- return $this;
- }
- public function getStartDate(): ?DateTimeInterface
- {
- return $this->startDate;
- }
- public function setStartDate(DateTimeInterface $startDate): static
- {
- $this->startDate = $startDate;
- return $this;
- }
- public function getEventTranslationDe(): ?EventTranslation
- {
- return $this->eventTranslationDe;
- }
- public function setEventTranslationDe(?EventTranslation $eventTranslationDe): static
- {
- $this->eventTranslationDe = $eventTranslationDe;
- $this->eventTranslationDe->setLocale('de');
- return $this;
- }
- public function getEventTranslationEn(): ?EventTranslation
- {
- return $this->eventTranslationEn;
- }
- public function setEventTranslationEn(?EventTranslation $eventTranslationEn): static
- {
- $this->eventTranslationEn = $eventTranslationEn;
- $this->eventTranslationEn->setLocale('en');
- return $this;
- }
- public function getEndDate(): ?DateTimeInterface
- {
- return $this->endDate;
- }
- public function setEndDate(?DateTimeInterface $endDate): static
- {
- $this->endDate = $endDate;
- return $this;
- }
- public function getDateSignUpClose(): ?DateTimeInterface
- {
- return $this->dateSignUpClose;
- }
- public function setDateSignUpClose(?DateTimeInterface $dateSignUpClose): static
- {
- $this->dateSignUpClose = $dateSignUpClose;
- return $this;
- }
- public function getItemNr(): ?float
- {
- return $this->itemNr;
- }
- public function setItemNr(?float $itemNr): static
- {
- $this->itemNr = $itemNr;
- return $this;
- }
- /**
- * @return Collection<int, Category>
- */
- public function getCategories(): Collection
- {
- return $this->categories;
- }
- public function addCategory(Category $category): static
- {
- if (!$this->categories->contains($category)) {
- $this->categories->add($category);
- }
- return $this;
- }
- public function removeCategory(Category $category): static
- {
- $this->categories->removeElement($category);
- return $this;
- }
- public function getMaxDrivers(): ?int
- {
- return $this->maxDrivers;
- }
- public function setMaxDrivers(?int $maxDrivers): static
- {
- $this->maxDrivers = $maxDrivers;
- return $this;
- }
- public function getAvailableBreakpoint(): ?int
- {
- return $this->availableBreakpoint;
- }
- public function setAvailableBreakpoint(?int $availableBreakpoint): static
- {
- $this->availableBreakpoint = $availableBreakpoint;
- return $this;
- }
- public function getLastModified(): ?DateTimeInterface
- {
- return $this->lastModified;
- }
- public function setLastModified(): static
- {
- date_default_timezone_set('Europe/Berlin');
- $this->lastModified = new DateTimeImmutable('now');
- return $this;
- }
- public function getEventTranslation(string $locale = 'en'): array
- {
- return $locale === 'de' ? $this->getEventTranslationDe()->toArray() : $this->getEventTranslationEn()->toArray();
- }
- public function getCategoriesArray($locale): array
- {
- $categories = $this->getCategories()->toArray();
- return array_map(fn($category) => $category->toArray($locale), $categories);
- }
- public function getBookingStatus(): ?int
- {
- // if bookingStatus is not customised set to 'Preview'
- if ($this->bookingStatus == null) {
- $this->bookingStatus = 0;
- }
- return $this->bookingStatus;
- }
- public function setBookingStatus(int $bookingStatus): static
- {
- $this->bookingStatus = $bookingStatus;
- return $this;
- }
- public function getOrganiser(): ?Organiser
- {
- return $this->organiser;
- }
- public function setOrganiser(?Organiser $organiser): static
- {
- $this->organiser = $organiser;
- return $this;
- }
- public function getBookingStatusString($locale): ?string
- {
- if ($locale == 'en') {
- $bookingStatusArray = ['Preview', 'Available', 'Not Available', 'Review', 'On Request'];
- } else {
- $bookingStatusArray = ['Vorschau', 'Verfügbar', 'Nicht mehr verfügbar', 'Rückblick', 'Auf Anfrage'];
- }
- return $bookingStatusArray[$this->getBookingStatus()] ?? null;
- }
- public function getTravelTypeString(): ?string
- {
- $bookingStatusArray = ['none', 'packageTravel'];
- return $bookingStatusArray[$this->getTravelType()] ?? null;
- }
- public function getStatusString(): ?string
- {
- $statusArray = ['draft', 'live'];
- return $statusArray[$this->getStatus()] ?? null;
- }
- public function getSliderImages($entityManager): array
- {
- $imageSliderEntities = $entityManager->getRepository(ImageSlider::class)->findBy(['event' => $this->getId()]);
- $sliderImages = [];
- foreach ($imageSliderEntities as $imageSliderEntity) {
- $sliderImages[] = '/uploads/images/event/slider/' . $imageSliderEntity->getImage();
- }
- return $sliderImages;
- }
- private function mapVarietyDataContent($entityManager, $varietyCollection): array
- {
- $formFields = [];
- $varietyCollectionFormFields = $entityManager->getRepository(VarietyCollectionFormField::class)
- ->findBy(['varietyCollection' => $varietyCollection->getId()]);
- foreach ($varietyCollectionFormFields as $varietyCollectionFormField) {
- $formFields[] = [
- 'id' => $varietyCollectionFormField->getId(),
- 'inputType' => $varietyCollectionFormField->getInputType(),
- 'label' => $varietyCollectionFormField->getLabel(),
- 'isRequired' => $varietyCollectionFormField->isIsRequired(),
- ];
- }
- return [
- 'id' => $varietyCollection->getId(),
- 'textTop' => $varietyCollection->getTextTop(),
- 'textBottom' => $varietyCollection->getTextBottom(),
- 'halfWidth' => $varietyCollection->isHalfWidth(),
- 'formFields' => $formFields,
- ];
- }
- private function mapVarietyData($variety, $entityManager): array
- {
- $varietyContent = [];
- if ($variety) {
- $varietyCollections = $entityManager->getRepository(VarietyCollection::class)
- ->findBy(['variety' => $variety->getId()]);
- foreach ($varietyCollections as $varietyCollection) {
- $varietyContent[] = $this->mapVarietyDataContent($entityManager, $varietyCollection);
- }
- return [
- 'id' => $variety->getId(),
- 'neededSeats' => $variety->getNeededSeats(),
- 'title' => $variety->getTitle(),
- 'varietyContent' => $varietyContent,
- ];
- }
- return [];
- }
- public function getFormattedPrice($price, $locale)
- {
- $dotPosition = strpos($price, '.');
- $commaPosition = strpos($price, ',');
- if ($dotPosition && $commaPosition) {
- if (($dotPosition < $commaPosition && $locale == 'en') || ($dotPosition >= $commaPosition && $locale == 'de')) {
- $formattedNumber = str_replace('.', '|', $price);
- $formattedNumber = str_replace(',', '.', $formattedNumber);
- return str_replace('|', ',', $formattedNumber);
- } else {
- return $price;
- }
- } else {
- if ($dotPosition && $locale != 'en') {
- return str_replace('.', ',', $price);
- }
- if ($commaPosition && $locale == 'en') {
- return str_replace(',', '.', $price);
- }
- return $price;
- }
- }
- public function getEventsVarieties($entityManager, $locale): array
- {
- $eventVarietyCollections = $entityManager->getRepository(EventVarietyCollection::class)
- ->findBy(['event' => $this->getId()]);
- $varieties = [];
- $accompanyingPersonVarieties = [];
- foreach ($eventVarietyCollections as $eventVarietyCollection) {
- $tempArray = [
- 'id' => $eventVarietyCollection->getId(),
- 'variety' => $this->mapVarietyData($eventVarietyCollection->getVariety(), $entityManager),
- 'price' => $this->getFormattedPrice($eventVarietyCollection->getPrice(), $locale),
- 'maximumSelectableAmount' => $eventVarietyCollection->getMaximumSelectableAmount()
- ];
- // sort for varieties and accompaningVarieties
- $eventVarietyCollection->isIsAccompanyingPersonVariety() ?
- $accompanyingPersonVarieties[] = $tempArray : $varieties[] = $tempArray;
- }
- return ['eventsVarieties' => $varieties, 'eventsAccompanyingPersonVarieties' => $accompanyingPersonVarieties];
- }
- private function getSlugOfTitle($title): string
- {
- //remove spacen and / and make strin lowercase only
- return strtolower(preg_replace('/s+/ ', '-', $title));
- }
- public function toArray(EntityManagerInterface $entityManager, string $locale = 'en', bool $isDetail = false): array
- {
- $translation = $this->getEventTranslation($locale);
- $image = $this->getImage() != null ? '/uploads/images/event/' . $this->getImage() : null;
- $array = [
- 'id' => $this->getId(),
- 'title' => $translation['title'],
- 'slug' => $this->getSlugOfTitle($translation['title']),
- 'itemNr' => $this->getItemNr(),
- 'date' => $this->getStartDate(),
- 'endDate' => $this->getEndDate(),
- 'categories' => $this->getCategoriesArray($locale),
- 'image' => $image,
- 'location' => $translation['location'],
- 'buttonText' => $translation['buttonText'],
- 'travelType' => $this->getTravelTypeString(),
- 'status' => $this->getStatusString(),
- 'type' => $this->getBookingStatusString($locale),
- ];
- if ($this->getOrganiser()) {
- $array['organiser'] = $this->getOrganiser()->toArray($locale);
- } else {
- $array['organiser'] = null;
- }
- if ($isDetail) {
- $currentDate = new DateTime(); // Get the current date and time
- $currentDate->setTime(0, 0, 0);
- $varieties = $this->getEventsVarieties($entityManager, $locale);
- $array['teaser'] = $translation['teaser'];
- $array['maximumSeatAmount'] = $this->getMaxDrivers();
- $array['availabilityBreakpoint'] = $this->getAvailableBreakpoint();
- if ($this->getStartDate() >= $currentDate) {
- $array['availableSeats'] = $this->getAvailableSeats();
- } else {
- $array['availableSeats'] = 0;
- }
- $array['sliderImages'] = $this->getSliderImages($entityManager);
- $array['templateHeadline'] = $translation['templateHeadline'];
- $array['templateAdditionalInofs'] = $translation['templateAdditionalInofs'];
- $array['templateText'] = $translation['templateText'];
- $array['templateFooterText'] = $translation['templateFooterText'];
- $array['eventsVarieties'] = $varieties['eventsVarieties'];
- $array['eventsAccompanyingPersonVarieties'] = $varieties['eventsAccompanyingPersonVarieties'];
- }
- return $array;
- }
- public function getTemplate(): ?int
- {
- return $this->template;
- }
- public function setTemplate(?int $template): static
- {
- $this->template = $template;
- return $this;
- }
- /**
- * @return Collection<int, ImageSlider>
- */
- public function getTemplateImageSlider(): Collection
- {
- return $this->templateImageSlider;
- }
- public function addTemplateImageSlider(ImageSlider $templateImageSlider): static
- {
- if (!$this->templateImageSlider->contains($templateImageSlider)) {
- $this->templateImageSlider->add($templateImageSlider);
- $templateImageSlider->setEvent($this);
- }
- return $this;
- }
- public function removeTemplateImageSlider(ImageSlider $templateImageSlider): static
- {
- if ($this->templateImageSlider->removeElement($templateImageSlider)) {
- // set the owning side to null (unless already changed)
- if ($templateImageSlider->getEvent() === $this) {
- $templateImageSlider->setEvent(null);
- }
- }
- return $this;
- }
- /**
- * @return Collection<int, EventVarietyCollection>
- */
- public function getEventVarietyCollection(): Collection
- {
- return $this->eventVarietyCollection;
- }
- public function addEventVarietyCollection(EventVarietyCollection $eventVarietyCollection): static
- {
- if (!$this->eventVarietyCollection->contains($eventVarietyCollection)) {
- $this->eventVarietyCollection->add($eventVarietyCollection);
- $eventVarietyCollection->setEvent($this);
- }
- return $this;
- }
- public function removeEventVarietyCollection(EventVarietyCollection $eventVarietyCollection): static
- {
- if ($this->eventVarietyCollection->removeElement($eventVarietyCollection)) {
- // set the owning side to null (unless already changed)
- if ($eventVarietyCollection->getEvent() === $this) {
- $eventVarietyCollection->setEvent(null);
- }
- }
- return $this;
- }
- public function getTravelType(): ?int
- {
- // if travelType is not customised set to 'none'
- if ($this->travelType == null) {
- $this->travelType = 0;
- }
- return $this->travelType;
- }
- public function setTravelType(?int $travelType): static
- {
- $this->travelType = $travelType;
- return $this;
- }
- public function getStatus(): ?int
- {
- // if status is not customised set to 'none'
- if ($this->status == null) {
- $this->status = 0;
- }
- return $this->status;
- }
- public function setStatus(?int $status): static
- {
- $this->status = $status;
- return $this;
- }
- public function getBookedBlockedSeats(): int
- {
- $bookings = $this->getBooking();
- $totalCalculatedSeatAmount = 0;
- foreach ($bookings as $booking) {
- $totalCalculatedSeatAmount += $booking->getCalculatedSeatAmount();
- }
- return $totalCalculatedSeatAmount;
- }
- public function getTemporaryBlockedSeats(): int
- {
- // müsste bei hinzufügen zum Warenkorb noch berechnet werden und beim löschen aus dem Warenkorb wieder abgezogen werden
- return 0;
- }
- public function getBookableBlocked(): string
- {
- $blocked = $this->getBookedBlockedSeats();
- $bookable = $this->maxDrivers;
- return $bookable . '/' . $blocked;
- }
- public function getAvailableSeats(): int
- {
- $blocked = $this->getBookedBlockedSeats();
- $bookable = $this->maxDrivers;
- $temporaryBlocked = $this->getTemporaryBlockedSeats();
- return $bookable - $blocked - $temporaryBlocked;
- }
- /**
- * @return Collection<int, Booking>
- */
- public function getBooking(): Collection
- {
- return $this->booking;
- }
- public function addBooking(Booking $booking): static
- {
- if (!$this->booking->contains($booking)) {
- $this->booking->add($booking);
- $booking->setEvent($this);
- }
- return $this;
- }
- public function removeBooking(Booking $booking): static
- {
- if ($this->booking->removeElement($booking)) {
- // set the owning side to null (unless already changed)
- if ($booking->getEvent() === $this) {
- $booking->setEvent(null);
- }
- }
- return $this;
- }
- public function getLastModifiedBy(): ?string
- {
- return $this->lastModifiedBy;
- }
- public function setLastModifiedBy(TokenStorageInterface $tokenStorage): static {
- $user = $tokenStorage->getToken()->getUser();
- $this->lastModifiedBy = $user->getEmail();
- return $this;
- }
- }