src/Entity/Tour.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\TourRepository;
  4. use DateTime;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\Common\Collections\Criteria;
  8. use Doctrine\DBAL\Types\Type;
  9. use Doctrine\DBAL\Types\Types;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use JMS\Serializer\Annotation as Serializer;
  12. use JMS\Serializer\Annotation\MaxDepth;
  13. #[ORM\Entity(repositoryClassTourRepository::class)]
  14. #[ORM\HasLifecycleCallbacks]
  15. class Tour
  16. {
  17.     #[ORM\Id]
  18.     #[ORM\GeneratedValue]
  19.     #[ORM\Column]
  20.     #[Serializer\Groups(["tour","poi","category"])]
  21.     private ?int $id null;
  22.     #[ORM\OneToOne(cascade: ['persist''remove'])]
  23.     #[MaxDepth(1)]
  24.     #[Serializer\Groups(["tour"])]
  25.     private ?AudioTextBlock $title null;
  26.     #[ORM\OneToOne(cascade: ['persist''remove'])]
  27.     #[MaxDepth(1)]
  28.     #[Serializer\Groups(["tour"])]
  29.     private ?AudioTextBlock $description null;
  30.     #[ORM\OneToOne(cascade: ['persist''remove'])]
  31.     #[MaxDepth(1)]
  32.     #[Serializer\Groups(["tour"])]
  33.     #[Serializer\SerializedName("shortDescription")]
  34.     private ?AudioTextBlock $short_description null;
  35.     #[ORM\Column(length255nullabletrue)]
  36.     #[Serializer\Groups(["tour"])]
  37.     #[Serializer\SerializedName("previewImageUrl")]
  38.     private ?string $preview_image_url null;
  39.     #[ORM\Column(length2048nullabletrue)]
  40.     #[Serializer\Groups(["tour"])]
  41.     #[Serializer\SerializedName("completionText")]
  42.     private ?string $completion_text null;
  43.     #[ORM\Column(length2048nullabletrue)]
  44.     #[Serializer\Groups(["tour"])]
  45.     #[Serializer\SerializedName("guideCompletionText")]
  46.     private ?string $guide_completion_text null;
  47.     #[ORM\Column(length255nullabletrue)]
  48.     #[Serializer\Groups(["tour"])]
  49.     #[Serializer\SerializedName("audioGuideCompletionTextUrl")]
  50.     private ?string $audio_guide_completion_text_url null;
  51.     #[ORM\Column(length255nullabletrue)]
  52.     #[Serializer\Groups(["tour"])]
  53.     #[Serializer\SerializedName("approximateDuration")]
  54.     private ?string $approximate_duration null;
  55.     #[ORM\Column(length255nullabletrue)]
  56.     #[Serializer\Groups(["tour"])]
  57.     #[Serializer\SerializedName("approximateLength")]
  58.     private ?string $approximate_length null;
  59.     #[ORM\Column(nullabletrue)]
  60.     #[Serializer\Groups(["tour"])]
  61.     #[Serializer\SerializedName("notificationDistance")]
  62.     private ?int $notification_distance null;
  63.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  64.     #[Serializer\Groups(["tour"])]
  65.     #[Serializer\SerializedName("updatedAt")]
  66.     private ?DateTime $updated_at null;
  67.     #[ORM\OneToMany(mappedBy'tour'targetEntityTourPoi::class, cascade: ["persist","remove"], orphanRemovaltrue)]
  68.     #[MaxDepth(2)]
  69.     private Collection $pois;
  70.     #[ORM\Column(length255nullabletrue)]
  71.     #[Serializer\Groups(["tour"])]
  72.     private ?string $titlevalue null;
  73.     #[ORM\ManyToMany(targetEntityCategory::class, mappedBy'tours')]
  74.     #[MaxDepth(1)]
  75.     private Collection $categories;
  76.     #[ORM\ManyToMany(targetEntityAudioTextBlock::class,cascade: ['persist''remove'])]
  77.     #[ORM\JoinTable(name:"tourtextblockguidestart")]
  78.     #[MaxDepth(1)]
  79.     #[Serializer\Groups(["tour"])]
  80.     #[Serializer\SerializedName("guideTextBlocksStart")]
  81.     private Collection $guide_text_blocks_start;
  82.     #[ORM\ManyToMany(targetEntityAudioTextBlock::class,cascade: ['persist''remove'])]
  83.     #[ORM\JoinTable(name:"tourtextblockguidecompletion")]
  84.     #[MaxDepth(1)]
  85.     #[Serializer\Groups(["tour"])]
  86.     #[Serializer\SerializedName("guideTextBlocksCompletion")]
  87.     private Collection $guide_text_blocks_completion;
  88.     #[ORM\ManyToMany(targetEntityAudioTextBlock::class,cascade: ['persist''remove'])]
  89.     #[ORM\JoinTable(name:"tourtextblockcompletion")]
  90.     #[MaxDepth(1)]
  91.     #[Serializer\Groups(["tour"])]
  92.     #[Serializer\SerializedName("textBlocksCompletion")]
  93.     private Collection $text_blocks_completion;
  94.     #[ORM\ManyToMany(targetEntityAudioTextBlock::class,cascade: ['persist''remove'])]
  95.     #[ORM\JoinTable(name:"tourtextblocknotification")]
  96.     #[MaxDepth(1)]
  97.     #[Serializer\Groups(["tour"])]
  98.     #[Serializer\SerializedName("notificationText")]
  99.     private Collection $notification_text;
  100.     #[ORM\Column(nullabletrue)]
  101.     #[Serializer\Groups(["tour"])]
  102.     private ?bool $live null;
  103.     #[Serializer\Groups(["tour"])]
  104.     #[Serializer\VirtualProperty()]
  105.     #[Serializer\SerializedName("pois")]
  106.     public function getPoiIDs(){
  107.         $pois $this->getPois();
  108.         $poiIds = [];
  109.         foreach ($pois as $poi) {
  110.            $poiIds[]=$poi->getId();
  111.         }
  112.         return $poiIds ;
  113.     }
  114.     #[Serializer\Groups(["tour"])]
  115.     #[Serializer\VirtualProperty()]
  116.     #[Serializer\SerializedName("categories")]
  117.     public function getCategoryIDs(){
  118.         $categories $this->getCategories();
  119.         $categoryIds = [];
  120.         foreach ($categories as $category) {
  121.             $categoryIds[]=$category->getId();
  122.         }
  123.         return $categoryIds ;
  124.     }
  125.     public function __construct()
  126.     {
  127.         $this->pois = new ArrayCollection();
  128.         $this->categories = new ArrayCollection();
  129.         $this->guide_text_blocks_start = new ArrayCollection();
  130.         $this->guide_text_blocks_completion = new ArrayCollection();
  131.         $this->text_blocks_completion = new ArrayCollection();
  132.         $this->notification_text = new ArrayCollection();
  133.     }
  134.     public function getId(): ?int
  135.     {
  136.         return $this->id;
  137.     }
  138.     public function __toString() {
  139.         return $this->title->getText();
  140.     }
  141.   
  142.     public function getTitle(): ?AudioTextBlock
  143.     {
  144.         return $this->title;
  145.        
  146.     }
  147.     public function setTitle(?AudioTextBlock $title): self
  148.     {
  149.         $this->title $title;
  150.     
  151.         return $this;
  152.     }
  153.     public function getDescription(): ?AudioTextBlock
  154.     {
  155.         return $this->description;
  156.     }
  157.     public function setDescription(?AudioTextBlock $description): self
  158.     {
  159.         $this->description $description;
  160.         return $this;
  161.     }
  162.  
  163.     public function getPreviewImageUrl(): ?string
  164.     {
  165.         return $this->preview_image_url;
  166.     }
  167.     public function setPreviewImageUrl(?string $preview_image_url): self
  168.     {
  169.         $this->preview_image_url $preview_image_url;
  170.         return $this;
  171.     }
  172.     public function getShortDescription(): ?AudioTextBlock
  173.     {
  174.         return $this->short_description;
  175.     }
  176.     
  177.     public function setShortDescription(?AudioTextBlock $short_description): self
  178.     {
  179.         $this->short_description $short_description;
  180.     
  181.         return $this;
  182.     }
  183.     public function getCompletionText(): ?string
  184.     {
  185.         return $this->completion_text;
  186.     }
  187.     public function setCompletionText(?string $completion_text): self
  188.     {
  189.         $this->completion_text $completion_text;
  190.         return $this;
  191.     }
  192.     public function getGuideCompletionText(): ?string
  193.     {
  194.         return $this->guide_completion_text;
  195.     }
  196.     public function setGuideCompletionText(?string $guide_completion_text): self
  197.     {
  198.         $this->guide_completion_text $guide_completion_text;
  199.         return $this;
  200.     }
  201.     public function getAudioGuideCompletionTextUrl(): ?string
  202.     {
  203.         return $this->audio_guide_completion_text_url;
  204.     }
  205.     public function setAudioGuideCompletionTextUrl(?string $audio_guide_completion_text_url): self
  206.     {
  207.         $this->audio_guide_completion_text_url $audio_guide_completion_text_url;
  208.         return $this;
  209.     }
  210.     public function getApproximateDuration(): ?string
  211.     {
  212.         return $this->approximate_duration;
  213.     }
  214.     public function setApproximateDuration(?string $approximate_duration): self
  215.     {
  216.         $this->approximate_duration $approximate_duration;
  217.         return $this;
  218.     }
  219.     public function getApproximateLength(): ?string
  220.     {
  221.         return $this->approximate_length;
  222.     }
  223.     public function setApproximateLength(?string $approximate_length): self
  224.     {
  225.         $this->approximate_length $approximate_length;
  226.         return $this;
  227.     }
  228.     public function getNotificationDistance(): ?int
  229.     {
  230.         return $this->notification_distance;
  231.     }
  232.     public function setNotificationDistance(?int $notification_distance): self
  233.     {
  234.         $this->notification_distance $notification_distance;
  235.         return $this;
  236.     }
  237.     /**
  238.      * @return Collection<int, POI>
  239.      */
  240.     public function getPois(): Collection
  241.     {       
  242.         $sortedCollection = [];
  243.         $criteria Criteria::create()
  244.             ->orderBy(['id' => Criteria::ASC]);  
  245.         $poicollection $this->pois->matching($criteria);
  246.         $sortedCollection =  $poicollection->map(function (TourPoi $tourPoi) {
  247.             $poiEntity $tourPoi->getPoi();
  248.             $poiEntity->setTemporaryOrderValue($tourPoi->getSortorder());
  249.  
  250.             return $poiEntity;
  251.         });
  252.        //dd($sortedCollection);
  253.         return $sortedCollection;
  254.     }
  255.     public function addPoi(POI $poi): self
  256.     {
  257.         $tourcategoryrelation = new TourPoi;
  258.         $tourcategoryrelation->setPoi($poi);
  259.         $tourcategoryrelation->setTour($this);
  260.         
  261.         if (!$this->pois->contains($tourcategoryrelation)) {
  262.             $this->pois->add($tourcategoryrelation);
  263.         }
  264.         return $this;
  265.     }
  266.     public function removePoi(POI $poi): self
  267.     {
  268.         $poiToRemove = new TourPoi;
  269.         foreach ($this->pois as $tourPoi) {
  270.             if ($tourPoi->getPoi()->getId() == $poi->getId()) {
  271.                 $poiToRemove $tourPoi;
  272.             }
  273.         }
  274.         if ($this->pois->removeElement($poiToRemove)) {
  275.             //  dd($poiToRemove);
  276.             $poiToRemove->setTour(null);
  277.             $poi->removeTourPoi($poiToRemove);
  278.         }
  279.         return $this;
  280.     }
  281.     public function getTitlevalue(): ?string
  282.     {
  283.         return $this->titlevalue;
  284.     }
  285.     public function setTitlevalue(?string $titlevalue): self
  286.     {
  287.         $this->titlevalue $titlevalue;
  288.         return $this;
  289.     }
  290.     /**
  291.      * @return Collection<int, Category>
  292.      */
  293.     public function getCategories(): Collection
  294.     {
  295.         return $this->categories;
  296.     }
  297.     public function addCategory(Category $category): self
  298.     {
  299.         if (!$this->categories->contains($category)) {
  300.             $this->categories->add($category);
  301.         }
  302.         return $this;
  303.     }
  304.     public function removeCategory(Category $category): self
  305.     {
  306.         $this->categories->removeElement($category);
  307.         return $this;
  308.     }
  309.     public function getUpdatedAt(): ?\DateTimeInterface
  310.     {
  311.         return $this->updated_at;
  312.     }
  313.     
  314.     public function setUpdatedAt(?\DateTimeInterface $updated_at): self
  315.     {
  316.         $this->updated_at $updated_at;
  317.     
  318.         return $this;
  319.     }
  320.     
  321.     #[ORM\PrePersist]
  322.     #[ORM\PreUpdate]
  323.     public function updatedTimestamps()
  324.     {
  325.         $this->setUpdatedAt(new \DateTime('now'));
  326.     
  327.     }
  328.     /**
  329.      * @return Collection<int, AudioTextBlock>
  330.      */
  331.     public function getGuideTextBlocksStart(): Collection
  332.     {
  333.         return $this->guide_text_blocks_start;
  334.     }
  335.     public function addGuideTextBlocksStart(AudioTextBlock $guideTextBlocksStart): self
  336.     {
  337.         if (!$this->guide_text_blocks_start->contains($guideTextBlocksStart)) {
  338.             $this->guide_text_blocks_start->add($guideTextBlocksStart);
  339.         }
  340.         return $this;
  341.     }
  342.     public function removeGuideTextBlocksStart(AudioTextBlock $guideTextBlocksStart): self
  343.     {
  344.         $this->guide_text_blocks_start->removeElement($guideTextBlocksStart);
  345.         return $this;
  346.     }
  347.     /**
  348.      * @return Collection<int, AudioTextBlock>
  349.      */
  350.     public function getGuideTextBlocksCompletion(): Collection
  351.     {
  352.         return $this->guide_text_blocks_completion;
  353.     }
  354.     public function addGuideTextBlocksCompletion(AudioTextBlock $guideTextBlocksCompletion): self
  355.     {
  356.         if (!$this->guide_text_blocks_completion->contains($guideTextBlocksCompletion)) {
  357.             $this->guide_text_blocks_completion->add($guideTextBlocksCompletion);
  358.         }
  359.         return $this;
  360.     }
  361.     public function removeGuideTextBlocksCompletion(AudioTextBlock $guideTextBlocksCompletion): self
  362.     {
  363.         $this->guide_text_blocks_completion->removeElement($guideTextBlocksCompletion);
  364.         return $this;
  365.     }
  366.     /**
  367.      * @return Collection<int, AudioTextBlock>
  368.      */
  369.     #[Serializer\VirtualProperty()]
  370.     #[Serializer\SerializedName('textBlocksCompletion')]
  371.     public function getTextBlocksCompletion(): Collection
  372.     {
  373.         return $this->text_blocks_completion;
  374.     }
  375.     public function addTextBlocksCompletion(AudioTextBlock $textBlocksCompletion): self
  376.     {
  377.         if (!$this->text_blocks_completion->contains($textBlocksCompletion)) {
  378.             $this->text_blocks_completion->add($textBlocksCompletion);
  379.         }
  380.         return $this;
  381.     }
  382.     public function removeTextBlocksCompletion(AudioTextBlock $textBlocksCompletion): self
  383.     {
  384.         $this->text_blocks_completion->removeElement($textBlocksCompletion);
  385.         return $this;
  386.     }
  387.     /**
  388.      * @return Collection<int, AudioTextBlock>
  389.      */
  390.     #[Serializer\VirtualProperty()]
  391.     #[Serializer\SerializedName('notificationText')]
  392.     public function getNotificationText(): Collection
  393.     {
  394.         return $this->notification_text;
  395.     }
  396.     public function addNotificationText(AudioTextBlock $notificationText): self
  397.     {
  398.         if (!$this->notification_text->contains($notificationText)) {
  399.             $this->notification_text->add($notificationText);
  400.         }
  401.         return $this;
  402.     }
  403.     public function removeNotificationText(AudioTextBlock $notificationText): self
  404.     {
  405.         $this->notification_text->removeElement($notificationText);
  406.         return $this;
  407.     }
  408.     public function isLive(): ?bool
  409.     {
  410.         return $this->live;
  411.     }
  412.     public function setLive(?bool $live): self
  413.     {
  414.         $this->live $live;
  415.         return $this;
  416.     }
  417. }