public static function useJson($file, $post) { header('Content-Type: text/html; charset=UTF-8'); if (isset($file['fileimport'])) { $json = file_get_contents($file['fileimport']['tmp_name']); $json_objet = json_decode($json, true); $chaine = FileHelper::arbreJson($json_objet, "", ""); $arbre = explode(";", $chaine); foreach ($arbre as $key => $value) { $arbre[$key] = substr($value, 1); } $params = array("result" => true, "arbre" => $arbre, "nameFile" => $file['fileimport']['name'], "json_origine" => $json, "choose" => $post['choose']); if ($post['choose'] == "modify") { $params['chooseMapping'] = $post['chooseMapping']; } } else { $params['result'] = false; } return $params; }
foreach ($arrayCSV[0] as $key => $value) { echo '<option value="' . $key . '">' . $value . '</option>'; } } ?> </select> </td> <td> <select id="selectLinkCollection" class="col-sm-12"> <?php if ($createLink) { $params = array("_id" => new MongoId($idCollection)); $fields = array("mappingFields"); $fieldsCollection = ImportData::getMicroFormats($params, $fields); foreach ($fieldsCollection as $key => $value) { $pathMapping = FileHelper::arbreJson($value['mappingFields'], "", ""); $arrayPathMapping = explode(";", $pathMapping); foreach ($arrayPathMapping as $keyPathMapping => $valuePathMapping) { if (!empty($valuePathMapping)) { echo '<option name="optionLinkCollection" value="' . $valuePathMapping . '">' . $valuePathMapping . '</option>'; } } } } ?> </select> </td> <td> <input type="submit" id="addMapping" class="btn btn-primary col-sm-12" value="Ajouter"/> </td> </tr>
/** * arbreJson * * * * @access public * @param array * @return string */ public static function arbreJson($json, $chaine, $pere) { foreach ($json as $key => $value) { if (is_array($value) == true) { $pere = $pere . "." . $key; $chaine = FileHelper::arbreJson($value, $chaine, $pere); } else { $chaine = $chaine . $pere . "." . $key . ";"; } } return $chaine; }