first change
This commit is contained in:
117
Modules/PMS/app/Models/Task.php
Normal file
117
Modules/PMS/app/Models/Task.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\PMS\Models;
|
||||
|
||||
use App\Models\Document;
|
||||
use App\Traits\CreatedUpdatedBy;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
use Modules\Employee\Models\Employee;
|
||||
use Modules\Product\Models\Product;
|
||||
|
||||
class Task extends Model
|
||||
{
|
||||
use CreatedUpdatedBy;
|
||||
use \Staudenmeir\EloquentJsonRelations\HasJsonRelationships;
|
||||
|
||||
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',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'assigned_id' => 'json',
|
||||
];
|
||||
|
||||
protected function statusName(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: function (mixed $value, array $attributes) {
|
||||
$kanbanColumn = KanbanColumn::where('id',$attributes['status'])->first();
|
||||
return collect([
|
||||
'status' => $kanbanColumn->name ?? 'N/A',
|
||||
'color' => $kanbanColumn->name ?? '#808080'
|
||||
]);
|
||||
},
|
||||
|
||||
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>';
|
||||
case '11':
|
||||
return '<span class="badge bg-info">' . self::PRIORITY[$attributes['priority']] . '</span>';
|
||||
case '12':
|
||||
return '<span class="badge bg-primary">' . self::PRIORITY[$attributes['priority']] . '</span>';
|
||||
default:
|
||||
# code...
|
||||
break;
|
||||
}
|
||||
},
|
||||
set: fn($value) => $value,
|
||||
);
|
||||
}
|
||||
|
||||
public function product()
|
||||
{
|
||||
return $this->belongsTo(Product::class, 'product_id');
|
||||
}
|
||||
|
||||
public function subTask()
|
||||
{
|
||||
return $this->hasMany(Task::class, 'parent_id');
|
||||
}
|
||||
|
||||
public function taskTime()
|
||||
{
|
||||
return $this->hasMany(TaskTime::class, 'task_id');
|
||||
}
|
||||
|
||||
public function latest_task_time()
|
||||
{
|
||||
return $this->hasOne(TaskTime::class, 'task_id')->latestOfMany();
|
||||
}
|
||||
|
||||
public function assignedUser()
|
||||
{
|
||||
return $this->belongsToJson(Employee::class, 'assigned_id->ids');
|
||||
}
|
||||
|
||||
public function taskCategory()
|
||||
{
|
||||
return $this->belongsTo(TaskCategory::class, 'task_category_id');
|
||||
}
|
||||
|
||||
public function documents(): MorphMany
|
||||
{
|
||||
return $this->morphMany(Document::class, 'documentable');
|
||||
}
|
||||
|
||||
public function comments()
|
||||
{
|
||||
return $this->morphMany(Comment::class, 'commentable');
|
||||
}
|
||||
|
||||
public function column()
|
||||
{
|
||||
return $this->belongsTo(KanbanColumn::class, 'status');
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user