'Retrieved Help Menu Next Question', 'message' => 'You have successfully retrieved a Help Menu Next Question' ]; } /** @var CanFetchHelpMenuQuestion */ private $canFetchHelpMenuQuestion; /** @var SaveAnswerProcessor */ private $saveAnswerProcessor; /** @var DeleteAnswerQAProcessor */ private $deleteAnswerQAProcessor; /** @var FetchNextQuestionQAProcessor */ private $fetchNextQuestionQAProcessor; /** @var FetchFirstQuestionQAProcessor */ private $fetchFirstQuestionQAProcessor; /** @var CreatesPerfexCRMSupportTicket */ private $createsPerfexCRMSupportTicket; /** @var FetchesPerfexCRMCustomer */ private $fetchesPerfexCRMCustomer; /** * UpdateHelpMenuNextQuestionLogic constructor. * @param CanFetchHelpMenuQuestion $canFetchHelpMenuQuestion * @param SaveAnswerProcessor $saveAnswerProcessor * @param FetchNextQuestionQAProcessor $fetchNextQuestionQAProcessor * @param FetchFirstQuestionQAProcessor $fetchFirstQuestionQAProcessor * @param DeleteAnswerQAProcessor $deleteAnswerQAProcessor */ public function __construct(CanFetchHelpMenuQuestion $canFetchHelpMenuQuestion, SaveAnswerProcessor $saveAnswerProcessor, FetchNextQuestionQAProcessor $fetchNextQuestionQAProcessor, FetchFirstQuestionQAProcessor $fetchFirstQuestionQAProcessor, CreatesPerfexCRMSupportTicket $createsPerfexCRMSupportTicket, FetchesPerfexCRMCustomer $fetchesPerfexCRMCustomer, DeleteAnswerQAProcessor $deleteAnswerQAProcessor) { $this->canFetchHelpMenuQuestion = $canFetchHelpMenuQuestion; $this->saveAnswerProcessor = $saveAnswerProcessor; $this->fetchNextQuestionQAProcessor = $fetchNextQuestionQAProcessor; $this->fetchFirstQuestionQAProcessor = $fetchFirstQuestionQAProcessor; $this->createsPerfexCRMSupportTicket = $createsPerfexCRMSupportTicket; $this->fetchesPerfexCRMCustomer = $fetchesPerfexCRMCustomer; $this->deleteAnswerQAProcessor = $deleteAnswerQAProcessor; } /** * @param Request $request * @return JsonResponse * @throws ErrorException */ public function logic(Request $request) : JsonResponse { $questionId = 0; $userId = Auth::user()->id; $currentQuestion = $request->question; $questionId = $currentQuestion['id']; $questionType = $currentQuestion['question_type']; $this->canFetchHelpMenuQuestion->passes(); //Delete answer $this->deleteAnswerQAProcessor->execute($userId, $questionId, $request); //Save answer given by user if (!$request->has('isPrevious')) { $filesUpload = $request->input('files'); $answerOptionId = 0; if ($request->has('answerObj')) { $answerOptionId = intval($request->answerObj['id']); } $answerInText = $request->answer; $this->saveAnswerProcessor->execute($userId, 0, $questionId, $answerInText, $answerOptionId, $filesUpload); } //Create ticket at crm if (!$request->has('isPrevious')) { if($questionType == QAType::TICKET_CRM){ $email = Auth::user()->email; $customer = $this->fetchesPerfexCRMCustomer->execute($email); $subject = "test subject 3"; $department = 1; $contactid = 0; $userid = 0; if($customer){ $contactid = $customer->id; $userid = $customer->userid; } $this->createsPerfexCRMSupportTicket->execute($subject, $department, $contactid, $userid); } } //Get returned question (previous or next) $returnQuestion = $this->fetchNextQuestionQAProcessor->execute($request); //When a questionnaire ended, return back the first question if(is_null($returnQuestion)){ $returnQuestion = $this->fetchFirstQuestionQAProcessor->execute($request); } return $this->resourceResponse(new HelpMenuQuestionResource($returnQuestion, $userId)); } }