Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
sibiling
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Syaifur
sibiling
Commits
7937df57
Commit
7937df57
authored
Sep 06, 2024
by
FARDA ALAN MA'RUF
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into feature/import-dapodik
parents
704d1f4d
2789c35f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
355 additions
and
0 deletions
+355
-0
ImportDapodikController.php
...Http/Controllers/Admin/Import/ImportDapodikController.php
+297
-0
DapodikGuruModel.php
app/Models/Import/DapodikGuruModel.php
+20
-0
DapodikSiswaModel.php
app/Models/Import/DapodikSiswaModel.php
+20
-0
database.php
config/database.php
+15
-0
web.php
routes/web.php
+3
-0
No files found.
app/Http/Controllers/Admin/Import/ImportDapodikController.php
0 → 100644
View file @
7937df57
<?php
namespace
App\Http\Controllers\Admin\Import
;
use
App\Http\Controllers\Controller
;
use
Illuminate\Http\Request
;
use
Illuminate\Support\Facades\DB
;
use
App\Models\Import\DapodikGuruModel
;
use
App\Models\Import\DapodikSiswaModel
;
use
App\Models\User\UserModel
;
use
App\Models\Stakeholder\GuruModel
;
use
App\Models\Stakeholder\KonselorModel
;
use
App\Models\Perpus\SekolahModel
;
class
ImportDapodikController
extends
Controller
{
public
function
importDapodikGuru
()
{
$dataGuruTemp
=
DapodikGuruModel
::
select
([
'nama'
,
'nip'
,
'jenis_ptk'
,
'hp'
,
'email'
,
])
->
get
();
// echo json_encode($dataGuruTemp); die;
$importResults
=
[
'guru_mapel'
=>
[
'berhasil'
=>
0
,
'gagal'
=>
0
],
'guru_bk'
=>
[
'berhasil'
=>
0
,
'gagal'
=>
0
],
];
$dataGuruTemp
->
map
(
function
(
$guru
)
use
(
&
$importResults
)
{
// $existingGuru = GuruModel::where('nip', $guru->nip)->first();
$existingGuru
=
DB
::
table
(
'dummy_sekolah_guru'
)
->
where
(
'nip'
,
$guru
->
nip
)
->
first
();
if
(
$guru
->
jenis_ptk
==
'Guru Mapel'
)
{
if
(
!
$existingGuru
)
{
try
{
DB
::
table
(
'dummy_sekolah_guru'
)
->
insert
([
'idPSekolah'
=>
1
,
// dummy
'idMapel'
=>
99
,
'nip'
=>
$guru
->
nip
??
'-'
,
'telp'
=>
$guru
->
hp
??
'-'
,
'email'
=>
$guru
->
email
??
'-'
,
'status'
=>
1
,
]);
$importResults
[
'guru_mapel'
][
'berhasil'
]
++
;
}
catch
(
\Exception
$e
)
{
$importResults
[
'guru_mapel'
][
'gagal'
]
++
;
}
}
else
{
$importResults
[
'guru_mapel'
][
'gagal'
]
++
;
}
}
elseif
(
$guru
->
jenis_ptk
==
'Guru BK'
)
{
if
(
!
$existingGuru
)
{
try
{
$guruImport
=
DB
::
table
(
'dummy_sekolah_guru'
)
->
insertGetId
([
'idPSekolah'
=>
1
,
// dummy
'idMapel'
=>
99
,
'nip'
=>
$guru
->
nip
??
'-'
,
'telp'
=>
$guru
->
hp
??
'-'
,
'email'
=>
$guru
->
email
??
'-'
,
'status'
=>
1
,
]);
$konselorImport
=
DB
::
table
(
'dummy_sekolah_konselor'
)
->
insertGetId
([
'idPSekolah'
=>
1
,
// dummy
'idSGuru'
=>
$guruImport
,
'status'
=>
1
,
]);
$sekolah
=
SekolahModel
::
where
(
'id'
,
1
)
->
first
();
DB
::
table
(
'dummy_users'
)
->
insert
([
'username'
=>
$guru
->
email
,
'password'
=>
bcrypt
(
"sibiling-2024"
),
'sandi'
=>
"sibiling-2024"
,
// dummy
'status'
=>
1
,
'idPSekolah'
=>
1
,
// dummy
'role'
=>
3
,
// konselor
'idSKonselor'
=>
$konselorImport
,
'idPPeriode'
=>
$sekolah
->
idPPeriode
,
'telp'
=>
$guru
->
hp
??
'-'
,
]);
$importResults
[
'guru_bk'
][
'berhasil'
]
++
;
}
catch
(
\Exception
$e
)
{
$importResults
[
'guru_bk'
][
'gagal'
]
++
;
}
}
else
{
$importResults
[
'guru_bk'
][
'gagal'
]
++
;
}
}
});
return
response
()
->
json
([
'message'
=>
'Proses import selesai'
,
'hasil'
=>
$importResults
,
]);
}
public
function
importDapodikSiswa
()
{
$dataPesertaDidik
=
DapodikSiswaModel
::
select
([
'nama'
,
'nisn'
,
'tempat_lahir'
,
'tanggal_lahir'
,
'agama'
,
'alamat'
,
'rt'
,
'rw'
,
'dusun'
,
'kelurahan'
,
'kecamatan'
,
'kode_pos'
,
'jenis_tinggal'
,
'telepon'
,
'hp'
,
'email'
,
'nama_ayah'
,
'pekerjaan_ayah'
,
'rombel_saat_ini'
])
->
get
();
$importResults
=
[
'import_tingkat'
=>
[
'berhasil'
=>
0
,
'gagal'
=>
0
],
'import_jurusan'
=>
[
'berhasil'
=>
0
,
'gagal'
=>
0
],
'import_index'
=>
[
'berhasil'
=>
0
,
'gagal'
=>
0
],
'import_siswa'
=>
[
'berhasil'
=>
0
,
'gagal'
=>
0
],
'import_siswa_mutasi'
=>
[
'berhasil'
=>
0
,
'gagal'
=>
0
],
'import_siswa_ortu'
=>
[
'berhasil'
=>
0
,
'gagal'
=>
0
],
];
$sekolah
=
DB
::
table
(
'perpus_sekolah'
)
->
where
(
'id'
,
1
)
->
first
();
// dummy
$dataPesertaDidik
->
map
(
function
(
$peserta
)
use
(
&
$importResults
,
$sekolah
)
{
try
{
// Pastikan kolom rombel_saat_ini valid
if
(
!
$peserta
->
rombel_saat_ini
)
{
throw
new
\Exception
(
"Rombel tidak ditemukan"
);
}
list
(
$kelas
,
$jurusan
,
$kodeKelas
)
=
explode
(
'-'
,
$peserta
->
rombel_saat_ini
);
// Pengecekan jurusan
try
{
$jurusanId
=
DB
::
table
(
'dummy_perpus_jurusan'
)
->
where
(
'nama'
,
$jurusan
)
->
value
(
'id'
);
if
(
!
$jurusanId
)
{
$jurusanId
=
DB
::
table
(
'dummy_perpus_jurusan'
)
->
insertGetId
([
'idPSekolah'
=>
1
,
// dummy
'nama'
=>
$jurusan
,
]);
$importResults
[
'import_jurusan'
][
'berhasil'
]
++
;
}
}
catch
(
\Exception
$e
)
{
echo
json_encode
(
$e
);
die
;
$importResults
[
'import_jurusan'
][
'gagal'
]
++
;
}
// Pengecekan tingkat/kelas
try
{
$kelasId
=
DB
::
table
(
'dummy_perpus_kelas'
)
->
where
(
'nama'
,
$kelas
)
->
value
(
'id'
);
if
(
!
$kelasId
)
{
$kelasId
=
DB
::
table
(
'dummy_perpus_kelas'
)
->
insertGetId
([
'idPSekolah'
=>
1
,
// dummy
'idPJurusan'
=>
$jurusanId
,
'nama'
=>
$kelas
,
]);
$importResults
[
'import_tingkat'
][
'berhasil'
]
++
;
}
}
catch
(
\Exception
$e
)
{
echo
json_encode
(
$e
);
die
;
$importResults
[
'import_tingkat'
][
'gagal'
]
++
;
}
// Pengecekan kode kelas
try
{
$kelasKodeId
=
DB
::
table
(
'dummy_perpus_kelasKode'
)
->
where
([
[
'nama'
,
'='
,
$kodeKelas
],
[
'idPSekolah'
,
'='
,
1
],
// dummy
[
'idPJurusan'
,
'='
,
$jurusanId
],
[
'idPKelas'
,
'='
,
$kelasId
],
])
->
value
(
'id'
);
if
(
!
$kelasKodeId
)
{
$kelasKodeId
=
DB
::
table
(
'dummy_perpus_kelasKode'
)
->
insertGetId
([
'idPSekolah'
=>
1
,
// dummy
'idPJurusan'
=>
$jurusanId
,
'idPKelas'
=>
$kelasId
,
'nama'
=>
$kodeKelas
,
]);
$importResults
[
'import_index'
][
'berhasil'
]
++
;
}
}
catch
(
\Exception
$e
)
{
echo
json_encode
(
$e
);
die
;
$importResults
[
'import_index'
][
'gagal'
]
++
;
}
// Cek apakah siswa sudah ada
try
{
$existingSiswa
=
DB
::
table
(
'dummy_siswa'
)
->
where
(
'nisn'
,
$peserta
->
nisn
)
->
first
();
if
(
!
$existingSiswa
)
{
$alamatLengkap
=
$peserta
->
alamat
.
', RT: '
.
(
$peserta
->
rt
??
'-'
)
.
', RW: '
.
(
$peserta
->
rw
??
'-'
)
.
', Dusun: '
.
(
$peserta
->
dusun
??
'-'
)
.
', Kelurahan: '
.
(
$peserta
->
kelurahan
??
'-'
)
.
', Kecamatan: '
.
(
$peserta
->
kecamatan
??
'-'
)
.
', Kode Pos: '
.
(
$peserta
->
kode_pos
??
'-'
);
$idMTempat
=
$this
->
getTempatId
(
$peserta
->
jenis_tinggal
);
$idMAgama
=
$this
->
getAgamaId
(
$peserta
->
agama
);
$siswaId
=
DB
::
table
(
'dummy_siswa'
)
->
insertGetId
([
'idPSekolah'
=>
1
,
// dummy
'idPKKode'
=>
$kelasKodeId
,
'idMAgama'
=>
$idMAgama
,
'idPPeriode'
=>
$sekolah
->
idPPeriode
,
'idMStatus'
=>
1
,
'nisn'
=>
$peserta
->
nisn
??
'-'
,
'nama'
=>
$peserta
->
nama
,
'lahir_tanggal'
=>
$peserta
->
tanggal_lahir
,
'lahir_tempat'
=>
$peserta
->
tempat_lahir
,
'idPPKelas'
=>
$kelasId
,
'idPPStatus'
=>
1
,
'idMTempat'
=>
$idMTempat
,
'email'
=>
$peserta
->
email
??
'-'
,
'telp'
=>
$peserta
->
hp
??
$peserta
->
telepon
??
'-'
,
'alamat'
=>
$alamatLengkap
,
]);
$importResults
[
'import_siswa'
][
'berhasil'
]
++
;
// Insert ke siswa_mutasi
DB
::
table
(
'dummy_siswa_mutasi'
)
->
insert
([
'idSiswa'
=>
$siswaId
,
'idPKKode'
=>
$kelasKodeId
,
'idPPeriode'
=>
$sekolah
->
idPPeriode
,
'idMStatus'
=>
1
,
]);
$importResults
[
'import_siswa_mutasi'
][
'berhasil'
]
++
;
// Insert ke ortu
$idMPekerjaan
=
$this
->
getPekerjaanId
(
$peserta
->
pekerjaan_ayah
);
DB
::
table
(
'dummy_ortu'
)
->
insert
([
'idPSekolah'
=>
1
,
'idSiswa'
=>
$siswaId
,
'idMPekerjaan'
=>
$idMPekerjaan
,
'nama'
=>
$peserta
->
nama_ayah
,
'alamat'
=>
$alamatLengkap
,
]);
$importResults
[
'import_siswa_ortu'
][
'berhasil'
]
++
;
}
}
catch
(
\Exception
$e
)
{
$importResults
[
'import_siswa'
][
'gagal'
]
++
;
$importResults
[
'import_siswa_mutasi'
][
'gagal'
]
++
;
$importResults
[
'import_siswa_ortu'
][
'gagal'
]
++
;
}
}
catch
(
\Exception
$e
)
{
// Log error umum untuk satu peserta didik
error_log
(
$e
->
getMessage
());
}
});
return
response
()
->
json
(
$importResults
);
}
private
function
getTempatId
(
$jenisTinggal
)
{
$tempatMapping
=
[
'Bersama orang tua'
=>
1
,
'Wali'
=>
2
,
'Asrama'
=>
3
,
'Kost'
=>
4
,
];
return
$tempatMapping
[
$jenisTinggal
]
??
1
;
}
private
function
getAgamaId
(
$agama
)
{
$agamaMapping
=
[
'Islam'
=>
1
,
'Kristen'
=>
2
,
'Budha'
=>
3
,
'Konghucu'
=>
4
,
'Katolik'
=>
5
,
'Hindu'
=>
6
,
'Lainnya'
=>
0
];
return
$agamaMapping
[
$agama
]
??
0
;
}
private
function
getPekerjaanId
(
$pekerjaan
)
{
$pekerjaanMapping
=
[
'Guru'
=>
1
,
'Dosen'
=>
2
,
'PNS/TNI/POLRI'
=>
3
,
'BUMN'
=>
4
,
'Swasta'
=>
5
,
'Wiraswasta'
=>
6
,
];
if
(
!
isset
(
$pekerjaanMapping
[
$pekerjaan
]))
{
$idPekerjaan
=
DB
::
table
(
'master_pekerjaan'
)
->
insertGetId
([
'nama'
=>
$pekerjaan
,
]);
return
$idPekerjaan
;
}
return
$pekerjaanMapping
[
$pekerjaan
];
}
}
\ No newline at end of file
app/Models/Import/DapodikGuruModel.php
0 → 100644
View file @
7937df57
<?php
namespace
App\Models\Import
;
use
Illuminate\Database\Eloquent\Factories\HasFactory
;
use
Illuminate\Database\Eloquent\Model
;
// Library
use
DB
;
// use Illuminate\Database\Eloquent\SoftDeletes;
class
DapodikGuruModel
extends
Model
{
// use HasFactory, SoftDeletes;
use
HasFactory
;
protected
$connection
=
'bkpeduli_datatemp'
;
protected
$table
=
'data_guru'
;
}
app/Models/Import/DapodikSiswaModel.php
0 → 100644
View file @
7937df57
<?php
namespace
App\Models\Import
;
use
Illuminate\Database\Eloquent\Factories\HasFactory
;
use
Illuminate\Database\Eloquent\Model
;
// Library
use
DB
;
// use Illuminate\Database\Eloquent\SoftDeletes;
class
DapodikSiswaModel
extends
Model
{
// use HasFactory, SoftDeletes;
use
HasFactory
;
protected
$connection
=
'bkpeduli_datatemp'
;
protected
$table
=
'data_peserta_didik'
;
}
\ No newline at end of file
config/database.php
View file @
7937df57
...
@@ -35,6 +35,21 @@ return [
...
@@ -35,6 +35,21 @@ return [
'connections'
=>
[
'connections'
=>
[
'bkpeduli_datatemp'
=>
[
'driver'
=>
'mysql'
,
'host'
=>
env
(
'DB_HOST_TEMP'
,
'127.0.0.1'
),
'port'
=>
env
(
'DB_PORT_TEMP'
,
'3306'
),
'database'
=>
env
(
'DB_DATABASE_TEMP'
,
'bkpeduli_datatemp'
),
'username'
=>
env
(
'DB_USERNAME_TEMP'
,
'root'
),
'password'
=>
env
(
'DB_PASSWORD_TEMP'
,
''
),
'unix_socket'
=>
env
(
'DB_SOCKET_TEMP'
,
''
),
'charset'
=>
'utf8mb4'
,
'collation'
=>
'utf8mb4_unicode_ci'
,
'prefix'
=>
''
,
'strict'
=>
true
,
'engine'
=>
null
,
],
'sqlite'
=>
[
'sqlite'
=>
[
'driver'
=>
'sqlite'
,
'driver'
=>
'sqlite'
,
'url'
=>
env
(
'DATABASE_URL'
),
'url'
=>
env
(
'DATABASE_URL'
),
...
...
routes/web.php
View file @
7937df57
...
@@ -31,6 +31,9 @@ Route::get('admin/dashboard', 'Admin\DashboardController@index')->name('dashboar
...
@@ -31,6 +31,9 @@ Route::get('admin/dashboard', 'Admin\DashboardController@index')->name('dashboar
Route
::
middleware
([
'login:1,2'
])
->
group
(
function
()
{
Route
::
middleware
([
'login:1,2'
])
->
group
(
function
()
{
Route
::
get
(
'/import-dapodik-guru'
,
'Admin\Import\ImportDapodikController@importDapodikGuru'
);
Route
::
get
(
'/import-dapodik-siswa'
,
'Admin\Import\ImportDapodikController@importDapodikSiswa'
);
Route
::
prefix
(
'admin/master/sekolah'
)
->
group
(
function
()
{
Route
::
prefix
(
'admin/master/sekolah'
)
->
group
(
function
()
{
Route
::
get
(
'/info'
,
'Admin\Perpus\InfoController@index'
)
->
name
(
'info'
);
Route
::
get
(
'/info'
,
'Admin\Perpus\InfoController@index'
)
->
name
(
'info'
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment