<?php
namespace App\Entity;
use App\Repository\TourRepository;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
use JMS\Serializer\Annotation\MaxDepth;
#[ORM\Entity(repositoryClass: TourRepository::class)]
#[ORM\HasLifecycleCallbacks]
class Tour
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Serializer\Groups(["tour","poi","category"])]
private ?int $id = null;
#[ORM\OneToOne(cascade: ['persist', 'remove'])]
#[MaxDepth(1)]
#[Serializer\Groups(["tour"])]
private ?AudioTextBlock $title = null;
#[ORM\OneToOne(cascade: ['persist', 'remove'])]
#[MaxDepth(1)]
#[Serializer\Groups(["tour"])]
private ?AudioTextBlock $description = null;
#[ORM\OneToOne(cascade: ['persist', 'remove'])]
#[MaxDepth(1)]
#[Serializer\Groups(["tour"])]
#[Serializer\SerializedName("shortDescription")]
private ?AudioTextBlock $short_description = null;
#[ORM\Column(length: 255, nullable: true)]
#[Serializer\Groups(["tour"])]
#[Serializer\SerializedName("previewImageUrl")]
private ?string $preview_image_url = null;
#[ORM\Column(length: 2048, nullable: true)]
#[Serializer\Groups(["tour"])]
#[Serializer\SerializedName("completionText")]
private ?string $completion_text = null;
#[ORM\Column(length: 2048, nullable: true)]
#[Serializer\Groups(["tour"])]
#[Serializer\SerializedName("guideCompletionText")]
private ?string $guide_completion_text = null;
#[ORM\Column(length: 255, nullable: true)]
#[Serializer\Groups(["tour"])]
#[Serializer\SerializedName("audioGuideCompletionTextUrl")]
private ?string $audio_guide_completion_text_url = null;
#[ORM\Column(length: 255, nullable: true)]
#[Serializer\Groups(["tour"])]
#[Serializer\SerializedName("approximateDuration")]
private ?string $approximate_duration = null;
#[ORM\Column(length: 255, nullable: true)]
#[Serializer\Groups(["tour"])]
#[Serializer\SerializedName("approximateLength")]
private ?string $approximate_length = null;
#[ORM\Column(nullable: true)]
#[Serializer\Groups(["tour"])]
#[Serializer\SerializedName("notificationDistance")]
private ?int $notification_distance = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
#[Serializer\Groups(["tour"])]
#[Serializer\SerializedName("updatedAt")]
private ?DateTime $updated_at = null;
#[ORM\OneToMany(mappedBy: 'tour', targetEntity: TourPoi::class, cascade: ["persist","remove"], orphanRemoval: true)]
#[MaxDepth(2)]
private Collection $pois;
#[ORM\Column(length: 255, nullable: true)]
#[Serializer\Groups(["tour"])]
private ?string $titlevalue = null;
#[ORM\ManyToMany(targetEntity: Category::class, mappedBy: 'tours')]
#[MaxDepth(1)]
private Collection $categories;
#[ORM\ManyToMany(targetEntity: AudioTextBlock::class,cascade: ['persist', 'remove'])]
#[ORM\JoinTable(name:"tourtextblockguidestart")]
#[MaxDepth(1)]
#[Serializer\Groups(["tour"])]
#[Serializer\SerializedName("guideTextBlocksStart")]
private Collection $guide_text_blocks_start;
#[ORM\ManyToMany(targetEntity: AudioTextBlock::class,cascade: ['persist', 'remove'])]
#[ORM\JoinTable(name:"tourtextblockguidecompletion")]
#[MaxDepth(1)]
#[Serializer\Groups(["tour"])]
#[Serializer\SerializedName("guideTextBlocksCompletion")]
private Collection $guide_text_blocks_completion;
#[ORM\ManyToMany(targetEntity: AudioTextBlock::class,cascade: ['persist', 'remove'])]
#[ORM\JoinTable(name:"tourtextblockcompletion")]
#[MaxDepth(1)]
#[Serializer\Groups(["tour"])]
#[Serializer\SerializedName("textBlocksCompletion")]
private Collection $text_blocks_completion;
#[ORM\ManyToMany(targetEntity: AudioTextBlock::class,cascade: ['persist', 'remove'])]
#[ORM\JoinTable(name:"tourtextblocknotification")]
#[MaxDepth(1)]
#[Serializer\Groups(["tour"])]
#[Serializer\SerializedName("notificationText")]
private Collection $notification_text;
#[ORM\Column(nullable: true)]
#[Serializer\Groups(["tour"])]
private ?bool $live = null;
#[Serializer\Groups(["tour"])]
#[Serializer\VirtualProperty()]
#[Serializer\SerializedName("pois")]
public function getPoiIDs(){
$pois = $this->getPois();
$poiIds = [];
foreach ($pois as $poi) {
$poiIds[]=$poi->getId();
}
return $poiIds ;
}
#[Serializer\Groups(["tour"])]
#[Serializer\VirtualProperty()]
#[Serializer\SerializedName("categories")]
public function getCategoryIDs(){
$categories = $this->getCategories();
$categoryIds = [];
foreach ($categories as $category) {
$categoryIds[]=$category->getId();
}
return $categoryIds ;
}
public function __construct()
{
$this->pois = new ArrayCollection();
$this->categories = new ArrayCollection();
$this->guide_text_blocks_start = new ArrayCollection();
$this->guide_text_blocks_completion = new ArrayCollection();
$this->text_blocks_completion = new ArrayCollection();
$this->notification_text = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function __toString() {
return $this->title->getText();
}
public function getTitle(): ?AudioTextBlock
{
return $this->title;
}
public function setTitle(?AudioTextBlock $title): self
{
$this->title = $title;
return $this;
}
public function getDescription(): ?AudioTextBlock
{
return $this->description;
}
public function setDescription(?AudioTextBlock $description): self
{
$this->description = $description;
return $this;
}
public function getPreviewImageUrl(): ?string
{
return $this->preview_image_url;
}
public function setPreviewImageUrl(?string $preview_image_url): self
{
$this->preview_image_url = $preview_image_url;
return $this;
}
public function getShortDescription(): ?AudioTextBlock
{
return $this->short_description;
}
public function setShortDescription(?AudioTextBlock $short_description): self
{
$this->short_description = $short_description;
return $this;
}
public function getCompletionText(): ?string
{
return $this->completion_text;
}
public function setCompletionText(?string $completion_text): self
{
$this->completion_text = $completion_text;
return $this;
}
public function getGuideCompletionText(): ?string
{
return $this->guide_completion_text;
}
public function setGuideCompletionText(?string $guide_completion_text): self
{
$this->guide_completion_text = $guide_completion_text;
return $this;
}
public function getAudioGuideCompletionTextUrl(): ?string
{
return $this->audio_guide_completion_text_url;
}
public function setAudioGuideCompletionTextUrl(?string $audio_guide_completion_text_url): self
{
$this->audio_guide_completion_text_url = $audio_guide_completion_text_url;
return $this;
}
public function getApproximateDuration(): ?string
{
return $this->approximate_duration;
}
public function setApproximateDuration(?string $approximate_duration): self
{
$this->approximate_duration = $approximate_duration;
return $this;
}
public function getApproximateLength(): ?string
{
return $this->approximate_length;
}
public function setApproximateLength(?string $approximate_length): self
{
$this->approximate_length = $approximate_length;
return $this;
}
public function getNotificationDistance(): ?int
{
return $this->notification_distance;
}
public function setNotificationDistance(?int $notification_distance): self
{
$this->notification_distance = $notification_distance;
return $this;
}
/**
* @return Collection<int, POI>
*/
public function getPois(): Collection
{
$sortedCollection = [];
$criteria = Criteria::create()
->orderBy(['id' => Criteria::ASC]);
$poicollection = $this->pois->matching($criteria);
$sortedCollection = $poicollection->map(function (TourPoi $tourPoi) {
$poiEntity = $tourPoi->getPoi();
$poiEntity->setTemporaryOrderValue($tourPoi->getSortorder());
return $poiEntity;
});
//dd($sortedCollection);
return $sortedCollection;
}
public function addPoi(POI $poi): self
{
$tourcategoryrelation = new TourPoi;
$tourcategoryrelation->setPoi($poi);
$tourcategoryrelation->setTour($this);
if (!$this->pois->contains($tourcategoryrelation)) {
$this->pois->add($tourcategoryrelation);
}
return $this;
}
public function removePoi(POI $poi): self
{
$poiToRemove = new TourPoi;
foreach ($this->pois as $tourPoi) {
if ($tourPoi->getPoi()->getId() == $poi->getId()) {
$poiToRemove = $tourPoi;
}
}
if ($this->pois->removeElement($poiToRemove)) {
// dd($poiToRemove);
$poiToRemove->setTour(null);
$poi->removeTourPoi($poiToRemove);
}
return $this;
}
public function getTitlevalue(): ?string
{
return $this->titlevalue;
}
public function setTitlevalue(?string $titlevalue): self
{
$this->titlevalue = $titlevalue;
return $this;
}
/**
* @return Collection<int, Category>
*/
public function getCategories(): Collection
{
return $this->categories;
}
public function addCategory(Category $category): self
{
if (!$this->categories->contains($category)) {
$this->categories->add($category);
}
return $this;
}
public function removeCategory(Category $category): self
{
$this->categories->removeElement($category);
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updated_at;
}
public function setUpdatedAt(?\DateTimeInterface $updated_at): self
{
$this->updated_at = $updated_at;
return $this;
}
#[ORM\PrePersist]
#[ORM\PreUpdate]
public function updatedTimestamps()
{
$this->setUpdatedAt(new \DateTime('now'));
}
/**
* @return Collection<int, AudioTextBlock>
*/
public function getGuideTextBlocksStart(): Collection
{
return $this->guide_text_blocks_start;
}
public function addGuideTextBlocksStart(AudioTextBlock $guideTextBlocksStart): self
{
if (!$this->guide_text_blocks_start->contains($guideTextBlocksStart)) {
$this->guide_text_blocks_start->add($guideTextBlocksStart);
}
return $this;
}
public function removeGuideTextBlocksStart(AudioTextBlock $guideTextBlocksStart): self
{
$this->guide_text_blocks_start->removeElement($guideTextBlocksStart);
return $this;
}
/**
* @return Collection<int, AudioTextBlock>
*/
public function getGuideTextBlocksCompletion(): Collection
{
return $this->guide_text_blocks_completion;
}
public function addGuideTextBlocksCompletion(AudioTextBlock $guideTextBlocksCompletion): self
{
if (!$this->guide_text_blocks_completion->contains($guideTextBlocksCompletion)) {
$this->guide_text_blocks_completion->add($guideTextBlocksCompletion);
}
return $this;
}
public function removeGuideTextBlocksCompletion(AudioTextBlock $guideTextBlocksCompletion): self
{
$this->guide_text_blocks_completion->removeElement($guideTextBlocksCompletion);
return $this;
}
/**
* @return Collection<int, AudioTextBlock>
*/
#[Serializer\VirtualProperty()]
#[Serializer\SerializedName('textBlocksCompletion')]
public function getTextBlocksCompletion(): Collection
{
return $this->text_blocks_completion;
}
public function addTextBlocksCompletion(AudioTextBlock $textBlocksCompletion): self
{
if (!$this->text_blocks_completion->contains($textBlocksCompletion)) {
$this->text_blocks_completion->add($textBlocksCompletion);
}
return $this;
}
public function removeTextBlocksCompletion(AudioTextBlock $textBlocksCompletion): self
{
$this->text_blocks_completion->removeElement($textBlocksCompletion);
return $this;
}
/**
* @return Collection<int, AudioTextBlock>
*/
#[Serializer\VirtualProperty()]
#[Serializer\SerializedName('notificationText')]
public function getNotificationText(): Collection
{
return $this->notification_text;
}
public function addNotificationText(AudioTextBlock $notificationText): self
{
if (!$this->notification_text->contains($notificationText)) {
$this->notification_text->add($notificationText);
}
return $this;
}
public function removeNotificationText(AudioTextBlock $notificationText): self
{
$this->notification_text->removeElement($notificationText);
return $this;
}
public function isLive(): ?bool
{
return $this->live;
}
public function setLive(?bool $live): self
{
$this->live = $live;
return $this;
}
}