public function actionIndentJson() { return Rest::json(array('jsonindent' => FileHelper::indent_json($_POST['jsonnonindent']))); }
public static function createMappingWithJSON($post) { $json_array = json_decode($post['json_origine'], true); $jsonMapping["src"] = $post['source']; //json mapping if ($post['chooseSelected'] == "new") { $jsonMapping["date_create"] = date("d/m/y"); } else { $oneMapping = PHDB::findOne(City::COLLECTION_IMPORTHISTORY, array("_id" => new MongoId($post['mappingSelected']))); $jsonMapping["date_create"] = $oneMapping["date_create"]; // $jsonmapping["lastImportId"] = $oneMapping['lastImportId']; } $jsonMapping["date_update"] = date("d/m/y"); $jsonMapping["url"] = $post['url']; $jsonMapping["nameFile"] = $post['nameFile']; $jsonMapping["lien"] = $post['lien']; foreach ($post['tabmapping'] as $key => $value) { if ($value != '') { $jsonfilsFields[$post['tabidmapping'][$key]] = $value; } } $jsonMapping["fields"] = $jsonfilsFields; $idLien = $post['lien']; $cheminLien = explode(".", $idLien); //var_dump($cheminLien); $valueIdLien = FileHelper::get_value_json($json_array, $cheminLien); //var_dump($valueIdLien); $res = PHDB::findOne(City::COLLECTION, array("insee" => $valueIdLien)); $inc_import = 0; $inc_rejet = 0; if ($res != null) { $commune["insee"] = $valueIdLien; foreach ($jsonMapping['fields'] as $key => $value) { $map = explode(".", $value); $cheminJson = explode(".", $key); $value_json = FileHelper::get_value_json($json_array, $cheminJson); if (!isset($commune[$map[0]])) { if (count($map) > 1) { $newmap = array_splice($map, 1); $commune[$map[0]] = FileHelper::create_json($newmap, $value_json); } else { $commune[$map[0]] = $value_json; } } else { if (count($map) > 1) { $newmap = array_splice($map, 1); $commune[$map[0]] = FileHelper::create_json_with_father($newmap, $value_json, $commune[$map[0]]); } else { $commune[$map[0]] = $value_json; } } } } else { foreach ($jsonMapping['fields'] as $key => $value) { $map = explode(".", $value); $cheminJson = explode(".", $key); if (!isset($rejet[$valueIdLien])) { if (count($map) > 1) { $newmap = array_splice($map, 1); $rejet[$map[0]] = FileHelper::create_json_with_father($newmap, $value_json); } else { $rejet[$map[0]] = $value_json; } } else { if (count($map) > 1) { $newmap = array_splice($map, 1); $rejet[$map[0]] = FileHelper::create_json_with_father($newmap, $value_json, $rejet[$map[0]]); } else { $rejet[$map[0]] = $value_json; } } } } if (isset($commune)) { $jsonimport = $commune; } else { $jsonimport = []; $arrayCsvImport = []; } if (isset($rejet)) { $jsonrejet = $rejet; } else { $jsonrejet = []; $arrayCsvRejet = []; } $params = array('result' => true, 'jsonmapping' => FileHelper::indent_json(json_encode($jsonMapping)), "jsonimport" => FileHelper::indent_json(json_encode($jsonimport)), "jsonrejet" => FileHelper::indent_json(json_encode($jsonrejet)), "lien" => $post['lien']); return $params; }