<?php
namespace App\Amadeus\StructureParser\Structures\Ticketing; class ServiceDetails extends \App\Amadeus\StructureParser\Parser\ServiceDetails { public function getDetails() { if($this->CACHE[__METHOD__]) return $this->CACHE[__METHOD__]; $indexType = $this->transaction->getIndexType(); if ($indexType=='H') { $details = $this->getDetails_H(); if ($details) { $this->CACHE[__METHOD__] = $details; return $details; } } if ($indexType=='H:reissue') { $details = $this->getDetails_H_reissue(); if ($details) { $this->CACHE[__METHOD__] = $details; return $details; } } if ($indexType=='U:ticketing') { $details = $this->getDetails_U(); if ($details) { $this->CACHE[__METHOD__] = $details; return $details; } } return null; } public function getRelations() { if($this->CACHE[__METHOD__]) return $this->CACHE[__METHOD__]; $indexType = $this->transaction->getIndexType(); if ($indexType=='H') { $details = $this->getRelations_H(); if ($details) { $this->CACHE[__METHOD__] = $details; return $details; } } if ($indexType=='H:reissue') { $details = $this->getRelations_H_reissue(); if ($details) { $this->CACHE[__METHOD__] = $details; return $details; } } if ($indexType=='U:ticketing') { $details = $this->getRelations_U(); if ($details) { $this->CACHE[__METHOD__] = $details; return $details; } } return null; } protected function getDetails_H() { $parsedStructure = $this->transaction->getParsedStructure(); $index = $this->transaction->getIndex(); $item = new \App\Amadeus\StructureParser\Types\ServiceDetails(); $this->extractTourCode($parsedStructure, $index, $item); $item = $this->extractCommonServiceDetails($parsedStructure, $item); return $item; } protected function getRelations_H() { return parent::getRelations(); } protected function getDetails_H_reissue() { $parsedStructure = $this->transaction->getParsedStructure(); $index = $this->transaction->getIndex(); $item = new \App\Amadeus\StructureParser\Types\ServiceDetails(); $this->extractTourCode($parsedStructure, $index, $item); $item = $this->extractCommonServiceDetails($parsedStructure, $item); return $item; } protected function getRelations_H_reissue() { $parsedStructure = $this->transaction->getParsedStructure(); $index = $this->transaction->getIndex(); $I = $parsedStructure['I'][$index->passenger]; $relations = new \App\Amadeus\StructureParser\Types\Relations(); if ($I['FO']) { $previousTickets = $I['FO'][0]['previousTickets']; $previousTicketNumbersWithCnj = []; foreach ($previousTickets as $pt) { if (count($pt['tktNoArr'])>1) { $previousTicketNumbersWithCnj[$pt['tktNo']]++; } } $prevTkt = reset(array_reverse(array_slice(array_filter($previousTickets, function ($pt) use ($previousTicketNumbersWithCnj) { if ($previousTicketNumbersWithCnj[$pt['tktNo']] && count($pt['tktNoArr'])==1) { return false; } return !$pt['involuntary_reissue']; }), 0, 2))); foreach ($prevTkt['tktNoArr'] as $tktNo) { $r = new \App\Amadeus\StructureParser\Types\Relation(); $r->docNumber = $tktNo; $r->relationType = 'reissueOf'; $relations->relations[] = $r; } } return $relations; } protected function getDetails_U() { $parsedStructure = $this->transaction->getParsedStructure(); $item = new \App\Amadeus\StructureParser\Types\ServiceDetails(); $item = $this->extractCommonServiceDetails($parsedStructure, $item); return $item; } protected function getRelations_U() { $parsedStructure = $this->transaction->getParsedStructure(); $index = $this->transaction->getIndex(); $I = $parsedStructure['I'][$index->passenger]; $relations = new \App\Amadeus\StructureParser\Types\Relations(); $relations = $this->extractReferencesData($parsedStructure, $index, $relations); if ($I['FH']) { foreach ($I['FH'] as $FH) { if ($FH['HANDTKT_']['tktNo']) { $r = new \App\Amadeus\StructureParser\Types\Relation(); $r->docNumber = $FH['HANDTKT_']['tktNo']; $r->relationType = 'reference'; $relations->relations[] = $r; } } } return $relations; } } 