21 lines
750 B
PHP
21 lines
750 B
PHP
<?php
|
||
|
||
namespace App\Imports;
|
||
|
||
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
||
|
||
class Import {
|
||
public array $mapper = [];
|
||
|
||
public function mapData($row) {
|
||
$result = [];
|
||
foreach ($this->mapper as $int => $data) {
|
||
//if (!empty($data['prop']) && !empty($row[$data['prop']])) $result[$int] = trim(Str::replace(' ', '', $row[$data['prop']]));
|
||
if (!empty($data['prop']) && !empty($row[$data['prop']])) $result[$int] = trim($row[$data['prop']], ' ;,');
|
||
if (!empty($data['date']) && is_numeric($result[$int] ?? null)) $result[$int] = Date::excelToDateTimeObject($result[$int]);
|
||
if (!empty($data['required']) && empty($result[$int])) return false;
|
||
}
|
||
return $result;
|
||
}
|
||
}
|