toArray(); $payload['category'] = $this->surveyCategoryAssignmentService->getMemberCategoryIds($memberId); $survey = $this->surveyRepository->create($memberId, $payload); $this->surveyEditorRepository->assignEditor((int) $survey->id, $memberId); $this->surveyRepository->refreshListMetadata((int) $survey->id); return $survey; } public function updateSurvey(SurveyModel $survey, int $memberId, SurveyEditorData $data): void { $this->surveyRepository->update($survey, $memberId, $data->toArray()); } public function saveQuestion(SurveyModel $survey, SurveyQuestionData $data, int $questionId = 0): void { $this->assertUnlocked($survey); if ($questionId > 0) { $question = $this->surveyQuestionRepository->findByIdForSurvey((int) $survey->id, $questionId); if (null === $question) { throw new \RuntimeException('Die Frage wurde nicht gefunden.'); } $this->surveyQuestionRepository->update($question, $data->toArray()); $this->surveyRepository->touch((int) $survey->id); return; } $this->surveyQuestionRepository->create((int) $survey->id, $data->toArray()); $this->surveyRepository->touch((int) $survey->id); } public function deleteQuestion(SurveyModel $survey, int $questionId): void { $this->assertUnlocked($survey); $this->surveyQuestionRepository->delete((int) $survey->id, $questionId); $this->surveyRepository->touch((int) $survey->id); } public function saveCondition(SurveyModel $survey, SurveyConditionData $data, int $conditionId = 0): void { $this->assertUnlocked($survey); if ($conditionId > 0) { $condition = $this->surveyConditionRepository->findById($conditionId); if (null === $condition || (int) $condition->pid !== (int) $survey->id) { throw new \RuntimeException('Die Bedingung wurde nicht gefunden.'); } $this->surveyConditionRepository->update($condition, $data->toArray()); $this->surveyRepository->touch((int) $survey->id); return; } $this->surveyConditionRepository->create((int) $survey->id, $data->toArray()); $this->surveyRepository->touch((int) $survey->id); } public function deleteCondition(SurveyModel $survey, int $conditionId): void { $this->assertUnlocked($survey); $this->surveyConditionRepository->delete((int) $survey->id, $conditionId); $this->surveyRepository->touch((int) $survey->id); } private function assertUnlocked(SurveyModel $survey): void { if ('1' === (string) $survey->isLocked) { throw new \RuntimeException('Die Umfrage ist gesperrt, weil bereits Antworten existieren.'); } } }