89 lines
2.0 KiB
PHP
89 lines
2.0 KiB
PHP
<?php
|
|||
|
|
|
||
|
|
namespace App\Models;
|
||
|
|
|
||
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||
|
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||
|
|
|
||
|
|
class Task extends Model
|
||
|
|
{
|
||
|
|
use HasFactory, SoftDeletes;
|
||
|
|
|
||
|
|
public const STATUSES = ['todo', 'in_progress', 'done', 'blocked', 'waiting_review'];
|
||
|
|
|
||
|
|
protected $fillable = [
|
||
|
|
'title',
|
||
|
|
'description',
|
||
|
|
'status',
|
||
|
|
'project_id',
|
||
|
|
'priority',
|
||
|
|
'due_at',
|
||
|
|
'started_at',
|
||
|
|
'completed_at',
|
||
|
|
'estimated_hours',
|
||
|
|
'actual_hours',
|
||
|
|
];
|
||
|
|
|
||
|
|
protected $casts = [
|
||
|
|
'due_at' => 'datetime',
|
||
|
|
'started_at' => 'datetime',
|
||
|
|
'completed_at' => 'datetime',
|
||
|
|
];
|
||
|
|
|
||
|
|
public function project(): BelongsTo
|
||
|
|
{
|
||
|
|
return $this->belongsTo(Project::class);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function comments(): HasMany
|
||
|
|
{
|
||
|
|
return $this->hasMany(TaskComment::class)->orderBy('created_at');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function scopeByStatus($query, string $status)
|
||
|
|
{
|
||
|
|
return $query->where('status', $status);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function scopeTodo($query)
|
||
|
|
{
|
||
|
|
return $query->where('status', 'todo');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function scopeInProgress($query)
|
||
|
|
{
|
||
|
|
return $query->where('status', 'in_progress');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function scopeDone($query)
|
||
|
|
{
|
||
|
|
return $query->where('status', 'done');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function scopeBlocked($query)
|
||
|
|
{
|
||
|
|
return $query->where('status', 'blocked');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function scopeWaitingReview($query)
|
||
|
|
{
|
||
|
|
return $query->where('status', 'waiting_review');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function scopeDueSoon($query, int $days = 3)
|
||
|
|
{
|
||
|
|
return $query->where('due_at', '>=', now())
|
||
|
|
->where('due_at', '<=', now()->addDays($days))
|
||
|
|
->where('status', '!=', 'done');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function scopeOverdue($query)
|
||
|
|
{
|
||
|
|
return $query->where('due_at', '<', now())
|
||
|
|
->where('status', '!=', 'done');
|
||
|
|
}
|
||
|
|
}
|