public function mapFile($entityType, $filename, $columns, $map)
{
require_once app_path() . '/Includes/parsecsv.lib.php';
$csv = new parseCSV();
$csv->heading = false;
$csv->auto($filename);
Session::put("{$entityType}-data", $csv->data);
$headers = false;
$hasHeaders = false;
$mapped = [];
if (count($csv->data) > 0) {
$headers = $csv->data[0];
foreach ($headers as $title) {
if (strpos(strtolower($title), 'name') > 0) {
$hasHeaders = true;
break;
}
}
for ($i = 0; $i < count($headers); $i++) {
$title = strtolower($headers[$i]);
$mapped[$i] = '';
foreach ($map as $search => $column) {
if ($this->checkForMatch($title, $search)) {
$hasHeaders = true;
$mapped[$i] = $column;
break;
}
}
}
}
$data = ['entityType' => $entityType, 'data' => $csv->data, 'headers' => $headers, 'hasHeaders' => $hasHeaders, 'columns' => $columns, 'mapped' => $mapped];
return $data;
}