program dan basis data ekosistem
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Core;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
use App\Models\Pertanian\Komoditas;
|
||||
|
||||
class KomoditasProgram extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'core_program_komoditas';
|
||||
|
||||
protected $fillable = [
|
||||
"program_id",
|
||||
"komoditas_id",
|
||||
"default",
|
||||
];
|
||||
|
||||
public function komoditas(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Komoditas::class, 'komoditas_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Core;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
use App\Models\Wilayah\Provinsi;
|
||||
use App\Models\Wilayah\KabupatenKota;
|
||||
use App\Models\Wilayah\Kecamatan;
|
||||
use App\Models\Wilayah\DesaKelurahan;
|
||||
|
||||
class LokasiProgram extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'core_program_lokasi';
|
||||
|
||||
protected $fillable = [
|
||||
"program_id",
|
||||
"provinsi_id",
|
||||
"kabupaten_kota_id",
|
||||
"kecamatan_id",
|
||||
"desa_kelurahan_id",
|
||||
"default",
|
||||
];
|
||||
|
||||
public function provinsi(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Provinsi::class, 'provinsi_id');
|
||||
}
|
||||
|
||||
public function kabupatenKota(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(KabupatenKota::class, 'kabupaten_kota_id');
|
||||
}
|
||||
|
||||
public function kecamatan(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Kecamatan::class, 'kecamatan_id');
|
||||
}
|
||||
|
||||
public function desaKelurahan(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(DesaKelurahan::class, 'desa_kelurahan_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Core;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
use App\Models\Core\KomoditasProgram;
|
||||
use App\Models\Core\LokasiProgram;
|
||||
|
||||
class Program extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'core_program';
|
||||
|
||||
protected $fillable = [
|
||||
"nama",
|
||||
"sub_domain",
|
||||
"tahun",
|
||||
"instansi",
|
||||
];
|
||||
|
||||
public function komoditas(): HasMany
|
||||
{
|
||||
return $this->hasMany(KomoditasProgram::class, 'program_id', 'id');
|
||||
}
|
||||
|
||||
public function lokasi(): HasMany
|
||||
{
|
||||
return $this->hasMany(LokasiProgram::class, 'program_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Ekosistem;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
use App\Models\Ekosistem\TabelBasisData;
|
||||
|
||||
class GroupBasisData extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'ekosistem_basis_data_group';
|
||||
|
||||
protected $fillable = [
|
||||
'group',
|
||||
'label',
|
||||
'urutan',
|
||||
'deskripsi',
|
||||
];
|
||||
|
||||
public function tabel(): HasMany
|
||||
{
|
||||
return $this->hasMany(TabelBasisData::class, 'group_id')->orderBy('urutan');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Ekosistem;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
use App\Models\Ekosistem\TabelBasisData;
|
||||
|
||||
class KolomBasisData extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'ekosistem_basis_data_kolom';
|
||||
|
||||
protected $fillable = [
|
||||
'tabel_id',
|
||||
'kolom',
|
||||
'label',
|
||||
'tipe',
|
||||
'validasi',
|
||||
'urutan',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'validasi' => 'array',
|
||||
];
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
static::creating(function ($model) {
|
||||
$max = self::where('tabel_id', $model->tabel_id)->max('urutan');
|
||||
$model->urutan = ($max ?? 0) + 1;
|
||||
});
|
||||
static::addGlobalScope('order', function (Builder $builder) {
|
||||
$builder->orderBy('urutan');
|
||||
});
|
||||
}
|
||||
|
||||
public function tabel(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(TabelBasisData::class, 'tabel_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Ekosistem;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
use App\Models\Ekosistem\KolomBasisData;
|
||||
|
||||
class TabelBasisData extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'ekosistem_basis_data_tabel';
|
||||
|
||||
protected $fillable = [
|
||||
'tabel',
|
||||
'label',
|
||||
'menu',
|
||||
'deskripsi',
|
||||
'group_id',
|
||||
'urutan'
|
||||
|
||||
];
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
static::creating(function ($model) {
|
||||
$max = self::where('group_id', $model->group_id)->max('urutan');
|
||||
$model->urutan = ($max ?? 0) + 1;
|
||||
});
|
||||
static::addGlobalScope('order', function (Builder $builder) {
|
||||
$builder->orderBy('urutan');
|
||||
});
|
||||
}
|
||||
|
||||
public function kolom(): HasMany
|
||||
{
|
||||
return $this->hasMany(KolomBasisData::class, 'tabel_id')->orderBy('urutan');
|
||||
}
|
||||
|
||||
public function group(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(GroupBasisData::class, 'group_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Ekosistem;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
use App\Models\Ekosistem\TabelBasisData;
|
||||
use App\Models\Ekosistem\KolomBasisData;
|
||||
|
||||
class ValueBasisData extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'ekosistem_basis_data_value';
|
||||
|
||||
protected $fillable = [
|
||||
'program_id',
|
||||
'tabel_id',
|
||||
'kolom_id',
|
||||
'value_id',
|
||||
'value_varchar',
|
||||
'value_integer',
|
||||
'value_float',
|
||||
'value_boolean',
|
||||
'value_date',
|
||||
'value_datetime',
|
||||
'value_text',
|
||||
];
|
||||
|
||||
public function tabel(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(TabelBasisData::class, 'tabel_id');
|
||||
}
|
||||
|
||||
public function kolom(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(KolomBasisData::class, 'kolom_id');
|
||||
}
|
||||
|
||||
public function program(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Program::class, 'program_id');
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ namespace App\Models\Pertanian;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class Komoditas extends Model
|
||||
{
|
||||
@@ -17,4 +18,16 @@ class Komoditas extends Model
|
||||
'updated_by',
|
||||
'deleted_by',
|
||||
];
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
static::addGlobalScope('program', function (Builder $builder) {
|
||||
|
||||
if (!app()->has('SystemProgram')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$builder->whereIn('id', app('SystemProgram')->komoditas()->pluck('id'));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Scopes;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Scope;
|
||||
|
||||
class KomoditasProgramScope implements Scope
|
||||
{
|
||||
/**
|
||||
* Apply the scope to a given Eloquent query builder.
|
||||
*/
|
||||
public function apply(Builder $builder, Model $model): void
|
||||
{
|
||||
if (app()->has('SystemProgram')) {
|
||||
$program = app('SystemProgram');
|
||||
$builder->whereIn('komoditas_id', $program->komoditas()->pluck('id'));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user