PluginProbe
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration / 1.11
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration v1.11
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.11, at app/Http/Controllers/StageController.php

114 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 dragStage(Request $request, $board_id)
58 {
59 $stage_id = $request->getSafe('stageId');
60 $position = $request->getSafe('newPosition');
61 try{
62 $stage = Stage::findOrFail($stage_id);
63 $stage->moveToNewPosition($position);
64 do_action('fluent_boards/board_stages_reordered', $board_id, [$stage_id]);
65 return $this->sendSuccess([
66 'message' => __('Board stage has been updated', 'fluent-boards'),
67 'updatedStages' => $this->stageService->getLastOneMinuteUpdatedStages($board_id)
68 ], 200);
69 } catch (\Exception $e) {
70 return $this->sendError($e->getMessage(), 400);
71 }
72 }
73
74 public function updateStage(Request $request, $board_id, $stage_id)
75 {
76 $updatedStage = $this->stageSanitizeAndValidate($request->stage, [
77 'title' => 'required|string'
78 ]);
79 /*
80 * TODO: Check if the stage is empty or not. Let's allow duplicate stage
81 */
82 try {
83 $oldStage = Stage::findOrFail($stage_id);
84 $board = $oldStage->board;
85 $stages = $board->stages()->where('id', '!=', $stage_id)->get();
86 $stageEditable = $this->stageService->checkStageEditable($stages, $updatedStage);
87
88 if ($stageEditable) {
89 $updatedStage = $this->stageService->updateStage($updatedStage, $board->id, $oldStage);
90
91 return $this->sendSuccess([
92 'success' => true,
93 'stages' => $board->stages()->get(),
94 'updatedStage' => $updatedStage,
95 'message' => __('Stage has been updated', 'fluent-boards'),
96 ], 200);
97 } else {
98 return $this->sendError([
99 'success' => false,
100 'message' => __('Duplicate or empty stage', 'fluent-boards'),
101 ], 422);
102 }
103 } catch (\Exception $e) {
104 return $this->sendError($e->getMessage(), 400);
105 }
106 }
107
108 private function stageSanitizeAndValidate($data, array $rules = [])
109 {
110 $data = Helper::sanitizeStage($data);
111
112 return $this->validate($data, $rules);
113 }
114 }