<?php
namespace Modules\Orders\Apollo\Collector; class Model extends \ModulesAbstract\ImportedOrdersFileManager\Model { public function createConvertInputToFilters() { return new \Modules\Orders\Apollo\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\Apollo\FileParser\MIR(); $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(), 'generalAssociations'=> $processor->getInternalAssociations(), ]; } private function buildStructureParser($fileFullPath) { $fileParser = $this->buildFileParser($fileFullPath); $processor = new \App\Apollo\StructureParser\Processor($fileParser); $processor->initialize(); $processor->setFile($fileFullPath); return $processor; } public function parseFile($fileFullPath) { $processor = $this->buildStructureParser($fileFullPath); $storage = new \App\Apollo\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\ApolloService::select($entityId); } if ($entities) { $convertor = new \App\Apollo\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\ApolloFile::update($file->getId()); $idImportedOrders = $file->idImportedOrders; $idImportedOrders[] = $insertedOrderId; $fileUpd->idImportedOrders = $idImportedOrders; $fileUpd->save(); } } $processor->getFileParser()->destroyCCInformationAndWriteInto($fileFullPath); } } }