PluginProbe
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration / trunk
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration vtrunk
2.0.15 2.0.12 2.0.10 2.0.4 2.0.1 2.0.0 1.95.3 1.95.2 1.95 1.91.6 trunk 1.11 1.12 1.13 1.20 1.21 1.22 1.23 1.30 1.31 1.32 1.35 1.40 1.41 1.45 All 41 releases
fluent-boards / app / Http / Controllers / LabelController.php

LabelController.php in FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration trunk, at app/Http/Controllers/LabelController.php

171 lines 5.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentBoards\App\Http\Controllers;
4
5 use FluentBoards\App\Models\Label;
6 use FluentBoards\App\Services\Constant;
7 use FluentBoards\App\Services\Helper;
8 use FluentBoards\Framework\Http\Request\Request;
9 use FluentBoards\App\Services\LabelService;
10
11 class LabelController extends Controller
12 {
13 private LabelService $labelService;
14
15 public function __construct(LabelService $labelService)
16 {
17 parent::__construct();
18 $this->labelService = $labelService;
19 }
20
21 public function getLabelsByBoard($board_id)
22 {
23 $board_id = absint($board_id);
24 try {
25 $labels = $this->labelService->getLabelsByBoard($board_id);
26
27 return $this->sendSuccess([
28 'labels' => $labels,
29 ], 200);
30 } catch(\Exception $e) {
31 return $this->sendError($e->getMessage(), 400);
32 }
33 }
34
35 public function getLabelsByBoardUsedInTasks($board_id)
36 {
37 $board_id = absint($board_id);
38 try {
39 $labels = $this->labelService->getLabelsByBoardUsedInTasks($board_id);
40
41 return $this->sendSuccess([
42 'labels' => $labels,
43 ], 200);
44 } catch(\Exception $e) {
45 return $this->sendError($e->getMessage(), 400);
46 }
47 }
48
49 public function createLabel(Request $request, $board_id)
50 {
51 $board_id = absint($board_id);
52 $labelData = $this->labelSanitizeAndValidate($request->only(['bg_color', 'color', 'label']), [
53 'bg_color' => 'required|string',
54 'color' => 'required|string',
55 'label' => 'nullable|string',
56 ]);
57
58 try {
59 $label = $this->labelService->createLabel($labelData, $board_id);
60 do_action('fluent_boards/board_label_created', $label);
61
62 return $this->sendSuccess([
63 'message' => __('Label has been created', 'fluent-boards'),
64 'label' => $label,
65 ], 201);
66 } catch (\Exception $e) {
67 return $this->sendError($e->getMessage(), 400);
68 }
69 }
70
71 public function createLabelForTask(Request $request, $board_id)
72 {
73 $board_id = absint($board_id);
74 $requestData = [
75 'task_id' => $request->getSafe('taskId', 'intval'),
76 'board_term_id' => $request->getSafe('labelId', 'intval'),
77 ];
78
79 $labelData = $this->labelSanitizeAndValidate($requestData, [
80 'task_id' => 'required|integer',
81 'board_term_id' => 'required|integer',
82 ]);
83 try {
84 $label = $this->labelService->createLabelForTask($labelData, $board_id);
85
86 return $this->sendSuccess([
87 'message' => __('Label has been added', 'fluent-boards'),
88 'label' => $label,
89 ], 201);
90 } catch (\Exception $e) {
91 return $this->sendError($e->getMessage(), 400);
92 }
93 }
94
95 public function getLabelsByTask($board_id, $task_id)
96 {
97 $board_id = absint($board_id);
98 $task_id = absint($task_id);
99 try {
100 $labels = $this->labelService->getLabelsByTask($task_id, $board_id);
101
102 return $this->sendSuccess([
103 'labels' => $labels,
104 ], 200);
105 } catch(\Exception $e) {
106 return $this->sendError($e->getMessage(), 400);
107 }
108 }
109
110 public function deleteLabelOfTask($board_id, $task_id, $label_id)
111 {
112 $board_id = absint($board_id);
113 $task_id = absint($task_id);
114 $label_id = absint($label_id);
115 try {
116 $this->labelService->deleteLabelOfTask($task_id, $label_id, $board_id);
117
118 return $this->sendSuccess([
119 'message' => __('Label has been deleted', 'fluent-boards'),
120 ], 200);
121 } catch (\Exception $e) {
122 return $this->sendError($e->getMessage(), 400);
123 }
124 }
125
126 public function deleteLabelOfBoard($board_id, $label_id)
127 {
128 $board_id = absint($board_id);
129 $label_id = absint($label_id);
130 try {
131 $this->labelService->deleteLabelOfBoard($label_id, $board_id);
132
133 return $this->sendSuccess([
134 'message' => __('Label has been deleted', 'fluent-boards'),
135 'type' => 'success',
136 ], 200);
137 } catch (\Exception $e) {
138 return $this->sendError($e->getMessage(), 400);
139 }
140 }
141
142 public function editLabelofBoard(Request $request, $board_id, $label_id)
143 {
144 $board_id = absint($board_id);
145 $label_id = absint($label_id);
146 $labelData = $this->labelSanitizeAndValidate($request->only(['bg_color', 'color', 'label']), [
147 'bg_color' => 'required|string',
148 'color' => 'nullable|string',
149 'label' => 'nullable|string',
150 ]);
151 try {
152 $label = $this->labelService->editLabelofBoard($labelData, $label_id, $board_id);
153 do_action('fluent_boards/board_label_updated', $label);
154
155 return $this->sendSuccess([
156 'message' => __('Label has been updated', 'fluent-boards'),
157 'label' => $label,
158 ], 200);
159 } catch (\Exception $e) {
160 return $this->sendError($e->getMessage(), 400);
161 }
162 }
163
164 private function labelSanitizeAndValidate($data, array $rules = [])
165 {
166 $data = Helper::sanitizeLabel($data);
167
168 return $this->validate($data, $rules);
169 }
170 }
171