<?php
 namespace App\ImportedOrder; class Itinerary_Segment extends EntityAbstract { public ?\App\ImportedOrder\Place $departurePlace = null; public ?\App\ImportedOrder\Place $arrivalPlace = null; public ?\Engine\DateTime $departureDateTime = null; public ?\Engine\DateTime $arrivalDateTime = null; public $duration; public $distance; public $distanceUnit; public $transportNumber; public $transportUnit; public $seatNumber; public $classCode; public $className; public ?\App\ImportedOrder\Supplier $supplier = null; public ?\App\ImportedOrder\Supplier $operatedBy = null; public $stopOverAllowed; public $stopCounts; public $fareBasis; public $ticketDesignator; public $mealCode; public $mealDescription; public $baggageCode; public $terminalCheckIn; public $terminalCheckOut; public $supplierRecordLocator; public $co2Emissions; public ?array $ssrRecords = null; public function addSSRRecord(Itinerary_SSRRecord $ssrRecord) { if ($this->ssrRecordExists($ssrRecord)) { throw new \Exception('There is a SSR record that was attached twice to an itinerary segment.'); } if (!$this->ssrRecords) { $this->ssrRecords = []; } $this->ssrRecords[] = $ssrRecord; } public function ssrRecordExists(Itinerary_SSRRecord $ssrRecord) :bool { if (!$this->ssrRecords) { return false; } foreach ($this->ssrRecords as $ssrRecordObj) { if ($ssrRecord === $ssrRecordObj) { return true; } } return false; } protected function validateEntityFields(\App\MessagesCollector $messagesCollector): void { $CFG = \Engine\Loader_Cfg::getInstance()->getGlobal(); if ($this->duration and !\Engine\Validator::set($this->duration)->isTime()) { $messagesCollector->addInfo('The duration is not valid.'); } if ($this->distance) { if (!is_numeric($this->distance) or $this->distance<0) { $messagesCollector->addInfo('The distance must be a positive number.'); } if (!in_array($this->distanceUnit, ['km', 'miles']) ) { $messagesCollector->addInfo('The distance unit must be `km` or `miles`.'); } } if ($this->className and !in_array($this->className, $CFG['travel']['transportSegmentClassNames'])) { $messagesCollector->addInfo('The class name is not valid.'); } if ($this->departureDateTime and !$this->departureDateTime->isValid()) { $messagesCollector->addInfo('The departure date/time is not valid.'); } if ($this->arrivalDateTime and !$this->arrivalDateTime->isValid()) { $messagesCollector->addInfo('The arrival date/time is not valid.'); } if ($this->departurePlace) { $messagesCollector->appendMessages($this->departurePlace->getValidatingMessagesCollector(), 'Departure place: %s'); } if ($this->arrivalPlace) { $messagesCollector->appendMessages($this->arrivalPlace->getValidatingMessagesCollector(), 'Arrival place: %s'); } if ($this->supplier) { $messagesCollector->appendMessages($this->supplier->getValidatingMessagesCollector(), 'Supplier: %s'); } if ($this->operatedBy) { $messagesCollector->appendMessages($this->operatedBy->getValidatingMessagesCollector(), 'OperatedBy: %s'); } if ($this->ssrRecords) { foreach ($this->ssrRecords as $idx => $ssrRecord) { $messagesCollector->appendMessages($ssrRecord->getValidatingMessagesCollector(), "SSR record #".($idx+1).": %s"); } } } } 