Laravel 13 + Livewire/Volt app for managing client organizations, documents, passwords, flexible assets, virtual machines, contacts, domains, todos, shortcuts, and role-based user administration.
86 lines
1.9 KiB
PHP
86 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Contracts\Linkable;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
#[Fillable([
|
|
'organization_id', 'title', 'description', 'category', 'criticality',
|
|
'due_date', 'assigned_to', 'is_done', 'completed_at', 'created_by',
|
|
])]
|
|
class Todo extends Model implements Linkable
|
|
{
|
|
use SoftDeletes;
|
|
|
|
const CATEGORIES = [
|
|
'infra' => 'Infra',
|
|
'support' => 'Support',
|
|
'metier' => 'Métier',
|
|
'autre' => 'Autre',
|
|
];
|
|
|
|
const CRITICALITIES = [
|
|
'low' => 'Basse',
|
|
'medium' => 'Moyenne',
|
|
'high' => 'Haute',
|
|
'urgent' => 'Urgente',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'due_date' => 'date',
|
|
'is_done' => 'boolean',
|
|
'completed_at' => 'datetime',
|
|
];
|
|
}
|
|
|
|
public function organization()
|
|
{
|
|
return $this->belongsTo(Organization::class);
|
|
}
|
|
|
|
public function assignee()
|
|
{
|
|
return $this->belongsTo(User::class, 'assigned_to');
|
|
}
|
|
|
|
public function creator()
|
|
{
|
|
return $this->belongsTo(User::class, 'created_by');
|
|
}
|
|
|
|
public function categoryLabel(): string
|
|
{
|
|
return self::CATEGORIES[$this->category] ?? $this->category;
|
|
}
|
|
|
|
public function criticalityLabel(): string
|
|
{
|
|
return self::CRITICALITIES[$this->criticality] ?? $this->criticality;
|
|
}
|
|
|
|
public function isOverdue(): bool
|
|
{
|
|
return ! $this->is_done && $this->due_date && $this->due_date->isPast();
|
|
}
|
|
|
|
public function linkableKind(): string
|
|
{
|
|
return 'Todo';
|
|
}
|
|
|
|
public function linkableLabel(): string
|
|
{
|
|
return $this->title;
|
|
}
|
|
|
|
public function linkableUrl(): string
|
|
{
|
|
return route('organizations.todos.edit', [$this->organization_id, $this]);
|
|
}
|
|
}
|