testExporter = $testExporter; $this->fileSystemService = $fileSystemService; $this->fileHelperService = $fileHelperService; } /** * @param string $testUri * * @return common_report_Report * @throws common_Exception * @throws common_exception_Error */ public function exportDeliveryQtiPackage(string $testUri): common_report_Report { $exportReport = $this->testExporter->export( [ 'filename' => self::QTI_PACKAGE_FILENAME, 'instances' => $testUri, 'uri' => $testUri ], $this->fileHelperService->createTempDir() ); if ($exportReport->getType() === common_report_Report::TYPE_ERROR) { throw new common_Exception('QTI Test package export failed.'); } $reportData = $exportReport->getData(); if (!isset($reportData['path']) || !is_string($reportData['path'])) { throw new common_Exception('Export report does not contain path to exported QTI package: ' . json_encode($reportData)); } return $exportReport; } /** * @param string $testUri * @param string $fileSystemId * @param string $filePath * @return File * @throws common_Exception */ public function exportQtiTestPackageToFile(string $testUri, string $fileSystemId, string $filePath): File { $result = $this->exportDeliveryQtiPackage($testUri)->getData(); return $this->moveFileToSharedFileSystem($result['path'], $fileSystemId, $filePath); } /** * @param string $sourceFilePath * @param string $fileSystemId * @param string $destinationFilePath * @return File * @throws common_Exception */ private function moveFileToSharedFileSystem(string $sourceFilePath, string $fileSystemId, string $destinationFilePath): File { $source = $this->fileHelperService->readFile($sourceFilePath); $file = $this->fileSystemService ->getDirectory($fileSystemId) ->getFile($destinationFilePath); $file->put($source); $this->fileHelperService->closeFile($source); $this->fileHelperService->removeFile($sourceFilePath); return $file; } }