2026-05-07 23:31:33 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2026-06-16 18:05:53 +02:00
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
|
use App\Traits\LogsActivity;
|
2026-05-07 23:31:33 +02:00
|
|
|
|
|
|
|
|
class Feature extends Model
|
|
|
|
|
{
|
2026-06-16 18:05:53 +02:00
|
|
|
use SoftDeletes, LogsActivity;
|
|
|
|
|
|
|
|
|
|
const STATUSES = ['planned', 'started', 'in_progress', 'completed', 'verified'];
|
|
|
|
|
|
2026-05-07 23:31:33 +02:00
|
|
|
protected $fillable = [
|
2026-06-16 18:05:53 +02:00
|
|
|
'layer_id', 'name', 'geometry', 'properties', 'template_id',
|
|
|
|
|
'progress', 'status', 'responsible', 'responsible_user_id',
|
2026-05-07 23:31:33 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected $casts = [
|
2026-06-16 18:05:53 +02:00
|
|
|
'geometry' => 'array',
|
2026-05-07 23:31:33 +02:00
|
|
|
'properties' => 'array',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
public function layer()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Layer::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function template()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(InspectionTemplate::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function inspections()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(Inspection::class, 'feature_id');
|
|
|
|
|
}
|
2026-05-09 22:28:20 +02:00
|
|
|
|
2026-06-16 18:05:53 +02:00
|
|
|
public function issues()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(Issue::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function responsibleUser()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(User::class, 'responsible_user_id');
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-09 22:28:20 +02:00
|
|
|
public function media()
|
|
|
|
|
{
|
|
|
|
|
return $this->morphMany(Media::class, 'mediable');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function images()
|
|
|
|
|
{
|
|
|
|
|
return $this->morphMany(Media::class, 'mediable')->where('category', 'image');
|
|
|
|
|
}
|
2026-06-16 18:05:53 +02:00
|
|
|
|
|
|
|
|
public function getStatusColorAttribute(): string
|
|
|
|
|
{
|
|
|
|
|
return match($this->status) {
|
|
|
|
|
'planned' => '#6b7280',
|
|
|
|
|
'started' => '#3b82f6',
|
|
|
|
|
'in_progress' => '#f59e0b',
|
|
|
|
|
'completed' => '#10b981',
|
|
|
|
|
'verified' => '#8b5cf6',
|
|
|
|
|
default => '#6b7280',
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|