Fix naming of two first column in csv import to be name independant

This commit is contained in:
osaajani 2020-06-13 19:49:17 +02:00
parent 53d462263c
commit 65a243b7b4
1 changed files with 7 additions and 5 deletions

View File

@ -139,15 +139,17 @@ namespace controllers\internals;
continue; continue;
} }
if (!isset($line['name'], $line['number'])) if (!isset($line[array_keys($line)[0]], $line[array_keys($line)[1]]))
{ {
continue; continue;
} }
$datas = []; $datas = [];
$i = 0;
foreach ($line as $key => $value) foreach ($line as $key => $value)
{ {
if ('name' === $key || 'number' === $key) $i++;
if ($i < 3)
{ {
continue; continue;
} }
@ -164,7 +166,7 @@ namespace controllers\internals;
try try
{ {
$success = $this->create($id_user, $line['number'], $line['name'], $datas); $success = $this->create($id_user, $line[array_keys($line)[1]], $line[array_keys($line)[0]], $datas);
if ($success) if ($success)
{ {
++$nb_insert; ++$nb_insert;
@ -259,8 +261,8 @@ namespace controllers\internals;
$contacts = $this->get_model()->gets_for_user($id_user); $contacts = $this->get_model()->gets_for_user($id_user);
$columns = [ $columns = [
'name', 'contact_name',
'number', 'contact_number',
]; ];
foreach ($contacts as $contact) foreach ($contacts as $contact)