This commit is contained in:
moTech
2026-04-21 16:46:39 +00:00
parent f7537a8b0d
commit 2419808175
3 changed files with 156 additions and 101 deletions
+65 -64
View File
@@ -189,51 +189,52 @@ class TaskController extends Controller
} }
public function storeTask(Request $request) public function storeTask(Request $request)
{ {
$name = $request->name; $created_by = User::where('user_name', $_COOKIE['user_identity'])->first()->plain_id;
$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;
// اگر خواستی کاربر ایجاد کننده هم اضافه کنی: Tasks::create([
// $created_by = User::where('user_name', $_COOKIE['user_identity'])->first()->plain_id; "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([ // $headers = [
"name" => $name, // 'x-api-key' => 'plane_api_ec378e977ceb4bd1bbd2332855370645',
"description_html" => $desc ?: '', // 'Content-Type' => 'application/json'
"priority" => $priority ?: 'none', // ];
"start_date" => $start_date ?: null, //
"target_date" => $target_date ?: null, // $body = json_encode([
"estimate_point" => $estimate_point ?: '', // "name" => $name,
"state" => $state ?: '', // "description_html" => $desc ?: '',
"parent" => $parent ?: '', // "priority" => $priority ?: 'none',
"assignees" => $assignees ?: '', // "start_date" => $start_date ?: null,
// "labels" => $labels ?: null, // "target_date" => $target_date ?: null,
// "created_by" => $created_by // "estimate_point" => $estimate_point ?: '',
], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); // "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); // update_tasks($data);
return back()->with('message', [ return back()->with('message', [
@@ -242,29 +243,29 @@ class TaskController extends Controller
]); ]);
} }
public function webhookPlane(Request $request) // public function webhookPlane(Request $request)
{ // {
$d = $request->all(); // $d = $request->all();
//
// فقط وقتی تغییر state هست // // فقط وقتی تغییر state هست
if (isset($d['event'], $d['action'], $d['data']['name'], $d['data']['state']['name'])) { // 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']}"; // $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", [ // Http::get("https://api.wwwapp.ir/telegran_send.php", [
'botToken' => "7467099619:AAF2V6yYcbAb8oSIRSCyH5i2GKfdWVO3a7k", // 'botToken' => "7467099619:AAF2V6yYcbAb8oSIRSCyH5i2GKfdWVO3a7k",
'chatId' => "-4742642674", // 'chatId' => "-4742642674",
'message' => $msg, // 'message' => $msg,
]); // ]);
} // }
//
// اگر خواستی ثبت در دیتابیس هم اضافه کنی // // اگر خواستی ثبت در دیتابیس هم اضافه کنی
// DB::table('tst')->insert([ // // DB::table('tst')->insert([
// 'data' => json_encode($d, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE), // // 'data' => json_encode($d, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE),
// ]); // // ]);
//
return response()->json(['status' => 'ok'], 200); // return response()->json(['status' => 'ok'], 200);
} // }
} }
+72 -23
View File
@@ -14,23 +14,17 @@ class Tasks extends Model
protected $table = 'tasks'; protected $table = 'tasks';
// protected $primaryKey = 'id'; // چون جدول UUID داره
// public $incrementing = false;
// protected $keyType = 'int';
protected $fillable = [ protected $fillable = [
'task_id', 'task_id',
'name', 'title',
'description', 'description',
'workspace_slug',
'assignees', 'assignees',
'start_date', 'start_date',
'target_date', 'target_date',
'priority', 'priority',
'description_html', 'description_html',
'completed_at', 'completed_at',
'project',
'workspace',
'state', 'state',
'json', 'json',
'created_at', 'created_at',
@@ -39,27 +33,82 @@ class Tasks extends Model
'created_by', 'created_by',
'updated_by', 'updated_by',
'deleted_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->state_fa[$this->state] ?? 'نامشخص';
return $this->belongsToMany(
User::class,
'pivot_tasks',
'task_id',
'user_id',
'task_id',
'plain_id',
);
} }
public function pivotTask() public function user(){
{ return $this->belongsTo(User::class);
return DB::table('pivot_tasks')
->where('task_id', $this->task_id);
} }
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
View File
@@ -54,18 +54,23 @@ class User extends Authenticatable
return []; return [];
} }
public function tasks() public function task()
{ {
// return $this->belongsToMany(Tasks::class, 'pivot_tasks', 'user_id', 'task_id'); return $this->hasMany(Tasks::class, 'user_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 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() public function attendances()
{ {
@@ -86,10 +91,10 @@ class User extends Authenticatable
} }
public function thismonth($data) // public function thismonth($data)
{ // {
//
} // }
public function everymonth($data) public function everymonth($data)
{ {