/** * @return ISurvey|null * @throws NotFoundEntityException */ private function getCurrentSurveyInstance() { // get current template $current_template = $this->survey_manager->getCurrentSurveyTemplate(); if (is_null($current_template)) { throw new NotFoundEntityException('SurveyTemplate', 'current template not set'); } if (!is_null($this->current_survey)) { return $this->current_survey; } $this->current_survey = $this->survey_repository->getByTemplateAndCreator($current_template->getIdentifier(), Member::currentUserID()); // if not, create the survey and do the population if (is_null($this->current_survey)) { $this->current_survey = $this->survey_manager->buildSurvey($current_template->getIdentifier(), Member::currentUserID()); // check if we should pre populate with former data .... if ($current_template->shouldPrepopulateWithFormerData()) { $this->survey_manager->doAutopopulation($this->current_survey, new OldSurveyDataAutopopulationStrategy()); } } $this->current_survey = $this->survey_manager->updateSurveyWithTemplate($this->current_survey, $current_template); return $this->current_survey; }