stageService = $stageService; } public function updateStageProperty(Request $request, $board_id, $stage_id) { $col = $request->getSafe('property'); $value = $request->getSafe('value'); try { $validatedData = $this->updateStagePropValidationAndSanitation($col, $value); $stage = $this->stageService->updateStageProperty($col, $validatedData[$col], $stage_id); return $this->sendSuccess([ 'message' => __('Stage has been updated', 'fluent-boards'), 'stage' => $stage ], 200); } catch (\Exception $e) { return $this->sendError($e->getMessage(), 404); } } private function updateStagePropValidationAndSanitation($col, $value) { $rules = [ 'title' => 'required|string', 'color' => 'nullable|string', 'bg_color' => 'nullable|string', 'archived_at' => 'nullable|string', 'status' => 'required|string', 'settings' => 'nullable|array', ]; if (array_key_exists($col, $rules)) { $rule = $rules[$col]; $data = Helper::sanitizeStage([$col => $value]); return $this->validate($data, [ $col => $rule, ]); } } public function sortStageTasks(Request $request, $board_id, $stage_id) { $order = $request->getSafe('order', 'sanitize_text_field'); $orderBy = $request->getSafe('orderBy', 'sanitize_text_field'); $updatedTasks = $this->stageService->sortStageTasks($order, $orderBy, $stage_id); return [ 'message' => __('Tasks has been sorted', 'fluent-boards'), 'updatedTasks' => $updatedTasks, ]; } public function dragStage(Request $request, $board_id) { $stage_id = $request->getSafe('stageId'); $position = $request->getSafe('newPosition'); try{ $stage = Stage::findOrFail($stage_id); $stage->moveToNewPosition($position); do_action('fluent_boards/board_stages_reordered', $board_id, [$stage_id]); return $this->sendSuccess([ 'message' => __('Board stage has been updated', 'fluent-boards'), 'updatedStages' => $this->stageService->getLastOneMinuteUpdatedStages($board_id) ], 200); } catch (\Exception $e) { return $this->sendError($e->getMessage(), 400); } } public function updateStage(Request $request, $board_id, $stage_id) { $updatedStage = $this->stageSanitizeAndValidate($request->stage, [ 'title' => 'required|string' ]); /* * TODO: Check if the stage is empty or not. Let's allow duplicate stage */ try { $oldStage = Stage::findOrFail($stage_id); $board = $oldStage->board; $stages = $board->stages()->where('id', '!=', $stage_id)->get(); $stageEditable = $this->stageService->checkStageEditable($stages, $updatedStage); if ($stageEditable) { $updatedStage = $this->stageService->updateStage($updatedStage, $board->id, $oldStage); return $this->sendSuccess([ 'success' => true, 'stages' => $board->stages()->get(), 'updatedStage' => $updatedStage, 'message' => __('Stage has been updated', 'fluent-boards'), ], 200); } else { return $this->sendError([ 'success' => false, 'message' => __('Duplicate or empty stage', 'fluent-boards'), ], 422); } } catch (\Exception $e) { return $this->sendError($e->getMessage(), 400); } } private function stageSanitizeAndValidate($data, array $rules = []) { $data = Helper::sanitizeStage($data); return $this->validate($data, $rules); } }