115 lines
2.5 KiB
PHP
115 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Console\View\Components\Task;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
class Tasks extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'tasks';
|
|
|
|
|
|
protected $fillable = [
|
|
'task_id',
|
|
'title',
|
|
'description',
|
|
'assignees',
|
|
'start_date',
|
|
'target_date',
|
|
'priority',
|
|
'description_html',
|
|
'completed_at',
|
|
'state',
|
|
'json',
|
|
'created_at',
|
|
'updated_at',
|
|
'deleted_at',
|
|
'created_by',
|
|
'updated_by',
|
|
'deleted_by',
|
|
'id',
|
|
'app',
|
|
'task_type',
|
|
'user_id',
|
|
];
|
|
|
|
protected $STATE = [
|
|
1=>'Backlog',
|
|
2=>'To Do',
|
|
3=>'In Progress',
|
|
4=>'Done',
|
|
];
|
|
protected $state_fa = [
|
|
1=>'انباشته',
|
|
2=>'برای انجام',
|
|
3=>'درحال انجام',
|
|
4=>'پایان یافته',
|
|
];
|
|
|
|
public function getStateFaAttribute()
|
|
{
|
|
return $this->state_fa[$this->state] ?? 'نامشخص';
|
|
}
|
|
|
|
public function user(){
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function app(){
|
|
return $this->belogsTo(App::class);
|
|
}
|
|
|
|
public function filterByState($tasks){
|
|
$backlog = [];
|
|
$todo = [];
|
|
$inprogress = [];
|
|
$done = [];
|
|
foreach($tasks as $task){
|
|
if($task->state == 1){
|
|
$backlog[] = $task;
|
|
}elseif ($task->state == 2){
|
|
$todo[] = $task;
|
|
}elseif ($task->state == 3){
|
|
$inprogress[] = $task;
|
|
}elseif ($task->state == 4){
|
|
$done[] = $task;
|
|
}
|
|
}
|
|
$tasks = [
|
|
'backlog' => $backlog,
|
|
'todo' => $todo,
|
|
'inprogress' => $inprogress,
|
|
'done' => $done,
|
|
'count' => count($tasks),
|
|
];
|
|
return $tasks;
|
|
}
|
|
|
|
|
|
// public function users()
|
|
// {
|
|
//// return $this->belongsToMany(User::class, 'pivot_tasks', 'task_id', 'user_id');
|
|
// return $this->belongsToMany(
|
|
// User::class,
|
|
// 'pivot_tasks',
|
|
// 'task_id',
|
|
// 'user_id',
|
|
// 'task_id',
|
|
// 'plain_id',
|
|
// );
|
|
// }
|
|
|
|
// public function pivotTask()
|
|
// {
|
|
// return DB::table('pivot_tasks')
|
|
// ->where('task_id', $this->task_id);
|
|
// }
|
|
|
|
}
|