<?php
 namespace App\ImportedOrder; class Itinerary extends EntityAbstract { public ?array $segments = null; public function addSegment(Itinerary_Segment $segment) { if (!$this->segments) { $this->segments = []; } $this->segments[] = $segment; } protected function validateEntityFields(\App\MessagesCollector $messagesCollector): void { $cnt=0; if ($this->segments) { foreach ($this->segments as $segm) { $cnt++; $messagesCollector->appendMessages($segm->getValidatingMessagesCollector(), "Segment #{$cnt}: %s"); } } } public function getMatchedItinerary($idExternalSystem) { if (!$this->segments) { return null; } $tinaItinerary = new \App\Itinerary(); foreach($this->segments as $importedSegment) { $tinaSegment = new \App\ItinerarySegment(); if ($importedSegment->departurePlace and $importedSegment->departurePlace->station) { $stationObj = $importedSegment->departurePlace->station; $matchedStationCode = $stationObj->getMatchedId($idExternalSystem); if ($matchedStationCode) { $tinaSegment->setDeparturePlace(\Entity\Station::select($matchedStationCode)->city->countryCode, \Entity\Station::select($matchedStationCode)->cityId, $matchedStationCode); } else { if ($stationObj->city) { $cityObj = $stationObj->city; $matchedCityId = $cityObj->getMatchedId($idExternalSystem); if ($matchedCityId) { $tinaSegment->setDeparturePlace(\Entity\Station::select($matchedCityId)->countryCode, $matchedCityId, ''); } else { if ($cityObj->country) { $matchedCountryCode = $cityObj->country->getMatchedId($idExternalSystem); if ($matchedCountryCode) { $tinaSegment->setDeparturePlace($matchedCountryCode, '', ''); } } } } } } if ($importedSegment->arrivalPlace and $importedSegment->arrivalPlace->station) { $stationObj = $importedSegment->arrivalPlace->station; $matchedStationCode = $stationObj->getMatchedId($idExternalSystem); if ($matchedStationCode) { $tinaSegment->setArrivalPlace(\Entity\Station::select($matchedStationCode)->city->countryCode, \Entity\Station::select($matchedStationCode)->cityId, $matchedStationCode); } else { if ($stationObj->city) { $cityObj = $stationObj->city; $matchedCityId = $cityObj->getMatchedId($idExternalSystem); if ($matchedCityId) { $tinaSegment->setArrivalPlace(\Entity\Station::select($matchedCityId)->countryCode, $matchedCityId, ''); } else { if ($cityObj->country) { $matchedCountryCode = $cityObj->country->getMatchedId($idExternalSystem); if ($matchedCountryCode) { $tinaSegment->setArrivalPlace($matchedCountryCode, '', ''); } } } } } } if ($importedSegment->departureDateTime) { $tinaSegment->setDepartureDateTime($importedSegment->departureDateTime); } if ($importedSegment->arrivalDateTime) { $tinaSegment->setArrivalDateTime($importedSegment->arrivalDateTime); } if ($importedSegment->classCode!==null or $importedSegment->className!==null) { $tinaSegment->setServiceClass((String)$importedSegment->classCode, (String)$importedSegment->className); } if ($importedSegment->distance!==null) { $tinaSegment->setDistance($importedSegment->distance, $importedSegment->distanceUnit); } if ($importedSegment->duration!==null) { $tinaSegment->setDuration($importedSegment->duration); } if ($importedSegment->transportNumber!==null) { $tinaSegment->setTransportNumber($importedSegment->transportNumber); } if ($importedSegment->transportUnit!==null) { $tinaSegment->setTransportUnit($importedSegment->transportUnit); } if ($importedSegment->seatNumber!==null) { $tinaSegment->setSeatNumber($importedSegment->seatNumber); } if ($importedSegment->supplier) { $idMatchedSupplier = $importedSegment->supplier->getMatchedId($idExternalSystem); if ($idMatchedSupplier) { $tinaSegment->setIdSupplier($idMatchedSupplier); } } if ($importedSegment->fareBasis!==null) { $tinaSegment->setFareBasis($importedSegment->fareBasis); } if ($importedSegment->stopOverAllowed!==null) { $tinaSegment->setStopOverAllowed($importedSegment->stopOverAllowed); } if ($importedSegment->baggageCode!==null) { $tinaSegment->setBaggageCode($importedSegment->baggageCode); } if ($importedSegment->mealCode!==null) { $tinaSegment->setMealCode($importedSegment->mealCode); } if ($importedSegment->mealDescription!==null) { $tinaSegment->setMealDescription($importedSegment->mealDescription); } if ($importedSegment->terminalCheckIn!==null) { $tinaSegment->setTerminalCheckIn($importedSegment->terminalCheckIn); } if ($importedSegment->terminalCheckOut!==null) { $tinaSegment->setTerminalCheckOut($importedSegment->terminalCheckOut); } $tinaItinerary->addSegment($tinaSegment); } return $tinaItinerary; } } 