private function canAdd(\App\User $user, $request) { if (\App\Subscription::isSubscribed($user)) { return true; } else { $deck = \App\Deck::find($request->id); if ($deck->users->count() >= DeckAddUser::USER_LIMIT) { return false; } else { return true; } } }
/** * Show the statistics for the entire deck. Can only be accessed if the user has edit permissions on the deck. * @param Request $request - a HTTP request * @param $id - id of the deck. */ public function deckStats(Request $request, $id) { $deck = \App\Deck::find($id); $deckStatsCalculator = new \App\Stats\DeckStatsCalculator($deck); $numUsers = $deckStatsCalculator->numUsers(); $totalTime = $deckStatsCalculator->totalTime(); $totalInteractions = $deckStatsCalculator->totalInteractions(); $mostDifficultConcepts = $deckStatsCalculator->mostDifficultConcepts(); $mostIntuitiveConcepts = $deckStatsCalculator->mostIntuitiveConcepts(); $mostDifficultCards = $this->convertArrayKeysToFlashcards($mostDifficultConcepts); $mostIntuitiveCards = $this->convertArrayKeysToFlashcards($mostIntuitiveConcepts); $accuracy = $deckStatsCalculator->accuracy(); return view('stats.deck')->with(['deck' => $deck, 'numUsers' => $numUsers, 'totalTime' => $totalTime, 'totalInteractions' => $totalInteractions, 'mostDifficultConcepts' => $mostDifficultConcepts, 'mostIntuitiveConcepts' => $mostIntuitiveConcepts, 'mostDifficultCards' => $mostDifficultCards, 'mostIntuitiveCards' => $mostIntuitiveCards, 'accuracy' => round($accuracy * 100)]); }
public function next(Request $request, $id, $type) { if (!$this->isValidSessionType($type)) { return response('Not found.', 404); } $sessionManager = Session::get('sessionManager'); try { $remainingFlashcards = $sessionManager->remainingFlashcards(); } catch (\InvalidArgumentException $e) { return 'Error'; } try { $totalFlashcards = $sessionManager->getTotalFlashcards(); } catch (\InvalidArgumentException $e) { return 'Error'; } $user = $request->user(); $deck = \App\Deck::find($id); $fromWhence = Session::get('fromWhence'); $answer = new \App\Answer($request->answer, $fromWhence); if ($info = $sessionManager->next($answer)) { if ($info['next'] instanceof \App\QuestionAnswer) { Session::put('fromWhence', 'multiple-choice'); return view('session.' . $type)->with(['type' => $type, 'deck' => $deck, 'question' => $info['next']->getQuestion(), 'answers' => $info['next']->getChoices(), 'cardtype' => $info['next']->getCardtype(), 'previouslyCorrect' => $info['previouslyCorrect'], 'remainingFlashcards' => $remainingFlashcards, 'totalFlashcards' => $totalFlashcards]); } else { if ($info['next'] instanceof \App\Flashcard) { Session::put('fromWhence', 'card'); return view('session.card')->with(['card' => $info['next'], 'type' => $type, 'deck' => $deck, 'previouslyCorrect' => $info['previouslyCorrect'], 'remainingFlashcards' => $remainingFlashcards, 'totalFlashcards' => $totalFlashcards]); } } } else { $sessionManager->end(); $sessionCalculator = new \App\Stats\SessionStatsCalculator($sessionManager->getSession()); $time = $sessionCalculator->totalTime(); $cardsInteractedWith = $sessionCalculator->totalInteractions(); $accuracy = $sessionCalculator->accuracy(); $timePerCard = $cardsInteractedWith == 0 ? 0 : $time / $cardsInteractedWith; return view('session.complete')->with(['deck' => $deck, 'time' => $time, 'cardsInteractedWith' => $cardsInteractedWith, 'accuracy' => $accuracy, 'timePerCard' => $timePerCard]); } }
/** * Copy a deck to this user */ public function copyDeck(Request $request) { $id = $request->id; $deck = Deck::find($id); $newDeck = $deck->clone(); Auth::user()->decks()->save($newDeck, ['permissions' => 'edit']); }