PluginProbe
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration / 1.91.6
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration v1.91.6
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 / StageController.php

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

127 lines 4.5 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\Stage;
6 use FluentBoards\App\Services\Helper;
7 use FluentBoards\App\Services\StageService;
8 use FluentBoards\Framework\Http\Request\Request;
9
10 class StageController extends Controller
11 {
12 private $stageService;
13 public function __construct(StageService $stageService)
14 {
15 parent::__construct();
16 $this->stageService = $stageService;
17 }
18 public function updateStageProperty(Request $request, $board_id, $stage_id)
19 {
20 $board_id = absint($board_id);
21 $stage_id = absint($stage_id);
22 $col = $request->getSafe('property', 'sanitize_text_field');
23 $value = $request->getSafe('value', 'sanitize_text_field');
24
25 try {
26 $validatedData = $this->updateStagePropValidationAndSanitation($col, $value);
27
28 $stage = $this->stageService->updateStageProperty($col, $validatedData[$col], $stage_id);
29
30 return $this->sendSuccess([
31 'message' => __('Stage has been updated', 'fluent-boards'),
32 'stage' => $stage
33 ], 200);
34 } catch (\Exception $e) {
35 return $this->sendError($e->getMessage(), 404);
36 }
37 }
38
39 private function updateStagePropValidationAndSanitation($col, $value)
40 {
41 $rules = [
42 'title' => 'required|string',
43 'color' => 'nullable|string',
44 'bg_color' => 'nullable|string',
45 'archived_at' => 'nullable|string',
46 'status' => 'required|string',
47 'settings' => 'nullable|array',
48 ];
49 if (array_key_exists($col, $rules)) {
50 $rule = $rules[$col];
51 $data = Helper::sanitizeStage([$col => $value]);
52
53 return $this->validate($data, [
54 $col => $rule,
55 ]);
56 }
57 }
58
59 public function sortStageTasks(Request $request, $board_id, $stage_id)
60 {
61 $board_id = absint($board_id);
62 $stage_id = absint($stage_id);
63 $order = $request->getSafe('order', 'sanitize_text_field');
64 $orderBy = $request->getSafe('orderBy', 'sanitize_text_field');
65
66 $updatedTasks = $this->stageService->sortStageTasks($order, $orderBy, $stage_id);
67 return [
68 'message' => __('Tasks has been sorted', 'fluent-boards'),
69 'updatedTasks' => $updatedTasks,
70 ];
71 }
72
73 public function dragStage(Request $request, $board_id)
74 {
75 $board_id = absint($board_id);
76 $stage_id = $request->getSafe('stageId', 'intval');
77 $position = $request->getSafe('newPosition', 'intval');
78 try{
79 $stage = Stage::findOrFail($stage_id);
80 $stage->moveToNewPosition($position);
81 do_action('fluent_boards/board_stages_reordered', $board_id, [$stage_id]);
82 return $this->sendSuccess([
83 'message' => __('Board stage has been updated', 'fluent-boards'),
84 'updatedStages' => $this->stageService->getLastOneMinuteUpdatedStages($board_id)
85 ], 200);
86 } catch (\Exception $e) {
87 return $this->sendError($e->getMessage(), 400);
88 }
89 }
90
91 public function updateStage(Request $request, $board_id, $stage_id)
92 {
93 $board_id = absint($board_id);
94 $stage_id = absint($stage_id);
95 $stageData = $request->getSafe('stage');
96 if (!is_array($stageData)) {
97 $stageData = [];
98 }
99 $updatedStage = $this->stageSanitizeAndValidate($stageData, [
100 'title' => 'required|string',
101 'cover_bg' => 'nullable'
102 ]);
103 try {
104 $oldStage = Stage::findOrFail($stage_id);
105 $board = $oldStage->board;
106 $stages = $board->stages()->where('id', '!=', $stage_id)->get();
107
108 $updatedStage = $this->stageService->updateStage($updatedStage, $board->id, $oldStage);
109
110 return $this->sendSuccess([
111 'success' => true,
112 'stages' => $board->stages()->get(),
113 'updatedStage' => $updatedStage,
114 'message' => __('Stage has been updated', 'fluent-boards'),
115 ], 200);
116 } catch (\Exception $e) {
117 return $this->sendError($e->getMessage(), 400);
118 }
119 }
120
121 private function stageSanitizeAndValidate($data, array $rules = [])
122 {
123 $data = Helper::sanitizeStage($data);
124
125 return $this->validate($data, $rules);
126 }
127 }