/** * @param array $data * @param ISurveyStep $current_step * @return ISurveyStep */ public function completeStep(ISurveyStep $current_step, array $data) { $template_repository = $this->template_repository; $survey_repository = $this->survey_repository; $survey_builder = $this->survey_builder; $member_repository = $this->member_repository; return $this->tx_manager->transaction(function () use($current_step, $data, $survey_builder, $member_repository, $template_repository, $survey_repository) { $current_survey = $current_step->survey(); if ($current_step instanceof ISurveyRegularStep) { $current_step->clearAnswers(); foreach ($current_step->template()->getQuestions() as $q) { if (isset($data[$q->name()])) { // its has an answer set if ($q->name() === SurveyOrganizationQuestionTemplate::FieldName) { //publish event PublisherSubscriberManager::getInstance()->publish('survey_organization_selected', array($current_survey->createdBy(), $data[$q->name()])); } $current_step->addAnswer($survey_builder->buildAnswer($q, $data[$q->name()])); } } } return $current_survey->completeCurrentStep(); }); }