PluginProbe
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration / 2.1.0
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration v2.1.0
2.1.0 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 All 42 releases
fluent-boards / app / Http / Controllers / LabelController.php

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

177 lines 5.9 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 = Helper::sanitizeLabel($request->only(['bg_color', 'color', 'color_preset', 'label']));
53 $hasPreset = !empty($labelData['color_preset']);
54 $labelData = $this->validate($labelData, [
55 'bg_color' => $hasPreset ? 'nullable|string' : 'required|string',
56 'color' => $hasPreset ? 'nullable|string' : 'required|string',
57 'color_preset' => 'nullable|string',
58 'label' => 'nullable|string',
59 ]);
60
61 try {
62 $label = $this->labelService->createLabel($labelData, $board_id);
63 do_action('fluent_boards/board_label_created', $label);
64
65 return $this->sendSuccess([
66 'message' => __('Label has been created', 'fluent-boards'),
67 'label' => $label,
68 ], 201);
69 } catch (\Exception $e) {
70 return $this->sendError($e->getMessage(), 400);
71 }
72 }
73
74 public function createLabelForTask(Request $request, $board_id)
75 {
76 $board_id = absint($board_id);
77 $requestData = [
78 'task_id' => $request->getSafe('taskId', 'intval'),
79 'board_term_id' => $request->getSafe('labelId', 'intval'),
80 ];
81
82 $labelData = $this->labelSanitizeAndValidate($requestData, [
83 'task_id' => 'required|integer',
84 'board_term_id' => 'required|integer',
85 ]);
86 try {
87 $label = $this->labelService->createLabelForTask($labelData, $board_id);
88
89 return $this->sendSuccess([
90 'message' => __('Label has been added', 'fluent-boards'),
91 'label' => $label,
92 ], 201);
93 } catch (\Exception $e) {
94 return $this->sendError($e->getMessage(), 400);
95 }
96 }
97
98 public function getLabelsByTask($board_id, $task_id)
99 {
100 $board_id = absint($board_id);
101 $task_id = absint($task_id);
102 try {
103 $labels = $this->labelService->getLabelsByTask($task_id, $board_id);
104
105 return $this->sendSuccess([
106 'labels' => $labels,
107 ], 200);
108 } catch(\Exception $e) {
109 return $this->sendError($e->getMessage(), 400);
110 }
111 }
112
113 public function deleteLabelOfTask($board_id, $task_id, $label_id)
114 {
115 $board_id = absint($board_id);
116 $task_id = absint($task_id);
117 $label_id = absint($label_id);
118 try {
119 $this->labelService->deleteLabelOfTask($task_id, $label_id, $board_id);
120
121 return $this->sendSuccess([
122 'message' => __('Label has been deleted', 'fluent-boards'),
123 ], 200);
124 } catch (\Exception $e) {
125 return $this->sendError($e->getMessage(), 400);
126 }
127 }
128
129 public function deleteLabelOfBoard($board_id, $label_id)
130 {
131 $board_id = absint($board_id);
132 $label_id = absint($label_id);
133 try {
134 $this->labelService->deleteLabelOfBoard($label_id, $board_id);
135
136 return $this->sendSuccess([
137 'message' => __('Label has been deleted', 'fluent-boards'),
138 'type' => 'success',
139 ], 200);
140 } catch (\Exception $e) {
141 return $this->sendError($e->getMessage(), 400);
142 }
143 }
144
145 public function editLabelofBoard(Request $request, $board_id, $label_id)
146 {
147 $board_id = absint($board_id);
148 $label_id = absint($label_id);
149 $labelData = Helper::sanitizeLabel($request->only(['bg_color', 'color', 'color_preset', 'label']));
150 $isCustomSelection = array_key_exists('color_preset', $labelData) && $labelData['color_preset'] === '';
151 $labelData = $this->validate($labelData, [
152 'bg_color' => $isCustomSelection ? 'required|string' : 'nullable|string',
153 'color' => $isCustomSelection ? 'required|string' : 'nullable|string',
154 'color_preset' => 'nullable|string',
155 'label' => 'nullable|string',
156 ]);
157 try {
158 $label = $this->labelService->editLabelofBoard($labelData, $label_id, $board_id);
159 do_action('fluent_boards/board_label_updated', $label);
160
161 return $this->sendSuccess([
162 'message' => __('Label has been updated', 'fluent-boards'),
163 'label' => $label,
164 ], 200);
165 } catch (\Exception $e) {
166 return $this->sendError($e->getMessage(), 400);
167 }
168 }
169
170 private function labelSanitizeAndValidate($data, array $rules = [])
171 {
172 $data = Helper::sanitizeLabel($data);
173
174 return $this->validate($data, $rules);
175 }
176 }
177