113 lines
3.0 KiB
PHP
113 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace Modules\PMS\Models;
|
|
|
|
use App\Traits\CreatedUpdatedBy;
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Modules\Employee\Models\Employee;
|
|
|
|
class Task extends Model
|
|
{
|
|
use CreatedUpdatedBy;
|
|
|
|
protected $table = 'tbl_tasks';
|
|
protected $guarded = [];
|
|
protected $appends = ['status_name', 'priority_status'];
|
|
|
|
const CATEGORY = [
|
|
10 => 'Vue',
|
|
11 => 'Laravel',
|
|
];
|
|
|
|
const PRIORITY = [
|
|
10 => 'High',
|
|
11 => 'Meduim',
|
|
12 => 'Low',
|
|
];
|
|
|
|
const STATUS = [
|
|
10 => 'Incomplete',
|
|
11 => 'To DO',
|
|
12 => 'Doing',
|
|
13 => 'In Review',
|
|
14 => 'Completed',
|
|
];
|
|
|
|
protected $casts = [
|
|
'assigned_id' => 'array',
|
|
];
|
|
|
|
protected function statusName(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: function (mixed $value, array $attributes) {
|
|
switch ($attributes['status']) {
|
|
case '10':
|
|
$color = 'danger';
|
|
break;
|
|
case '11':
|
|
$color = 'info';
|
|
break;
|
|
case '12':
|
|
$color = 'primary';
|
|
break;
|
|
case '13':
|
|
$color = 'warning';
|
|
break;
|
|
case '14':
|
|
$color = 'success';
|
|
break;
|
|
default:
|
|
$color = 'light';
|
|
break;
|
|
}
|
|
|
|
return collect([
|
|
'status' => self::STATUS[$attributes['status']],
|
|
'color' => $color]);
|
|
},
|
|
set: fn($value) => $value,
|
|
);
|
|
}
|
|
|
|
protected function priorityStatus(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: function (mixed $value, array $attributes) {
|
|
switch ($attributes['priority']) {
|
|
case '10':
|
|
return '<span class="badge bg-danger">' . self::PRIORITY[$attributes['priority']] . '</span>';
|
|
break;
|
|
case '11':
|
|
return '<span class="badge bg-info">' . self::PRIORITY[$attributes['priority']] . '</span>';
|
|
break;
|
|
case '12':
|
|
return '<span class="badge bg-primary">' . self::PRIORITY[$attributes['priority']] . '</span>';
|
|
break;
|
|
default:
|
|
# code...
|
|
break;
|
|
}
|
|
},
|
|
set: fn($value) => $value,
|
|
);
|
|
}
|
|
|
|
public function project()
|
|
{
|
|
return $this->belongsTo(Project::class, 'project_id');
|
|
}
|
|
|
|
public function assigned()
|
|
{
|
|
return $this->belongsTo(Employee::class, 'assigned_id');
|
|
}
|
|
|
|
public function taskCategory()
|
|
{
|
|
return self::CATEGORY[$this->task_category_id ?? null];
|
|
}
|
|
|
|
}
|