コード例 #1
0
 /**
  * @param $request
  * @return HTMLText|SS_HTTPResponse|void
  * @throws NotFoundEntityException
  */
 public function EditEntity($request)
 {
     try {
         if (!Member::currentUser()) {
             return $this->httpError(403);
         }
         $step = $request->param('STEP_SLUG');
         $sub_step = $request->param('SUB_STEP_SLUG');
         $entity_survey_id = intval($request->param('ENTITY_SURVEY_ID'));
         $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', $current_step->template()->title()));
             }
         }
         $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()));
         }
         $entity_step = $this->current_entity_survey->currentStep();
         $entity_step_template = $entity_step->template();
         // check substep variable
         if (empty($sub_step)) {
             // is not set, redirect to first step uri
             $steps = $this->current_entity_survey->getSteps();
             return $this->redirect($request->getUrl() . '/' . $steps[0]->template()->title());
         } else {
             if ($sub_step !== $entity_step_template->title()) {
                 // if set, but differs from current step check if we are allowed to use that step
                 $desired_sub_step = $this->current_entity_survey->getStep($sub_step);
                 if (!is_null($desired_sub_step) && $this->current_entity_survey->isAllowedStep($sub_step)) {
                     $this->current_entity_survey->registerCurrentStep($desired_sub_step);
                 } else {
                     // if we are not allowed to go to desired step , redirect to current step
                     $current_url = Controller::join_links(Director::absoluteBaseURL(), $this->Link(), $step, 'edit', $entity_survey_id, $entity_step_template->title());
                     return $this->redirect($current_url);
                 }
             }
         }
         $this->current_entity_survey = $this->survey_manager->updateSurveyWithTemplate($this->current_entity_survey, $this->current_entity_survey->template());
         if ($sub_step === 'skip-step' && $this->current_entity_survey->currentStep()->canSkip()) {
             $next_step = $this->survey_manager->completeStep($this->current_entity_survey->currentStep(), $data = array());
             return $this->go2DynEntityStep($this->current_entity_survey, $next_step);
         }
         return $this->customise(array('Survey' => $this->current_survey, 'EntitySurvey' => $this->current_entity_survey))->renderWith(array('Surveys_CurrentSurveyDynamicEntityContainer', 'Page'));
     } catch (Exception $ex) {
         SS_Log::log($ex->getMessage(), SS_Log::ERR);
         return $this->httpError(404);
     }
 }