dikplhd/app/Imports/DatasetTable22Import.php

127 lines
4.3 KiB
PHP

<?php
namespace App\Imports;
use App\Models\Dataset\DatasetTable22;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithStartRow;
class DatasetTable22Import implements ToModel,WithStartRow
{
/**
* @param array $row
*
* @return \Illuminate\Database\Eloquent\Model|null
*/
protected $datasetId;
protected $userId;
public function __construct($datasetId,$userId)
{
$this->datasetId = $datasetId;
$this->userId = $userId;
}
public function startRow(): int
{
return 6;
}
public function model(array $row)
{
// cek kalau row kosong jangan insert
if (
$row[0] === null &&
$row[1] === null &&
$row[2] === null &&
$row[3] === null &&
$row[4] === null &&
$row[5] === null &&
$row[6] === null &&
$row[7] === null &&
$row[8] === null &&
$row[9] === null &&
$row[10] === null &&
$row[11] === null &&
$row[12] === null &&
$row[13] === null &&
$row[14] === null &&
$row[15] === null &&
$row[16] === null &&
$row[17] === null &&
$row[18] === null &&
$row[19] === null &&
$row[20] === null &&
$row[21] === null &&
$row[22] === null &&
$row[23] === null &&
$row[24] === null &&
$row[25] === null &&
$row[26] === null &&
$row[27] === null &&
$row[28] === null &&
$row[29] === null &&
$row[30] === null &&
$row[31] === null &&
$row[32] === null &&
$row[33] === null &&
$row[34] === null &&
$row[35] === null &&
$row[36] === null &&
$row[37] === null &&
$row[38] === null &&
$row[39] === null &&
$row[40] === null &&
$row[41] === null
) {
return null; // baris kosong dilewati
}
return new DatasetTable22([
'dataset_id' => $this->datasetId,
'created_by' => $this->userId,
'lokasi' => $row[1],
'waktu' => $row[2],
'lat' => $row[3],
'long' => $row[4],
'tempratur' => $row[5],
'ph' => $row[6],
'kekeruhan' => $row[7],
'warna' => $row[8],
'rasa' => $row[9],
'bau' => $row[10],
'tds' => $row[11],
'bod' => $row[12],
'cod' => $row[13],
'do' => $row[14],
'fosfat' => $row[15],
'no3' => $row[16],
'nh3' => $row[17],
'arsen' => $row[18],
'kobalt' => $row[19],
'barium' => $row[20],
'boron' => $row[21],
'selenium' => $row[22],
'kadmium' => $row[23],
'khrom' => $row[24],
'tembaga' => $row[25],
'besi' => $row[26],
'timbal' => $row[27],
'mangan' => $row[28],
'air_raksa' => $row[29],
'seng' => $row[30],
'khlorida' => $row[31],
'sianida' => $row[32],
'fluorida' => $row[33],
'nitrit' => $row[34],
'sulfat' => $row[35],
'khlorin_bebas' => $row[36],
'belereng' => $row[37],
'fecal_coliform' => $row[38],
'total_coliform' => $row[39],
'gross' => $row[40],
'grossb' => $row[41],
]);
}
}