コード例 #1
0
ファイル: SurveyPage.php プロジェクト: Thingee/openstack-org
 /**
  * @param $data
  * @param $form
  * @return SS_HTTPResponse
  */
 public function NextDynamicEntityStep($data, $form)
 {
     try {
         $step = $this->request->param('STEP_SLUG');
         if (is_null($step)) {
             $step = $this->request->requestVar('STEP_SLUG');
         }
         $sub_step = $this->request->param('SUB_STEP_SLUG');
         if (is_null($sub_step)) {
             $sub_step = $this->request->requestVar('SUB_STEP_SLUG');
         }
         $entity_survey = $this->getCurrentEntitySurveyInstance(intval($data['survey_id']));
         if (is_null($entity_survey)) {
             throw new LogicException('entity survey not found!');
         }
         $current_step = $entity_survey->currentStep();
         $next_step = $this->survey_manager->completeStep($current_step, $data);
         if ($entity_survey->isLastStep()) {
             return $this->redirect($this->Link() . $this->current_survey->currentStep()->template()->title());
         } else {
             return $this->go2DynEntityStep($entity_survey, $next_step);
         }
     } catch (Exception $ex) {
         SS_Log::log($ex->getMessage(), SS_Log::ERR);
         return $this->httpError(404);
     }
 }
コード例 #2
0
 public function deleteTeamMember(SS_HTTPRequest $request)
 {
     if (!Director::is_ajax()) {
         return $this->forbiddenError();
     }
     if (!Member::currentUser()) {
         return $this->forbiddenError();
     }
     $entity_survey_id = (int) $request->param('ENTITY_SURVEY_ID');
     $member_id = (int) $request->param('MEMBER_ID');
     try {
         $this->survey_manager->unRegisterTeamMemberOnEntitySurvey($entity_survey_id, $member_id);
         return $this->deleted();
     } catch (Exception $ex) {
         return $this->serverError();
     }
 }
コード例 #3
0
 /**
  * @param ISurvey $survey
  * @param ISurveyBuilder $survey_builder
  * @param ISurveyManager $manager
  */
 public function autoPopulate(ISurvey $survey, ISurveyBuilder $survey_builder, ISurveyManager $manager)
 {
     $template = $survey->template();
     $owner = $survey->createdBy();
     $mappings = $template->getAutopopulationMappings();
     // get former survey ...
     $old_survey = DeploymentSurvey::get()->filter('MemberID', $owner->getIdentifier())->sort('Created', 'DESC')->first();
     if (is_null($old_survey)) {
         return;
     }
     foreach ($mappings as $mapping) {
         if (!$mapping instanceof IOldSurveyMigrationMapping) {
             continue;
         }
         $origin_table_name = $mapping->getOriginTableName();
         $origin_field_name = $mapping->getOriginFieldName();
         $question = $mapping->getTargetQuestion();
         if (is_null($question)) {
             continue;
         }
         $step_template = $question->step();
         if (is_null($step_template)) {
             continue;
         }
         $step = $survey->getStep($step_template->title());
         if (is_null($step)) {
             continue;
         }
         if (!$step instanceof ISurveyRegularStep) {
             continue;
         }
         if ($origin_table_name === 'DeploymentSurvey') {
             $old_data = $old_survey->{$origin_field_name};
             // old data is only a label, we need to find out the value
             $data = $old_data;
             if ($question instanceof IMultiValueQuestionTemplate) {
                 $data = '';
                 if ($question instanceof IDropDownQuestionTemplate && $question->isCountrySelector()) {
                     $data = $old_data;
                 } else {
                     $old_data = explode(',', $old_data);
                     foreach ($old_data as $od) {
                         $v = $question->getValueByValue($od);
                         if (is_null($v)) {
                             continue;
                         }
                         if (!empty($data)) {
                             $data .= ',';
                         }
                         $data .= $v->getIdentifier();
                     }
                 }
             }
             if (empty($data)) {
                 continue;
             }
             $step->addAnswer($survey_builder->buildAnswer($question, $data));
         }
         if ($origin_table_name === 'AppDevSurvey') {
             $app_dev_survey = $old_survey->AppDevSurveys()->first();
             if (!$app_dev_survey) {
                 continue;
             }
             $old_data = $app_dev_survey->{$origin_field_name};
             $data = $old_data;
             if ($question instanceof IMultiValueQuestionTemplate) {
                 $data = '';
                 $old_data = explode(',', $old_data);
                 foreach ($old_data as $od) {
                     $v = $question->getValueByValue($od);
                     if (is_null($v)) {
                         continue;
                     }
                     if (!empty($data)) {
                         $data .= ',';
                     }
                     $data .= $v->getIdentifier();
                 }
             }
             if (empty($data)) {
                 continue;
             }
             $step->addAnswer($survey_builder->buildAnswer($question, $data));
         }
     }
     //check if we need to auto-populate entities
     foreach ($template->getEntities() as $entity_survey) {
         if ($entity_survey->belongsToDynamicStep() && $entity_survey->shouldPrepopulateWithFormerData()) {
             $mappings = $entity_survey->getAutopopulationMappings();
             $dyn_step = $survey->getStep($entity_survey->getDynamicStepTemplate()->title());
             if (is_null($dyn_step)) {
                 continue;
             }
             foreach ($old_survey->Deployments() as $old_deployment) {
                 $entity_survey = $manager->buildEntitySurvey($dyn_step, $owner->getIdentifier());
                 foreach ($mappings as $mapping) {
                     if (!$mapping instanceof IOldSurveyMigrationMapping) {
                         continue;
                     }
                     $origin_table_name = $mapping->getOriginTableName();
                     $origin_field_name = $mapping->getOriginFieldName();
                     $question = $mapping->getTargetQuestion();
                     $step_template = $question->step();
                     $step = $entity_survey->getStep($step_template->title());
                     if (!$step instanceof ISurveyRegularStep) {
                         continue;
                     }
                     if ($origin_table_name === 'Deployment') {
                         $old_data = $old_deployment->{$origin_field_name};
                         $data = $old_data;
                         if ($question instanceof IMultiValueQuestionTemplate) {
                             $data = '';
                             $old_data = explode(',', $old_data);
                             foreach ($old_data as $od) {
                                 $v = $question->getValueByValue($od);
                                 if (is_null($v)) {
                                     continue;
                                 }
                                 if (!empty($data)) {
                                     $data .= ',';
                                 }
                                 $data .= $v->getIdentifier();
                             }
                         }
                         if (empty($data)) {
                             continue;
                         }
                         $step->addAnswer($survey_builder->buildAnswer($question, $data));
                     }
                 }
             }
         }
     }
 }