<?php
namespace Modules\Orders\Worldspan\Collector; class Model extends \ModulesAbstract\ImportedOrdersFileManager\Model { public function createConvertInputToFilters() { return new \Modules\Orders\Worldspan\Collector\Model\ConvertInputToFilters(); } public function getFileParsedData($fileFullPath) { $fileParser = $this->buildFileParser($fileFullPath); return [ 'extractedData' => $fileParser->getExtractedData(), 'fileId' => $fileParser->getFileId(), 'messages' => $fileParser->getMessagesCollector(), ]; } private function buildFileParser($fileFullPath) { $fileParser = new \App\Worldspan\FileParser\TAIR(); $fileParser->setMessagesCollector(new \App\MessagesCollector()); $fileParser->setRawData(\Engine\File::getContents($fileFullPath)); $fileParser->extract(); return $fileParser; } public function getStructureParserData($fileFullPath) { $processor = $this->buildStructureParser($fileFullPath); return [ 'transactions' => $processor->getSortedTransactions(), 'messages' => $processor->getMessagesCollector(), 'fileId' => $processor->getFileParser()->getFileId(), 'fileParserMessages' => $processor->getFileParser()->getMessagesCollector(), 'generalAssociations'=> $processor->getInternalAssociations(), ]; } private function buildStructureParser($fileFullPath) { $fileParser = $this->buildFileParser($fileFullPath); $processor = new \App\Worldspan\StructureParser\Processor($fileParser); $processor->initialize(); $processor->setFile($fileFullPath); return $processor; } public function parseFile($fileFullPath) { $processor = $this->buildStructureParser($fileFullPath); $storage = new \App\Worldspan\Storage\StorageHandler(); $storage->setProcessor($processor); $storage->setOption('source', "manual"); $storage->setOption('IP', $_SERVER['REMOTE_ADDR']); $ret = $storage->execute(); $entities = []; if ($ret['inserted']) { foreach ($ret['inserted'] as $entityId) { $entities[] = \Entity\WorldspanService::select($entityId); } if ($entities) { $convertor = new \App\Worldspan\CompatibilityWithImportedOrders\Processor($entities); $order = $convertor->getConvertedOrder(); $applyMode = $convertor->getConvertedApplyMode(); $orderInsert = \Entity\ImportedOrder::insert(); $orderInsert->applyMode = $applyMode; $orderInsert->order = $order; $orderInsert->originalFilesWithPath = [$this->getFilePathRelativeToFilesRoot($fileFullPath)]; $orderInsert->save(); $insertedOrderId = $orderInsert->getId(); $affectedFiles = []; foreach($entities as $ent) { $affectedFiles[$ent->idFile] = $ent->file; } foreach($affectedFiles as $file) { $fileUpd = \Entity\WorldspanFile::update($file->getId()); $idImportedOrders = $file->idImportedOrders; $idImportedOrders[] = $insertedOrderId; $fileUpd->idImportedOrders = $idImportedOrders; $fileUpd->save(); } } $processor->getFileParser()->destroyCCInformationAndWriteInto($fileFullPath); } } }