-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskController.php
More file actions
92 lines (78 loc) · 2.58 KB
/
Copy pathTaskController.php
File metadata and controls
92 lines (78 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
namespace App\Controllers;
use App\Core\Session;
use App\Repositories\TaskRepository;
use App\Repositories\UserRepository;
class TaskController
{
private TaskRepository $taskRepo;
private UserRepository $userRepo;
public function __construct()
{
$this->taskRepo = new TaskRepository();
$this->userRepo = new UserRepository();
}
/**
* Get all tasks for current user
*/
public function getMyTasks(): array
{
$userId = Session::getUserId();
return $this->taskRepo->getTasksByUser($userId);
}
/**
* Get tasks by status
*/
public function getTasksByStatus(string $status): array
{
$userId = Session::getUserId();
return $this->taskRepo->getTasksByUserAndStatus($userId, $status);
}
/**
* Get task statistics
*/
public function getStatistics(): array
{
$userId = Session::getUserId();
$todo = count($this->taskRepo->getTasksByUserAndStatus($userId, 'todo'));
$inProgress = count($this->taskRepo->getTasksByUserAndStatus($userId, 'in_progress'));
$review = count($this->taskRepo->getTasksByUserAndStatus($userId, 'review'));
$done = count($this->taskRepo->getTasksByUserAndStatus($userId, 'done'));
$total = $todo + $inProgress + $review + $done;
$completion = $total > 0 ? round(($done / $total) * 100, 1) : 0;
return [
'todo' => $todo,
'in_progress' => $inProgress,
'review' => $review,
'done' => $done,
'total' => $total,
'completion_rate' => $completion
];
}
/**
* Update task status
*/
public function updateStatus(int $taskId, string $newStatus): bool
{
// Validate status
$validStatuses = ['todo', 'in_progress', 'review', 'done'];
if (!in_array($newStatus, $validStatuses)) {
Session::flash('error', 'Trạng thái không hợp lệ');
return false;
}
$result = $this->taskRepo->updateStatus($taskId, $newStatus);
if ($result) {
Session::flash('success', 'Cập nhật trạng thái thành công');
return true;
}
Session::flash('error', 'Cập nhật thất bại');
return false;
}
/**
* Get task detail
*/
public function getTaskDetail(int $taskId): ?array
{
return $this->taskRepo->getTaskWithDetails($taskId);
}
}