instance = $stage; } public function getStage($id, $with = []) { if ( ! $id) { return false; } $stage = Stage::where('id', $id)->with($with)->first(); if ( ! $stage) { return false; } return $stage; } public function getStagesByBoard($boardId, $with = []) { if ( ! $boardId) { return false; } if ( ! PermissionManager::userHasPermission($boardId)) { return false; } $query = Stage::where('board_id', $boardId) ->whereNull('archived_at'); if ( ! empty($with)) { $query->with($with); } $stages = $query->get(); return $stages; } public function create($data) { if (empty($data)) { return false; } if (empty($data['title']) || empty($data['board_id'])) { return false; } //checking if current user has access to board if ( ! PermissionManager::userHasPermission($data['board_id'])) { return false; } $stageData = Helper::sanitizeStage($data); $stageService = new StageService(); $stage = $stageService->createStage($stageData, $stageData['board_id']); return $stage; } public function updateProperty($stageId, $property, $value) { $stageService = new StageService(); $stage = Stage::findOrFail($stageId); if ( ! $stage) { return false; } $allowedColumns = ['title', 'status', 'bg_color']; if ( ! in_array($property, $allowedColumns)) { return false; } //checking if current user has access to board if ( ! PermissionManager::userHasPermission($stage->board_id)) { return false; } $stage = $stageService->updateStageProperty($property, $value, $stageId); return $stage; } public function archiveStage($stageId) { if ( ! $stageId) { return false; } $stage = Stage::findOrFail($stageId); if ( ! $stage) { return false; } //checking if current user has access to board if ( ! PermissionManager::userHasPermission($stage->board_id)) { return false; } $boardService = new BoardService(); $stage = $boardService->archiveStage($stage->board_id, $stage); return $stage; } public function restoreStage($stageId) { if ( ! $stageId) { return false; } $stage = Stage::findOrFail($stageId); if ( ! $stage) { return false; } //checking if current user has access to board if ( ! PermissionManager::userHasPermission($stage->board_id)) { return false; } $boardService = new BoardService(); return $boardService->restoreStage($stage->board_id, $stage); } public function getInstance() { return $this->instance; } public function __call($method, $params) { if (in_array($method, $this->allowedInstanceMethods)) { return call_user_func_array([$this->instance, $method], $params); } throw new \Exception("Method {$method} does not exist."); } }