name); $fileManager = new main\mgLibs\custom\FileManager($path); $importInfo = array(); $importInfo['zoneName'] = $zone->name; $module = $zone->getModule(); if(!$module->zoneExists()) { throw new \Exception(main\mgLibs\lang::T('you_cannot_edit_this_zone_because_it_is_terminated_on_server')); } else { $importInfo['zoneRecords'] = $module->getRecords(); } return $fileManager->saveDataToFile(json_encode($importInfo, JSON_PRETTY_PRINT), $newFileName); } public static function listFilesForZone($zone, $fileManager) { $files = $fileManager->getFilesFromStorage(); foreach($files as $key => $filename) { $nameParts = explode('_', $filename); if($nameParts[0] !== $zone->name || in_array($filename, self::$skipFileList)) { unset($files[$key]); } } return $files; } public static function loadFileContent($path, $fileName) { if(!$fileName) { throw new \Exception('You have to select a file'); } $fileManager = new main\mgLibs\custom\FileManager($path); $cont = $fileManager->loadFileContent($fileName); if(!$cont) { return false; } $backupZone = json_decode($cont); return $backupZone; } public static function generateClientFileName($clientId) { return date("Y.m.d_H.i.s").'_'. $clientId; } public static function generateNewExportFileName($associateName) { return $associateName.'_'.date("Y.m.d_H.i.s"); } public static function bulkImportZoneToFile($zone, $path, $fileName = false) { $newFileName = $fileName ? $fileName : self::generateNewExportFileName($zone->name); $fileManager = new main\mgLibs\custom\FileManager($path); $importInfo = array(); $importInfo['zoneName'] = $zone->name; $module = $zone->getModule(); if(!$module->zoneExists()) { throw new \Exception(main\mgLibs\lang::T('you_cannot_edit_this_zone_because_it_is_terminated_on_server')); } else { $importInfo['zoneRecords'] = $module->getRecords(); } $content = $fileManager->loadFileContent($newFileName); $decodedContent = json_decode($content); if(!$decodedContent) { $newContent = array(); $newContent[$zone->name] = $importInfo; } else { $decodedContent->{$zone->name} = $importInfo; $newContent = $decodedContent; } return $fileManager->saveDataToFile(json_encode($newContent, JSON_PRETTY_PRINT), $newFileName, true); } public static function listFilesForBulkExport($fileManager, $serverName = false, $order = 0) { $files = $fileManager->getFilesFromStorage($order); foreach($files as $key => $filename) { $nameParts = explode('_', $filename); if($serverName && $nameParts[0] !== $serverName) { unset($files[$key]); } if($filename === '.' || $filename === '..' || in_array($filename, self::$skipFileList)) { unset($files[$key]); } } return $files; } public static function listBulkExportZones($fileName, $path) { $fileManager = new main\mgLibs\custom\FileManager($path); $content = $fileManager->loadFileContent($fileName); $decodedContent = json_decode($content); return $decodedContent; } }