Files
backend/app/Models/Camp.php
2024-02-01 09:53:53 +00:00

158 lines
3.8 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Camp extends Model
{
public static function boot()
{
parent::boot();
self::creating(function($model){
});
self::created(function($model){
auth()->user()->addActivityComplete(1047,$model);
});
self::updating(function($model){
auth()->user()->addActivityComplete(1048,$model);
});
self::updated(function($model){
});
self::deleting(function($model){
auth()->user()->addActivityComplete(1049,$model);
});
self::deleted(function($model){
});
}
protected $fillable = [
'block_axis_desc',
'active_rahdar_count',
'active_cars_count',
'is_open',
'is_open_type',
'is_open_type_fa',
'blockage_damage_count',
'blockage_damage_lower_6_count',
'blockage_damage_higher_6_count',
'blockage_damage_money',
'blockage_length',
'blockage_type',
'blockage_type_fa',
'prediction_time',
'prediction_time_fa',
'blockage_cause',
'blockage_cause_fa',
'axis_type',
'axis_type_fa',
'city_1_fa',
'city_2_fa',
'city_3_fa',
'province_fa',
'submited_at',
'is_open_at'
];
protected $casts = [
'cities_id' => 'array',
'start_latlng' => 'array',
'end_latlng' => 'array'
];
public function user()
{
return $this->belongsTo('App\Models\User');
}
public function files()
{
return $this->morphMany('App\Models\ProjectFile', 'project_fileable');
}
public function setAxisTypeFa($axis_type)
{
switch ($axis_type) {
case 1:
$axis_type_fa = 'آزادراه';
break;
case 2:
$axis_type_fa = 'اصلی';
break;
case 3:
$axis_type_fa = 'فرعی';
break;
case 4:
$axis_type_fa = 'روستایی';
break;
case 5:
$axis_type_fa = 'بزرگراه';
break;
}
$this->attributes['axis_type_fa'] = $axis_type_fa;
}
public function setBlockageCauseFa($blockage_cause)
{
switch ($blockage_cause) {
case 1:
$blockage_cause_fa = 'برف';
break;
case 2:
$blockage_cause_fa = 'سیل';
break;
case 3:
$blockage_cause_fa = 'رانش و ریزش';
break;
case 4:
$blockage_cause_fa = 'سایر';
break;
case 5:
$blockage_cause_fa = 'طوفان شن';
break;
}
$this->attributes['blockage_cause_fa'] = $blockage_cause_fa;
}
public function setPredictionTimeFa($prediction_time)
{
switch ($prediction_time) {
case 1:
$prediction_time_fa = 'یک روزه';
break;
case 2:
$prediction_time_fa = 'سه روزه';
break;
case 3:
$prediction_time_fa = 'یک هفته';
break;
case 4:
$prediction_time_fa = 'دو هفته';
break;
case 5:
$prediction_time_fa = 'یک ماه';
break;
case 6:
$prediction_time_fa = 'سه ماه';
break;
case 7:
$prediction_time_fa = 'شش ماه';
break;
case 8:
$prediction_time_fa = 'بیش از شش ماه';
break;
}
$this->attributes['prediction_time_fa'] = $prediction_time_fa;
}
}