/** * @return Form|string * @throws NotFoundEntityException */ public function SurveyDynamicEntityStepForm() { if (!Member::currentUser()) { return $this->httpError(403); } try { $request = $this->getRequest(); $step = $request->param('STEP_SLUG'); if (is_null($step)) { $step = $request->requestVar('STEP_SLUG'); } $sub_step = $request->param('SUB_STEP_SLUG'); if (is_null($sub_step)) { $sub_step = $request->requestVar('SUB_STEP_SLUG'); } if (empty($step) || empty($sub_step)) { throw new LogicException(sprintf('step/sub_step empty (%s - %s) - member_id %s', $step, $sub_step, Member::currentUserID())); } $this->current_survey = $this->getCurrentSurveyInstance(); $current_step = $this->current_survey->currentStep(); if (!$current_step instanceof ISurveyDynamicEntityStep) { if ($this->current_survey->isAllowedStep($step)) { $current_step = $this->current_survey->getStep($step); $this->survey_manager->registerCurrentStep($this->current_survey, $step); } else { throw new LogicException(sprintf('template %s - member_id %s', $current_step->template()->title(), Member::currentUserID())); } } // check entity survey id $entity_survey_id = intval($request->param('ENTITY_SURVEY_ID')); if ($entity_survey_id === 0) { $entity_survey_id = intval($request->requestVar('ENTITY_SURVEY_ID')); } if ($entity_survey_id === 0) { throw new LogicException(sprintf('entity survey id is %s - member_id %s', $entity_survey_id, Member::currentUserID())); } $this->current_entity_survey = $current_step->getEntitySurvey($entity_survey_id); if (is_null($this->current_entity_survey)) { //check if its a entity survey from a team that i belong $current_member = Member::currentUser(); $this->current_entity_survey = $current_member->TeamEntitySurveys()->filter('EntitySurveyID', $entity_survey_id)->first(); } if (is_null($this->current_entity_survey)) { throw new LogicException(sprintf('entity survey id is %s - member_id %s', $entity_survey_id, Member::currentUserID())); } if ($this->current_entity_survey->currentStep()->template()->title() !== $sub_step) { if ($this->current_entity_survey->isAllowedStep($sub_step)) { $this->survey_manager->registerCurrentStep($this->current_entity_survey, $sub_step); } else { throw new LogicException(sprintf('current step %s differs from requested one %s - member_id %s', $this->current_entity_survey->currentStep()->template()->title(), $sub_step, Member::currentUserID())); } } $builder = SurveyStepUIBuilderFactory::getInstance()->build($this->current_entity_survey->currentStep()); if (is_null($builder)) { throw new LogicException(sprintf('There is not set any form yet! - member_id %s', Member::currentUserID())); } $form = $builder->build($this->current_entity_survey->currentStep(), 'NextDynamicEntityStep', 'SurveyDynamicEntityStepForm'); $form->Fields()->add(new HiddenField('ENTITY_SURVEY_ID', 'ENTITY_SURVEY_ID', $entity_survey_id)); $form->Fields()->add(new HiddenField('STEP_SLUG', 'STEP_SLUG', $step)); $form->Fields()->add(new HiddenField('SUB_STEP_SLUG', 'SUB_STEP_SLUG', $sub_step)); return $form; } catch (Exception $ex) { SS_Log::log($ex->getMessage(), SS_Log::ERR); return $this->httpError(404); } }
/** * @param ISurvey $survey * @param string $step_name * @return void */ public function registerCurrentStep(ISurvey $survey, $step_name) { $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($survey, $step_name, $survey_builder, $member_repository, $template_repository, $survey_repository) { if ($survey->isAllowedStep($step_name)) { $survey->registerCurrentStep($survey->getStep($step_name)); } }); }