Skip to content

Commit 4bb9670

Browse files
committed
Merge branch 'dev-538' into dev-539
2 parents 5bc7e30 + 86d399b commit 4bb9670

25 files changed

+1358
-104
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Admin;
4+
5+
use App\Http\Controllers\Controller;
6+
use App\Models\Opendk;
7+
use Illuminate\Http\Request;
8+
9+
class OpenDKPetaController extends Controller
10+
{
11+
public function __construct()
12+
{
13+
config()->set('adminlte.sidebar_collapse', true);
14+
config()->set('adminlte.sidebar_collapse_remember', false);
15+
}
16+
17+
public function index(Request $request)
18+
{
19+
if ($request->ajax()) {
20+
$fillters = [
21+
'kode_provinsi' => $request->kode_provinsi,
22+
'kode_kabupaten' => $request->kode_kabupaten,
23+
'kode_kecamatan' => $request->kode_kecamatan,
24+
'period' => $request->period,
25+
];
26+
27+
$geoJSONdata = Opendk::filter($fillters)
28+
->whereRaw("CONCAT('',lat * 1) = lat") // tdk ikut sertakan data bukan bilangan
29+
->whereRaw("CONCAT('',lng * 1) = lng") // tdk ikut sertakan data bukan bilangan
30+
->whereRaw('lat BETWEEN -10 AND 6')
31+
->whereRaw('lng BETWEEN 95 AND 142')
32+
->where(function ($query) {
33+
$query
34+
->where('lat', '!=', config('tracksid.desa_contoh.lat'))
35+
->where('lng', '!=', config('tracksid.desa_contoh.lng'));
36+
})->orderBy('kode_kecamatan', 'ASC')->get()->map(function ($kecamatan) {
37+
return [
38+
'type' => 'Feature',
39+
'geometry' => [
40+
'type' => 'Point',
41+
'coordinates' => [
42+
(float) $kecamatan->lng,
43+
(float) $kecamatan->lat,
44+
],
45+
],
46+
'properties' => $this->properties($kecamatan),
47+
'id' => $kecamatan->kode_kecamatan,
48+
];
49+
});
50+
51+
return response()->json([
52+
'type' => 'FeatureCollection',
53+
'features' => $geoJSONdata,
54+
]);
55+
}
56+
57+
return view('admin.opendk.peta.index');
58+
}
59+
60+
private function properties(Opendk $kecamatan)
61+
{
62+
$link = '';
63+
if (auth()->check()) {
64+
$link = '<tr><td>Website</td><td> : <a href="http://' . strtolower($kecamatan->url) . '" target="_blank">' . strtolower($kecamatan->url) . '</a></b></td></tr>';
65+
}
66+
67+
return [
68+
'logo' => null,
69+
'popupContent' => '
70+
<h6 class="text-center"><b style="color:red">' . strtoupper($kecamatan->sebutan_wilayah . ' ' . $kecamatan->nama_kecamatan) . '</b></h6>
71+
<b><table width="100%">
72+
<tr>
73+
<td>' . ucwords($kecamatan->sebutan_wilayah) . '</td><td> : ' . ucwords($kecamatan->sebutan_wilayah . ' ' . $kecamatan->nama_kecamatan) . '</b></td>
74+
</tr>
75+
<tr>
76+
<td>Kecamatan</td><td> : ' . ucwords($kecamatan->nama_kecamatan) . '</b></td>
77+
</tr>
78+
<tr>
79+
<td>Kab/Kota</td><td> : ' . ucwords($kecamatan->nama_kabupaten) . '</b></td>
80+
</tr>
81+
<tr>
82+
<td>Provinsi</td><td> : ' . ucwords($kecamatan->nama_provinsi) . '</b></td>
83+
</tr>
84+
<tr>
85+
<td>Alamat</td><td> : ' . $kecamatan->alamat . '</b></td>
86+
</tr>
87+
' . $link . '
88+
</table></b>',
89+
];
90+
}
91+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Api;
4+
5+
use App\Http\Controllers\Controller;
6+
use App\Models\Desa;
7+
use Illuminate\Http\Request;
8+
9+
class DesaAktifOpensidController extends Controller
10+
{
11+
/**
12+
* Handle the incoming request.
13+
*/
14+
public function __invoke(Request $request)
15+
{
16+
return Desa::jumlahDesa()->filterWilayah($request)->first();
17+
}
18+
}

app/Http/Controllers/Api/InstallOpensidController.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,9 @@ class InstallOpensidController extends Controller
1111
{
1212
public function chart(Request $request)
1313
{
14-
$provinsi = $request->get('provinsi');
15-
$kabupaten = $request->get('kabupaten');
16-
$kecamatan = $request->get('kecamatan');
1714
$minCreatedAt = Carbon::now()->subYears(2)->format('Y-m-d');
18-
$opensid = Desa::selectRaw("DATE_FORMAT(created_at, '%m-%Y') month_year, count(*) as total")
15+
$opensid = Desa::filterWilayah($request)->selectRaw("DATE_FORMAT(created_at, '%m-%Y') month_year, count(*) as total")
1916
->groupBy('month_year')->orderBy('created_at')->whereDate('created_at', '>', $minCreatedAt);
20-
if ($provinsi) {
21-
$opensid->where('kode_provinsi', $provinsi);
22-
}
23-
if ($kabupaten) {
24-
$opensid->where('kode_kabupaten', $kabupaten);
25-
}
26-
if ($kecamatan) {
27-
$opensid->where('kode_kecamatan', $kecamatan);
28-
}
2917

3018
$opensidData = $opensid->get();
3119
$labels = [];
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Api;
4+
5+
use App\Http\Controllers\Controller;
6+
use App\Models\Desa;
7+
use Carbon\Carbon;
8+
use Illuminate\Http\Request;
9+
10+
class InstallOpensidTodayController extends Controller
11+
{
12+
/**
13+
* Handle the incoming request.
14+
*/
15+
public function __invoke(Request $request)
16+
{
17+
$totalInstall = Desa::filterWilayah($request)->count();
18+
$totalInstallOnline = Desa::filterWilayah($request)->online()->count();
19+
$installHariIni = Desa::filterWilayah($request)->whereDate('created_at', '>=', Carbon::now()->format('Y-m-d'))->get();
20+
return [
21+
'total' => ['online' => $totalInstallOnline, 'offline' => $totalInstall - $totalInstallOnline],
22+
'installHariIni' => $installHariIni,
23+
];
24+
}
25+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Api;
4+
5+
use App\Http\Controllers\Controller;
6+
use App\Models\Desa;
7+
use App\Models\Pbb;
8+
use Illuminate\Http\Request;
9+
10+
class PenggunaSelainOpensidController extends Controller
11+
{
12+
/**
13+
* Handle the incoming request.
14+
*/
15+
public function __invoke(Request $request)
16+
{
17+
return [
18+
'pbb' => Pbb::filterWilayah($request)->count(),
19+
'anjungan' => Desa::filterWilayah($request)->anjungan()->count(),
20+
];
21+
}
22+
}

app/Http/Controllers/DashboardController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function index()
4747
public function datatableDesaBaru(Request $request)
4848
{
4949
if ($request->ajax()) {
50-
return DataTables::of($this->desa->desaBaru()->get()->map(function ($desa) {
50+
return DataTables::of($this->desa->filterWilayah($request)->desaBaru()->get()->map(function ($desa) {
5151
if (auth()->check() == false) {
5252
unset($desa['url_hosting']);
5353
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use App\Models\Opendk;
6+
use App\Models\Desa;
7+
use Carbon\Carbon;
8+
use Illuminate\Http\Request;
9+
use Yajra\DataTables\Facades\DataTables;
10+
use Illuminate\Support\Facades\DB;
11+
12+
class KecamatanAktifOpendkController extends Controller
13+
{
14+
public function index(Request $request)
15+
{
16+
$fillters = [
17+
'kode_provinsi' => $request->kode_provinsi,
18+
'kode_kabupaten' => $request->kode_kabupaten,
19+
'kode_kecamatan' => $request->kode_kecamatan,
20+
'akses_opendk' => $request->akses_opendk,
21+
'versi_opendk' => $request->versi_opendk,
22+
];
23+
24+
if ($request->ajax()) {
25+
$_30HariLalu = Carbon::now()->subDays(30);
26+
27+
// Query untuk mendapatkan data kecamatan OpenDK yang aktif dalam 30 hari terakhir
28+
$query = Opendk::wilayahkhusus()
29+
->where('updated_at', '>=', $_30HariLalu)
30+
->filterDatatable($fillters)
31+
->select([
32+
'kode_kecamatan',
33+
'nama_kecamatan',
34+
'nama_kabupaten',
35+
'nama_provinsi',
36+
'updated_at'
37+
]);
38+
39+
return DataTables::of($query)
40+
->addIndexColumn()
41+
->addColumn('jumlah_desa', function ($data) {
42+
// Hitung jumlah desa berdasarkan kode kecamatan
43+
return Desa::where('kode_kecamatan', $data->kode_kecamatan)->count();
44+
})
45+
->addColumn('akses_publik_30_hari', function ($data) use ($_30HariLalu) {
46+
// Hitung total akses dalam 30 hari untuk desa di kecamatan ini
47+
return Desa::where('kode_kecamatan', $data->kode_kecamatan)
48+
->withCount([
49+
'akses' => function ($q) use ($_30HariLalu) {
50+
$q->where('created_at', '>=', $_30HariLalu);
51+
}
52+
])
53+
->get()
54+
->sum('akses_count');
55+
})
56+
->addColumn('akses_admin_30_hari', function ($data) use ($_30HariLalu) {
57+
// Untuk sementara gunakan data yang sama seperti akses publik
58+
// karena tidak ada pembedaan admin/publik di tabel akses
59+
return Desa::where('kode_kecamatan', $data->kode_kecamatan)
60+
->withCount([
61+
'akses' => function ($q) use ($_30HariLalu) {
62+
$q->where('created_at', '>=', $_30HariLalu);
63+
}
64+
])
65+
->get()
66+
->sum('akses_count');
67+
})
68+
->addColumn('jumlah_artikel', function ($data) {
69+
// Hitung total artikel untuk desa di kecamatan ini
70+
return Desa::where('kode_kecamatan', $data->kode_kecamatan)
71+
->sum('jml_artikel') ?? 0;
72+
})
73+
->addColumn('akses_terakhir', function ($data) {
74+
return $data->updated_at ? $data->updated_at->format('Y-m-d H:i:s') : '-';
75+
})
76+
->make(true);
77+
}
78+
79+
return view('opendk.kecamatan_aktif', compact('fillters'));
80+
}
81+
}

app/Http/Controllers/WebsiteDashboardController.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -365,24 +365,15 @@ public function opensid(Request $request)
365365
'tte' => $request->tte,
366366
];
367367

368-
$totalInstall = Desa::count();
369-
$totalInstallOnline = Desa::online()->count();
370-
$installHariIni = Desa::whereDate('created_at', '>=', Carbon::now()->format('Y-m-d'))->get();
371-
372368
return view('website.opensid', [
373369
'fillters' => $fillters,
374370
'fillterModals' => $fillterModals,
375-
'total' => ['online' => $totalInstallOnline, 'offline' => $totalInstall - $totalInstallOnline],
376-
'installHariIni' => $installHariIni,
377371
'total_versi' => Desa::distinct('versi_hosting')->whereNotNull('versi_hosting')->count(),
378372
'versi_terakhir' => lastrelease_opensid(),
379373
'provinsi_pengguna_opensid' => Desa::selectRaw('nama_provinsi, count(*) as total')->orderBy('total', 'desc')->groupBy('nama_provinsi')->get(),
380-
'pengguna_pbb' => Pbb::count(),
381374
'versi_pbb' => lastrelease_pbb(),
382-
'pengguna_anjungan' => Desa::anjungan()->count(),
383375
'latestPremiumVersion' => 'v'.lastrelease_opensid().'-premium',
384376
'latestUmumVersion' => 'v'.lastrelease_opensid(),
385-
'statistikDesa' => Desa::jumlahDesa()->get()->first(),
386377
]);
387378
}
388379

app/Models/Desa.php

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Models;
44

55
use App\Models\Traits\HasRegionAccess;
6+
use App\Traits\FilterWilayahTrait;
67
use Carbon\Carbon;
78
use Illuminate\Database\Eloquent\Factories\HasFactory;
89
use Illuminate\Database\Eloquent\Model;
@@ -11,7 +12,8 @@
1112

1213
class Desa extends Model
1314
{
14-
use HasFactory, HasRegionAccess;
15+
16+
use HasFactory, HasRegionAccess, FilterWilayahTrait;
1517

1618
/** {@inheritdoc} */
1719
protected $table = 'desa';
@@ -67,18 +69,28 @@ public function scopeJumlahDesa($query)
6769
if ($provinsi = session('provinsi')) {
6870
$states = "and x.kode_provinsi={$provinsi->kode_prov}";
6971
}
72+
$filterWilayah = '';
73+
$request = request();
74+
if ($request->kode_provinsi || $request->kode_kabupaten || $request->kode_kecamatan) {
75+
$filterWilayah = Desa::filterWilayah($request)->toBoundSql();
76+
}
77+
if ($filterWilayah) {
78+
$filterWilayah = Str::replaceFirst('select * from `desa` where ', 'and ', $filterWilayah);
79+
$filterWilayah = Str::replaceMatches('/\b(kode_provinsi|kode_kabupaten|kode_kecamatan)\b/', 'x.$1', $filterWilayah);
80+
$filterWilayah = Str::replace('`', '', $filterWilayah);
81+
}
7082

7183
return $query
7284
->selectRaw('count(id) as desa_total')
73-
->selectRaw("(select count(id) from desa as x where x.versi_lokal <> '' and x.versi_hosting is null and coalesce(x.tgl_akses_lokal, 0) >= now() - interval 7 day {$states}) desa_offline")
74-
->selectRaw("(select count(id) from desa as x where x.versi_hosting <> '' and greatest(coalesce(x.tgl_akses_lokal, 0), coalesce(x.tgl_akses_hosting, 0)) >= now() - interval 7 day {$states}) desa_online")
85+
->selectRaw("(select count(id) from desa as x where x.versi_lokal <> '' and x.versi_hosting is null and coalesce(x.tgl_akses_lokal, 0) >= now() - interval 7 day {$states} {$filterWilayah}) desa_offline")
86+
->selectRaw("(select count(id) from desa as x where x.versi_hosting <> '' and greatest(coalesce(x.tgl_akses_lokal, 0), coalesce(x.tgl_akses_hosting, 0)) >= now() - interval 7 day {$states} {$filterWilayah}) desa_online")
7587
->selectRaw('count(distinct kode_kabupaten) as kabupaten_total')
76-
->selectRaw("(select count(distinct x.kode_kabupaten) from desa as x where (x.versi_hosting like '{$version}-premium%' or x.versi_lokal like '{$version}-premium%') {$states} ) as kabupaten_premium")
77-
->selectRaw("(select count(distinct x.kode_kabupaten) from desa as x where x.versi_lokal <> '' {$states}) kabupaten_offline")
78-
->selectRaw("(select count(distinct x.kode_kabupaten) from desa as x where x.versi_hosting <> '' {$states}) kabupaten_online")
79-
->selectRaw("(select count(id) from desa as x where x.jenis = 2 {$states}) bukan_desa")
80-
->selectRaw("(select count(id) from desa as x where greatest(coalesce(x.tgl_akses_lokal, 0), coalesce(x.tgl_akses_hosting, 0)) < now() - interval 4 month {$states}) tidak_aktif")
81-
->selectRaw("(select count(id) from desa as x where greatest(coalesce(x.tgl_akses_lokal, 0), coalesce(x.tgl_akses_hosting, 0)) >= now() - interval 7 day {$states}) aktif")
88+
->selectRaw("(select count(distinct x.kode_kabupaten) from desa as x where (x.versi_hosting like '{$version}-premium%' or x.versi_lokal like '{$version}-premium%') {$states} {$filterWilayah}) as kabupaten_premium")
89+
->selectRaw("(select count(distinct x.kode_kabupaten) from desa as x where x.versi_lokal <> '' {$states} {$filterWilayah}) kabupaten_offline")
90+
->selectRaw("(select count(distinct x.kode_kabupaten) from desa as x where x.versi_hosting <> '' {$states} {$filterWilayah}) kabupaten_online")
91+
->selectRaw("(select count(id) from desa as x where x.jenis = 2 {$states} {$filterWilayah}) bukan_desa")
92+
->selectRaw("(select count(id) from desa as x where greatest(coalesce(x.tgl_akses_lokal, 0), coalesce(x.tgl_akses_hosting, 0)) < now() - interval 4 month {$states} {$filterWilayah}) tidak_aktif")
93+
->selectRaw("(select count(id) from desa as x where greatest(coalesce(x.tgl_akses_lokal, 0), coalesce(x.tgl_akses_hosting, 0)) >= now() - interval 7 day {$states} {$filterWilayah}) aktif")
8294
->when($provinsi, function ($query, $provinsi) {
8395
$query->where('kode_provinsi', $provinsi->kode_prov);
8496
});
@@ -201,6 +213,7 @@ public function scopeVersiOpenSID($query, $fillters = [])
201213
->fromSub(function ($query) use ($fillters) {
202214
$query
203215
->selectRaw("versi_lokal AS versi, 'offline' AS jenis ")
216+
->filterWilayah(request())
204217
->where('versi_lokal', '<>', '')
205218
->when(session('provinsi'), function ($query, $provinsi) {
206219
$query->where('kode_provinsi', $provinsi->kode_prov);
@@ -222,7 +235,7 @@ public function scopeVersiOpenSID($query, $fillters = [])
222235
})
223236
->when($fillters['aktif'] == '0', function ($query) {
224237
$query->whereRaw('coalesce(tgl_akses_hosting, 0) <= now() - interval 7 day');
225-
})
238+
})->filterWilayah(request())
226239
->from('desa');
227240
})
228241
->from('desa');

app/Models/Pbb.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
namespace App\Models;
44

5+
use App\Traits\FilterWilayahTrait;
56
use Carbon\Carbon;
67
use Illuminate\Database\Eloquent\Factories\HasFactory;
78
use Illuminate\Database\Eloquent\Model;
89

910
class Pbb extends Model
1011
{
11-
use HasFactory;
12+
use HasFactory, FilterWilayahTrait;
1213

1314
const ACTIVE_DAYS = 7;
1415

0 commit comments

Comments
 (0)