100 lines
2.6 KiB
PHP
100 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Spatie\Activitylog\LogOptions;
|
|
use Spatie\Activitylog\Traits\LogsActivity;
|
|
|
|
class IssueManagement extends Model
|
|
{
|
|
use LogsActivity, SoftDeletes;
|
|
|
|
protected $table = 'issue_managements';
|
|
|
|
protected $fillable = [
|
|
'location_id',
|
|
'sub_location_id',
|
|
'classification_id',
|
|
'sub_classification_id',
|
|
'media_monitoring_id',
|
|
'issue',
|
|
'response',
|
|
'description',
|
|
'enhancer_id',
|
|
];
|
|
|
|
public function location()
|
|
{
|
|
return $this->belongsTo(Location::class, 'location_id', 'id');
|
|
}
|
|
|
|
public function subLocation()
|
|
{
|
|
return $this->belongsTo(SubLocation::class, 'sub_location_id', 'id');
|
|
}
|
|
|
|
public function classification()
|
|
{
|
|
return $this->belongsTo(Classification::class, 'classification_id', 'id');
|
|
}
|
|
|
|
public function subClassification()
|
|
{
|
|
return $this->belongsTo(SubClassification::class, 'sub_classification_id', 'id');
|
|
}
|
|
|
|
public function mediaMonitoring()
|
|
{
|
|
return $this->belongsTo(MediaMonitoring::class, 'media_monitoring_id', 'id');
|
|
}
|
|
|
|
public function governmentAgencies()
|
|
{
|
|
return $this->belongsToMany(GovernmentAgency::class, 'issue_managements_government_agencies', 'issue_management_id', 'government_agency_id')
|
|
->using(IssueManagementGovernmentAgency::class)
|
|
->withTimestamps();
|
|
}
|
|
|
|
public function enhancer()
|
|
{
|
|
return $this->belongsTo(User::class, 'enhancer_id', 'id');
|
|
}
|
|
|
|
public function getActivitylogOptions(): LogOptions
|
|
{
|
|
return LogOptions::defaults()
|
|
->logOnly([
|
|
'location_id',
|
|
'sub_location_id',
|
|
'classification_id',
|
|
'sub_classification_id',
|
|
'media_monitoring_id',
|
|
'issue',
|
|
'response',
|
|
'description',
|
|
'enhancer_id',
|
|
]) // kolom yang dicatat
|
|
->useLogName('issue_management') // nama log
|
|
->logOnlyDirty(); // hanya log kalau ada perubahan
|
|
}
|
|
|
|
public function getDescriptionForEvent(string $eventName): string
|
|
{
|
|
switch ($eventName) {
|
|
case 'created':
|
|
$eventName = 'dibuat';
|
|
break;
|
|
case 'updated':
|
|
$eventName = 'diubah';
|
|
break;
|
|
case 'deleted':
|
|
$eventName = 'dihapus';
|
|
break;
|
|
}
|
|
|
|
return "Manajemen Isu telah {$eventName}";
|
|
}
|
|
}
|