103 lines
3.7 KiB
PHP
103 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Dataset;
|
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class DatasetTable32 extends Model
|
|
{
|
|
use HasFactory;
|
|
use SoftDeletes;
|
|
protected $table = 'dataset_table32';
|
|
protected $primaryKey = 'DatasetTable32Id';
|
|
|
|
protected $guarded = [];
|
|
|
|
function dataset() {
|
|
return $this->belongsTo('App\Models\Dataset','dataset_id');
|
|
}
|
|
|
|
public static function dataChart($modelClass,$datasetId,$templateId){
|
|
|
|
$datasets = \App\Models\Dataset::where('template_id', $templateId)
|
|
->orderBy('tahun', 'asc')
|
|
->get()
|
|
->map(function ($dataset) use ($modelClass) {
|
|
$dataset->items = (new $modelClass)->where('dataset_id', $dataset->id)->get();
|
|
return $dataset;
|
|
});
|
|
$years = $datasets->pluck('tahun')->toArray();
|
|
$model = self::with('dataset')->whereHas('dataset',function($query) use ($years){
|
|
$query->whereIn('tahun',$years);
|
|
})->where('dataset_id',$datasetId)->selectRaw('
|
|
SUM(REPLACE(tidak_sekolah_l,",",".")::numeric ) as ts_l,
|
|
SUM(REPLACE(tidak_sekolah_p,",",".")::numeric ) as ts_p,
|
|
SUM(REPLACE(sd_p,",",".")::numeric ) as dasar_p,
|
|
SUM(REPLACE(sd_l,",",".")::numeric ) as dasar_l,
|
|
SUM(REPLACE(sltp_p,",",".")::numeric ) as smp_p,
|
|
SUM(REPLACE(sltp_l,",",".")::numeric ) as smp_l,
|
|
SUM(REPLACE(slta_smk_p,",",".")::numeric ) as sma_p,
|
|
SUM(REPLACE(slta_smk_l,",",".")::numeric ) as sma_l,
|
|
SUM(REPLACE(pt_l,",",".")::numeric ) as univ_l,
|
|
SUM(REPLACE(pt_p,",",".")::numeric ) as univ_p
|
|
')->get();
|
|
// Sekolah::selectRaw('SUM(jumlah_siswa) as total_siswa, SUM(jumlah_guru) as total_guru')->first();
|
|
|
|
$result = [];
|
|
foreach ($model as $k => $row) {
|
|
// $lokasi = $row->lokasi ?? 'Unknown';
|
|
|
|
if (!isset($result)) {
|
|
$result = [
|
|
'tidak_sekolah' => [],
|
|
'sd' => [],
|
|
'sltp' => [],
|
|
'slta' => [],
|
|
'pt' => [],
|
|
];
|
|
}
|
|
|
|
$result[$k]['tidak_sekolah'][] = (float) $row->ts_l+(float) $row->ts_p;
|
|
$result[$k]['sd'][] = (float) $row->dasar_p+(float) $row->dasar_l;
|
|
$result[$k]['sltp'][] = (float) $row->smp_p+(float) $row->smp_l;
|
|
$result[$k]['slta'][] = (float) $row->sma_p+(float) $row->sma_l;
|
|
$result[$k]['pt'][] = (float) $row->univ_p+(float) $row->univ_l;
|
|
}
|
|
|
|
return [
|
|
'title' => '',
|
|
'years' => $years,
|
|
'yTitle' => 'Jumlah',
|
|
'yOpposite' => '',
|
|
'series' => collect($result)->flatMap(function ($item) {
|
|
return [
|
|
[
|
|
'name' => "Tidak Sekolah",
|
|
'type' => 'column',
|
|
'data' => $item['tidak_sekolah']
|
|
],[
|
|
'name' => "SD",
|
|
'type' => 'column',
|
|
'data' => $item['sd']
|
|
],[
|
|
'name' => "SMP",
|
|
'type' => 'column',
|
|
'data' => $item['sltp']
|
|
],[
|
|
'name' => "SMA/SMK",
|
|
'type' => 'column',
|
|
'data' => $item['slta']
|
|
],[
|
|
'name' => "Perguruan Tinggi",
|
|
'type' => 'column',
|
|
'data' => $item['pt']
|
|
],
|
|
];
|
|
})->values()
|
|
];
|
|
}
|
|
}
|