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

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

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