56 lines
1.8 KiB
PHP
56 lines
1.8 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Models;
|
||
|
|
|
||
|
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||
|
|
use App\Traits\LogsActivity;
|
||
|
|
|
||
|
|
class Issue extends Model
|
||
|
|
{
|
||
|
|
use SoftDeletes, LogsActivity;
|
||
|
|
|
||
|
|
const STATUSES = ['open', 'in_review', 'resolved', 'closed'];
|
||
|
|
const PRIORITIES = ['low', 'medium', 'high', 'critical'];
|
||
|
|
|
||
|
|
protected $fillable = [
|
||
|
|
'project_id', 'feature_id', 'inspection_id',
|
||
|
|
'title', 'description', 'status', 'priority',
|
||
|
|
'reported_by', 'assigned_to', 'resolved_at', 'resolution_notes'
|
||
|
|
];
|
||
|
|
|
||
|
|
protected $casts = ['resolved_at' => 'datetime'];
|
||
|
|
|
||
|
|
public function project() { return $this->belongsTo(Project::class); }
|
||
|
|
public function feature() { return $this->belongsTo(Feature::class); }
|
||
|
|
public function inspection() { return $this->belongsTo(Inspection::class); }
|
||
|
|
public function reporter() { return $this->belongsTo(User::class, 'reported_by'); }
|
||
|
|
public function assignee() { return $this->belongsTo(User::class, 'assigned_to'); }
|
||
|
|
public function media() { return $this->morphMany(Media::class, 'mediable'); }
|
||
|
|
|
||
|
|
public function scopeOpen($q) { return $q->where('status', 'open'); }
|
||
|
|
public function scopeCritical($q) { return $q->where('priority', 'critical'); }
|
||
|
|
|
||
|
|
public function getPriorityColorAttribute(): string
|
||
|
|
{
|
||
|
|
return match($this->priority) {
|
||
|
|
'low' => '#6b7280',
|
||
|
|
'medium' => '#f59e0b',
|
||
|
|
'high' => '#ef4444',
|
||
|
|
'critical' => '#7c3aed',
|
||
|
|
default => '#6b7280',
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
public function getStatusColorAttribute(): string
|
||
|
|
{
|
||
|
|
return match($this->status) {
|
||
|
|
'open' => '#ef4444',
|
||
|
|
'in_review' => '#f59e0b',
|
||
|
|
'resolved' => '#10b981',
|
||
|
|
'closed' => '#6b7280',
|
||
|
|
default => '#6b7280',
|
||
|
|
};
|
||
|
|
}
|
||
|
|
}
|