예제 #1
0
 /**
  * @return array
  */
 public function answer($answerId)
 {
     try {
         $answer = $this->answersRepository->find($answerId);
     } catch (ModelNotFoundException $e) {
         return $this->respondNotFound("No answer found with an id={$answerId}");
     }
     return $this->respond(['data' => $this->answersTransformer->transform($answer->toArray())]);
 }
예제 #2
0
 /**
  * Unsubscribe an answerer from one or more lists.
  *
  * @param       $answer_id
  * @param array $allLists
  */
 public function unSubscribeAnswerer($answer_id, array $allLists = [])
 {
     // Update database record
     $this->answers->unSubscribeAnswererFromResults($answer_id);
     // Find the email for the answer, and unsubscribe it to the list
     $email = $this->answers->find($answer_id)->email;
     foreach ($allLists as $list) {
         $this->newsletter->unSubscribeFrom($list, $email);
     }
 }
예제 #3
0
 /**
  * Temp Store survey.
  *
  * @param AnswersFormRequest $request
  * @param AnswersRepository  $answerRepository
  *
  * @internal param AnswersRepository $repo
  *
  * @return \Illuminate\View\View
  */
 public function store(AnswersFormRequest $request, AnswersRepository $answerRepository, Dispatcher $dispatcher)
 {
     // Make an answers DTO from Inputs
     $answersDTO = new AnswersDTO(serializeArray($request->all()));
     // Create an Answer if email does not already exists
     try {
         $saved = $answerRepository->createAndSaveIfUnique($answersDTO->toArray());
         $dispatcher->fire(new SurveyWasSubmitted($saved->id));
     } catch (EmailExistsException $e) {
         return view('survey.alreadySubmitted', ['email' => $answersDTO->email]);
     }
     return Redirect::route('answer.saved', ['email' => $answersDTO->email ?: '', 'answer_id' => $saved->id]);
 }
예제 #4
0
 /**
  * Unsubscribe from results.
  *
  * @param $email
  *
  * @return \Illuminate\View\View
  */
 public function unSubscribeFromResults($email)
 {
     // Update database record
     try {
         $this->answers->unSubscribeToResults($email);
     } catch (NoAnswerFoundWithThisMailException $e) {
         return view('survey.error', ['message' => "Le mail {$email} n'existe pas dans la base de donnée !"]);
     }
     // Unsubscribe from mailing list
     try {
         $this->newsletter->unSubscribeFrom('Echo_results', $email);
     } catch (Mailchimp_List_NotSubscribed $e) {
         return view('survey.unsubscribed', compact('email'));
     }
     // Thank you for unsubscribing view
     return view('survey.unsubscribed', compact('email'));
 }
예제 #5
0
 /**
  * Return an array of answers.
  *
  * @return array
  */
 public function answersExplodedArray()
 {
     $groupped = [];
     foreach ($this->answers->allWithMedicalCenters()->toArray() as $answer) {
         foreach ($answer as $key => $value) {
             $answer_id = $answer['id'];
             // If we find a nested array, ignore it
             if (is_array($answer[$key])) {
                 continue;
             }
             // When we are at medical_center_id, substitute it for its name and id
             if ($key === 'medical_center_id') {
                 $groupped['medical_center_id'][$answer_id] = $answer['medical_center']['id'];
                 $groupped['medical_center_email'][$answer_id] = $answer['medical_center']['email'];
                 $groupped['medical_center'][$answer_id] = $answer['medical_center']['name'];
                 continue;
             }
             // if (!is_array($value)) {
             //     $values = (!in_array($key, $this->dontExplodeValue)) ? explode(',', $value) : [$value];
             // }
             // Add it to the groupped array
             $group = array_filter(explode(',', $value));
             if (!in_array($key, $this->dontExplodeValue)) {
                 // if (count($group) > 1) {
                 foreach ($group as $val) {
                     // Ignore specific field
                     if (in_array($key, ['commentaires'])) {
                         continue;
                     }
                     $str = new \Illuminate\Support\Str();
                     $val = substr($str->slug($val), 0, 35);
                     $groupped[$key . '_' . $val][$answer_id] = 1;
                 }
             } else {
                 $groupped[$key][$answer_id] = $value;
             }
         }
     }
     return $groupped;
 }
예제 #6
0
 /**
  * Nombre de participants.
  *
  * @return mixed
  */
 public function participants()
 {
     return $this->answersRepository->count();
 }