/** * @EXT\Route( * "/session/create/deck/{deck}", * name="claroline_create_session" * ) * * @param Deck $deck * * @return JsonResponse */ public function createSessionAction(Deck $deck) { $this->assertCanOpen($deck); $user = $this->tokenStorage->getToken()->getUser(); $session = new Session(); $session->setDeck($deck); $session->setUser($user); $session = $this->manager->save($session); $context = new SerializationContext(); $context->setGroups('api_flashcard_session'); return new JsonResponse(json_decode($this->serializer->serialize($session, 'json', $context))); }
/** * @EXT\Route( * "/cancel_last_study/deck/{deck}/session/{sessionId}/card/{card}", * name="claroline_cancel_last_study" * ) * * @param Deck $deck * @param int $sessionId * @param Card $card * * @return JsonResponse */ public function cancelStudyCardAction(Deck $deck, $sessionId, Card $card) { $this->assertCanOpen($deck); $user = $this->tokenStorage->getToken()->getUser(); $cardLearning = $this->cardLearningMgr->getCardLearning($card, $user); $lastCardLog = $this->cardLogMgr->getLastLog($card, $user); if ($lastCardLog) { $cardLearning->setFactor($lastCardLog->getFactor()); $cardLearning->setPainful($lastCardLog->getPainful()); $cardLearning->setNumberRepeated($lastCardLog->getNumberRepeated()); $cardLearning->setDueDate($lastCardLog->getDueDate()); $this->cardLearningMgr->save($cardLearning); $this->cardLogMgr->delete($lastCardLog); } else { $this->cardLearningMgr->delete($cardLearning); } // Save the session if ($sessionId > 0) { $session = $this->sessionMgr->get($sessionId); } else { $session = new Session(); $session->setDeck($deck); $session->setUser($user); } $session->deleteCard($card); // We dont upgrade the duration of the session $session = $this->sessionMgr->save($session); return new JsonResponse($session->getId()); }