Files
a.montask/app/Models/Tasks.php
T

131 lines
3.0 KiB
PHP
Raw Normal View History

2025-10-11 13:38:30 +00:00
<?php
namespace App\Models;
2026-04-08 07:22:13 +00:00
use Illuminate\Console\View\Components\Task;
2025-10-11 13:38:30 +00:00
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
2026-04-08 07:22:13 +00:00
use Illuminate\Support\Facades\DB;
2026-04-23 14:00:39 +03:30
use Illuminate\Database\Eloquent\SoftDeletes;
2026-04-08 07:22:13 +00:00
2025-10-11 13:38:30 +00:00
class Tasks extends Model
{
2026-04-23 14:00:39 +03:30
use HasFactory,SoftDeletes;
2025-10-11 13:38:30 +00:00
protected $table = 'tasks';
protected $fillable = [
'task_id',
2026-04-21 16:46:39 +00:00
'title',
2025-10-11 13:38:30 +00:00
'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',
2026-04-21 16:46:39 +00:00
'id',
'app',
'task_type',
'user_id',
2025-10-11 13:38:30 +00:00
];
2026-04-21 16:46:39 +00:00
protected $STATE = [
1=>'Backlog',
2=>'To Do',
3=>'In Progress',
4=>'Done',
];
protected $state_fa = [
1=>'انباشته',
2=>'برای انجام',
3=>'درحال انجام',
4=>'پایان یافته',
];
public function getStateFaAttribute()
2025-10-11 13:38:30 +00:00
{
2026-04-21 16:46:39 +00:00
return $this->state_fa[$this->state] ?? 'نامشخص';
2025-10-11 13:38:30 +00:00
}
2026-04-08 07:22:13 +00:00
2026-04-21 16:46:39 +00:00
public function user(){
return $this->belongsTo(User::class);
2026-04-08 07:22:13 +00:00
}
2026-04-21 16:46:39 +00:00
public function app(){
return $this->belogsTo(App::class);
}
2026-04-23 14:00:39 +03:30
public function duration(){
return $this->hasMany(TaskDuration::class, 'task_id', 'id');
}
public function comments()
{
return $this->hasMany(TaskComment::class, 'task_id', 'id')->orderBy('id', 'desc');
}
public function userDurations($userId = null)
{
$userId = $userId ?: User::where('user_name', $_COOKIE['user_identity'])->first()->id; // پیش‌فرض: کاربر جاری
return $this->taskDurations()->where('user_id', $userId);
}
2026-04-21 16:46:39 +00:00
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,
2026-04-23 14:00:39 +03:30
// 'count' => count($tasks),
2026-04-21 16:46:39 +00:00
];
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);
// }
2025-10-11 13:38:30 +00:00
}