<?php
namespace App\Amadeus\StructureParser\Structures\EMD; class Itinerary extends \App\Amadeus\StructureParser\Structures\MCO\Itinerary { public function isValid() { $parsedStructure = $this->transaction->getParsedStructure(); $indexType = $this->transaction->getIndexType(); $index = $this->transaction->getIndex(); $U = $parsedStructure['U'][$index->segment??null]; if($indexType=='EMD'){ if(isset($parsedStructure['EMD'])) { return true; } } if($indexType=='U' && $U['_type']=='19'){ if(isset($parsedStructure['U'][$index->segment??null])) { return true; } } return false; } protected function updateInternalSegmentData() { $indexType = $this->transaction->getIndexType(); if($indexType=='EMD'){ $ret = $this->updateInternalSegmentData_EMD(); if($ret){ return $ret; } } return false; } protected function updateInternalSegmentData_EMD() { $parsedStructure = $this->transaction->getParsedStructure(); $index = $this->transaction->getIndex(); foreach ($index->EMD as $EMDIndex) { $EMDt = $parsedStructure['EMD'][$EMDIndex]; $I = \App\Amadeus\StructureParser\Helpers::internal_MCO_MCO_to_I($parsedStructure, $EMDt, $this->transaction); foreach ($parsedStructure['EMD'] as $idx=>$EMD) { $add = false; if ($EMD && $idx==$EMDIndex) { $add = true; } if ($add && $EMD['PSGASS']) { $add = false; foreach ($EMD['PSGASS'] as $PSGASS) { if ($PSGASS==(int)$I['PSGRNBR']) { $add = true; break; } } } if ($add) { $item = new \App\Amadeus\StructureParser\Types\ItinerarySegment(); $item->departure->suggest('airport', $EMD['ORIGIN']); $item->departure->suggest('airport', $EMD['DESTIN']); $match = $item->match([ 'airportCode' => [$EMD['ORIGIN']], ]); $item->departure->airportCode = $match->airport??null; $item->departure->cityId = $match->city??null; $item->departure->countryCode = $match->country??null; $match = $item->match([ 'airportCode' => [$EMD['DESTIN']], ]); $item->destination->airportCode = $match->airport??null; $item->destination->cityId = $match->city??null; $item->destination->countryCode = $match->country??null; $item->departure->date = $EMD['PRCNDATE']; $item->destination->date = $EMD['PRCNDATE']; if ($EMD['NVADATE']) { $item->departure->date = $EMD['NVADATE']; $item->destination->date = $EMD['NVADATE']; } $item->supplierCode = rtrim($EMD['AIRCDE']); $item->segmentType = $EMD['_type']; $this->itinerary->appendSegment($item); } } } return true; } protected function updateInternalSegmentData_U() { $parsedStructure = $this->transaction->getParsedStructure(); $index = $this->transaction->getIndex(); $item = null; $U = $parsedStructure['U'][$index->segment]; $itinerary = []; foreach($parsedStructure['U'] as $segIdx=>$EMD){ if($EMD['_type']=='19' && in_array($segIdx, $parsedStructure['assoc:U:pax-segment'][$index->passenger])){ $item = new \App\Amadeus\StructureParser\Types\ItinerarySegment(); $item->departure->suggest('airport', $EMD['ORIGIN']); $item->departure->suggest('airport', $EMD['DESTIN']); $match = $item->match([ 'airportCode' => [$EMD['ORIGIN']], ]); $item->departure->airportCode = $match->airport; $item->departure->cityId = $match->city; $item->departure->countryCode = $match->country; $match = $item->match([ 'airportCode' => [$EMD['DESTIN']], ]); $item->destination->airportCode = $match->airport; $item->destination->cityId = $match->city; $item->destination->countryCode = $match->country; $item->departure->date = $EMD['PRCNDATE']; $item->destination->date = $EMD['PRCNDATE']; $item->supplierCode = rtrim($U['AIRCDE']); $item->segmentType = $U['_type']; $this->itinerary->appendSegment($item); } } return true; } } 