fix bugs
This commit is contained in:
@@ -189,51 +189,52 @@ class TaskController extends Controller
|
||||
}
|
||||
public function storeTask(Request $request)
|
||||
{
|
||||
$name = $request->name;
|
||||
$desc = $request->description_html;
|
||||
$priority = $request->priority;
|
||||
$start_date = $request->start_date;
|
||||
$target_date = $request->target_date;
|
||||
$state = $request->state;
|
||||
$assignees = $request->assignees;
|
||||
$parent = $request->parent;
|
||||
$estimate_point = $request->estimate_point;
|
||||
$created_by = User::where('user_name', $_COOKIE['user_identity'])->first()->plain_id;
|
||||
|
||||
// اگر خواستی کاربر ایجاد کننده هم اضافه کنی:
|
||||
// $created_by = User::where('user_name', $_COOKIE['user_identity'])->first()->plain_id;
|
||||
Tasks::create([
|
||||
"name" => $request->name,
|
||||
"desc" => $request->description_html,
|
||||
"priority" => $request->priority,
|
||||
"start_date" => $request->start_date,
|
||||
"target_date" => $request->target_date,
|
||||
"state" => $request->state,
|
||||
"assignees" => $request->assignees,
|
||||
"parent" => $request->parent,
|
||||
"estimate_point" => $request->estimate_point,
|
||||
|
||||
$headers = [
|
||||
'x-api-key' => 'plane_api_ec378e977ceb4bd1bbd2332855370645',
|
||||
'Content-Type' => 'application/json'
|
||||
];
|
||||
]);
|
||||
|
||||
$body = json_encode([
|
||||
"name" => $name,
|
||||
"description_html" => $desc ?: '',
|
||||
"priority" => $priority ?: 'none',
|
||||
"start_date" => $start_date ?: null,
|
||||
"target_date" => $target_date ?: null,
|
||||
"estimate_point" => $estimate_point ?: '',
|
||||
"state" => $state ?: '',
|
||||
"parent" => $parent ?: '',
|
||||
"assignees" => $assignees ?: '',
|
||||
// "labels" => $labels ?: null,
|
||||
// "created_by" => $created_by
|
||||
], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
||||
// $headers = [
|
||||
// 'x-api-key' => 'plane_api_ec378e977ceb4bd1bbd2332855370645',
|
||||
// 'Content-Type' => 'application/json'
|
||||
// ];
|
||||
//
|
||||
// $body = json_encode([
|
||||
// "name" => $name,
|
||||
// "description_html" => $desc ?: '',
|
||||
// "priority" => $priority ?: 'none',
|
||||
// "start_date" => $start_date ?: null,
|
||||
// "target_date" => $target_date ?: null,
|
||||
// "estimate_point" => $estimate_point ?: '',
|
||||
// "state" => $state ?: '',
|
||||
// "parent" => $parent ?: '',
|
||||
// "assignees" => $assignees ?: '',
|
||||
// // "labels" => $labels ?: null,
|
||||
// // "created_by" => $created_by
|
||||
// ], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
||||
//
|
||||
// $client = new Client();
|
||||
//
|
||||
// $response = $client->post(
|
||||
// 'https://api.plane.so/api/v1/workspaces/montzar/projects/c1df4085-582f-4b57-b3c6-95b7d4d19007/issues/',
|
||||
// [
|
||||
// 'headers' => $headers,
|
||||
// 'body' => $body,
|
||||
// ]
|
||||
// );
|
||||
//
|
||||
// $data = json_decode($response->getBody(), true);
|
||||
|
||||
$client = new Client();
|
||||
|
||||
$response = $client->post(
|
||||
'https://api.plane.so/api/v1/workspaces/montzar/projects/c1df4085-582f-4b57-b3c6-95b7d4d19007/issues/',
|
||||
[
|
||||
'headers' => $headers,
|
||||
'body' => $body,
|
||||
]
|
||||
);
|
||||
|
||||
$data = json_decode($response->getBody(), true);
|
||||
|
||||
// اگر میخوای بعدا داده رو ذخیره یا آپدیت کنی، میتونی اینجا صدا بزنی:
|
||||
// update_tasks($data);
|
||||
|
||||
return back()->with('message', [
|
||||
@@ -242,29 +243,29 @@ class TaskController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
public function webhookPlane(Request $request)
|
||||
{
|
||||
$d = $request->all();
|
||||
|
||||
// فقط وقتی تغییر state هست
|
||||
if (isset($d['event'], $d['action'], $d['data']['name'], $d['data']['state']['name'])) {
|
||||
$msg = "Event: {$d['event']}\nAction: {$d['action']}\nName: {$d['data']['name']}\nNew Status: {$d['data']['state']['name']}";
|
||||
|
||||
// ارسال به تلگرام
|
||||
Http::get("https://api.wwwapp.ir/telegran_send.php", [
|
||||
'botToken' => "7467099619:AAF2V6yYcbAb8oSIRSCyH5i2GKfdWVO3a7k",
|
||||
'chatId' => "-4742642674",
|
||||
'message' => $msg,
|
||||
]);
|
||||
}
|
||||
|
||||
// اگر خواستی ثبت در دیتابیس هم اضافه کنی
|
||||
// DB::table('tst')->insert([
|
||||
// 'data' => json_encode($d, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE),
|
||||
// ]);
|
||||
|
||||
return response()->json(['status' => 'ok'], 200);
|
||||
}
|
||||
// public function webhookPlane(Request $request)
|
||||
// {
|
||||
// $d = $request->all();
|
||||
//
|
||||
// // فقط وقتی تغییر state هست
|
||||
// if (isset($d['event'], $d['action'], $d['data']['name'], $d['data']['state']['name'])) {
|
||||
// $msg = "Event: {$d['event']}\nAction: {$d['action']}\nName: {$d['data']['name']}\nNew Status: {$d['data']['state']['name']}";
|
||||
//
|
||||
// // ارسال به تلگرام
|
||||
// Http::get("https://api.wwwapp.ir/telegran_send.php", [
|
||||
// 'botToken' => "7467099619:AAF2V6yYcbAb8oSIRSCyH5i2GKfdWVO3a7k",
|
||||
// 'chatId' => "-4742642674",
|
||||
// 'message' => $msg,
|
||||
// ]);
|
||||
// }
|
||||
//
|
||||
// // اگر خواستی ثبت در دیتابیس هم اضافه کنی
|
||||
// // DB::table('tst')->insert([
|
||||
// // 'data' => json_encode($d, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE),
|
||||
// // ]);
|
||||
//
|
||||
// return response()->json(['status' => 'ok'], 200);
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
||||
+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