Skip to content

Instantly share code, notes, and snippets.

@artemrogov
Created November 26, 2019 15:00
Show Gist options
  • Save artemrogov/ab6a095e6c3a6e35da2f5c533dd0ac01 to your computer and use it in GitHub Desktop.
Save artemrogov/ab6a095e6c3a6e35da2f5c533dd0ac01 to your computer and use it in GitHub Desktop.
Преобразование
/**
Преобразование для DataTablesJs
для карты меню ГИСП ЛК
**/
class XMLMenuController extends Controller
{
public function uploadXMLMenu(Request $request)
{
if ($request->hasFile('xml_upload')){
$fileXML = $request->file('xml_upload');
$file = $this->uploadCreateFileXML($fileXML);
//dd($file); // получили xml файл
$test = $this->createSimpleArrayXML($file);
return redirect()->back()->with('status','Import XML Menu');
}
}
private function uploadCreateFileXML($fileXML)
{
try {
$filePath = "/public/export/";
$file_name = 'menu_map_upload'.Carbon::now().'.xml';
Storage::putFileAs($filePath,$fileXML,$file_name);
$file = Storage::get($filePath.$file_name);
return $file;
}catch (IOException $exception){
return $exception->getMessage();
}
}
/**
* Преобразовать XML карту меню в многомерный вложенный массив
* @param $xml
* @return array
*/
private function toArrayMap($xml) : array
{
$data = simplexml_load_string($xml, "SimpleXMLElement", LIBXML_NOCDATA);
$json = json_encode($data);
$menuTableDataArray = json_decode($json,TRUE);
return $menuTableDataArray;
}
private function createSimpleArrayXML($stringXML) {
$arrayInput = $this->toArrayMap($stringXML);
dd($this->convertFlatArray($arrayInput));
}
private function convertFlatArray(array $arrayData){
//todo посотреть как будет идти преобразование
$array = Arr::collapse($arrayData);
return $array;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment