コード例 #1
0
 /**
  * @Route("/v1/translate", name="route.api.v1.translate")
  * @Method("POST")
  */
 public function translateAction(Request $request)
 {
     $englishVocabulary = $this->vocabularyNormalizer->normalize($request->query->get('vocabulary'));
     if (!$englishVocabulary) {
         throw new BadRequestHttpException('Vocabulary not defined');
     }
     $translationList = $this->seznamSlovnikApiTranslator->translate($englishVocabulary, SlovnikApiTranslator::TRANSLATE_EN2CZ);
     $currentUser = $this->currentUserGetter->getUserEntity();
     $userVocabulary = $this->translatorFacade->findVocabulary($englishVocabulary, $currentUser);
     if (!$userVocabulary) {
         $userVocabulary = new UserVocabulary();
     }
     return new JsonResponse(['translations' => $translationList->getTranslationsByOriginalWord($englishVocabulary), 'userVocabularyId' => $userVocabulary->getId(), 'userTranslation' => $userVocabulary->getUserTranslation(), 'explanation' => $userVocabulary->getExplanation(), 'note' => $userVocabulary->getNote()]);
 }
コード例 #2
0
ファイル: PractisingFacade.php プロジェクト: netucz/slovicka
 public function storeAnswer($answeredCorrectly, UserVocabulary $userVocabulary)
 {
     $now = $this->dateTimeFactory->getCurrentDateTime();
     $answer = new Answer($answeredCorrectly, $userVocabulary, $now->toDateTime());
     $this->answerRepository->save($answer);
     if ($answeredCorrectly && $userVocabulary->getCorrectAnswers() < $this->correctAnswersLimit) {
         $userVocabulary->setLastCorrectAnswerAt($now->toDateTime());
         $userVocabulary->increaseCorrectAnswers();
         $this->userVocabularyRepository->save($userVocabulary);
     } else {
         if (!$answeredCorrectly) {
             $userVocabulary->resetCorrectAnswers();
             $this->userVocabularyRepository->save($userVocabulary);
         }
     }
 }
コード例 #3
0
 private function createUserVocabulary(Vocabulary $vocabulary, $userTranslation, $note, User $user)
 {
     $now = $this->dateTimeFactory->getCurrentDateTime();
     $userVocabulary = new UserVocabulary();
     $userVocabulary->setUser($user);
     $userVocabulary->setVocabulary($vocabulary);
     $userVocabulary->setUserTranslation($userTranslation);
     $userVocabulary->setNote($note);
     $userVocabulary->setCreatedAt($now->toDateTime());
     $this->userVocabularyRepository->save($userVocabulary);
     return $userVocabulary;
 }