fix bugs
This commit is contained in:
+72
-23
@@ -14,23 +14,17 @@ class Tasks extends Model
|
||||
|
||||
protected $table = 'tasks';
|
||||
|
||||
// protected $primaryKey = 'id'; // چون جدول UUID داره
|
||||
// public $incrementing = false;
|
||||
// protected $keyType = 'int';
|
||||
|
||||
protected $fillable = [
|
||||
'task_id',
|
||||
'name',
|
||||
'title',
|
||||
'description',
|
||||
'workspace_slug',
|
||||
'assignees',
|
||||
'start_date',
|
||||
'target_date',
|
||||
'priority',
|
||||
'description_html',
|
||||
'completed_at',
|
||||
'project',
|
||||
'workspace',
|
||||
'state',
|
||||
'json',
|
||||
'created_at',
|
||||
@@ -39,27 +33,82 @@ class Tasks extends Model
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'deleted_by',
|
||||
'parent',
|
||||
|
||||
'id',
|
||||
'app',
|
||||
'task_type',
|
||||
'user_id',
|
||||
];
|
||||
|
||||
public function users()
|
||||
protected $STATE = [
|
||||
1=>'Backlog',
|
||||
2=>'To Do',
|
||||
3=>'In Progress',
|
||||
4=>'Done',
|
||||
];
|
||||
protected $state_fa = [
|
||||
1=>'انباشته',
|
||||
2=>'برای انجام',
|
||||
3=>'درحال انجام',
|
||||
4=>'پایان یافته',
|
||||
];
|
||||
|
||||
public function getStateFaAttribute()
|
||||
{
|
||||
// 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',
|
||||
);
|
||||
return $this->state_fa[$this->state] ?? 'نامشخص';
|
||||
}
|
||||
|
||||
public function pivotTask()
|
||||
{
|
||||
return DB::table('pivot_tasks')
|
||||
->where('task_id', $this->task_id);
|
||||
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);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
+19
-14
@@ -54,18 +54,23 @@ class User extends Authenticatable
|
||||
return [];
|
||||
}
|
||||
|
||||
public function tasks()
|
||||
public function task()
|
||||
{
|
||||
// return $this->belongsToMany(Tasks::class, 'pivot_tasks', 'user_id', 'task_id');
|
||||
return $this->belongsToMany(
|
||||
Tasks::class, // مدل مقصد
|
||||
'pivot_tasks', // جدول واسط
|
||||
'user_id', // ستون جدول واسط که به جدول users اشاره میکنه
|
||||
'task_id', // ستون جدول واسط که به جدول tasks اشاره میکنه
|
||||
'plain_id', // ستون جدول users که ستون جدول واسط بهش اشاره میکنه (local key)
|
||||
'task_id' // ستون جدول tasks که ستون جدول واسط بهش اشاره میکنه (related key)
|
||||
)->withPivot(['id', 'started_at','ended_at','duration',]);
|
||||
return $this->hasMany(Tasks::class, 'user_id');
|
||||
|
||||
}
|
||||
// public function tasks()
|
||||
// {
|
||||
//// return $this->belongsToMany(Tasks::class, 'pivot_tasks', 'user_id', 'task_id');
|
||||
// return $this->belongsToMany(
|
||||
// Tasks::class, // مدل مقصد
|
||||
// 'pivot_tasks', // جدول واسط
|
||||
// 'user_id', // ستون جدول واسط که به جدول users اشاره میکنه
|
||||
// 'task_id', // ستون جدول واسط که به جدول tasks اشاره میکنه
|
||||
// 'plain_id', // ستون جدول users که ستون جدول واسط بهش اشاره میکنه (local key)
|
||||
// 'task_id' // ستون جدول tasks که ستون جدول واسط بهش اشاره میکنه (related key)
|
||||
// )->withPivot(['id', 'started_at','ended_at','duration',]);
|
||||
// }
|
||||
|
||||
public function attendances()
|
||||
{
|
||||
@@ -86,10 +91,10 @@ class User extends Authenticatable
|
||||
}
|
||||
|
||||
|
||||
public function thismonth($data)
|
||||
{
|
||||
|
||||
}
|
||||
// public function thismonth($data)
|
||||
// {
|
||||
//
|
||||
// }
|
||||
|
||||
public function everymonth($data)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user