Beispiel #1
0
 /**
  * @return ISurvey|null
  * @throws NotFoundEntityException
  */
 private function getCurrentSurveyInstance()
 {
     // get current template
     $current_template = $this->SurveyTemplate();
     if (is_null($current_template)) {
         throw new NotFoundEntityException('SurveyTemplate', 'current template not set');
     }
     if ($current_template->isVoid()) {
         throw new NotFoundEntityException('SurveyTemplate', 'current template is void!');
     }
     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, SurveyDataAutoPopulationStrategyFactory::build(SurveyDataAutoPopulationStrategyFactory::NEW_STRATEGY));
         }
     }
     $this->current_survey = $this->survey_manager->updateSurveyWithTemplate($this->current_survey, $current_template);
     return $this->current_survey;
 }
 public function getTeamMembers(SS_HTTPRequest $request)
 {
     if (!Director::is_ajax()) {
         return $this->httpError(403);
     }
     if (!Member::currentUser()) {
         return $this->httpError(403);
     }
     $entity_survey_id = (int) $request->param('ENTITY_SURVEY_ID');
     try {
         $entity_survey = $this->survey_repository->getById($entity_survey_id);
         if (is_null($entity_survey) || !$entity_survey instanceof IEntitySurvey) {
             return $this->httpError(404);
         }
         $items = array();
         foreach ($entity_survey->getTeamMembers() as $member) {
             $items[] = array('id' => $member->ID, 'fname' => $member->FirstName, 'lname' => $member->Surname, 'pic_url' => $member->ProfilePhotoUrl(100));
         }
         $response = new SS_HTTPResponse();
         $response->addHeader('Content-Type', 'application/json');
         $response->setBody(json_encode($items));
         return $response;
     } catch (Exception $ex) {
         return $this->httpError(500);
     }
 }
 public function getTeamMembers(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');
     try {
         $entity_survey = $this->survey_repository->getById($entity_survey_id);
         if (is_null($entity_survey) || !$entity_survey instanceof IEntitySurvey) {
             return $this->httpError(404);
         }
         $items = array();
         foreach ($entity_survey->getTeamMembers() as $member) {
             $items[] = array('id' => $member->ID, 'fname' => $member->FirstName, 'lname' => $member->Surname, 'pic_url' => $member->ProfilePhotoUrl(100));
         }
         return $this->ok($items);
     } catch (Exception $ex) {
         return $this->serverError();
     }
 }