Exemplo n.º 1
0
 public function load()
 {
     $this->deck = \App\Deck::create(['name' => 'Elite SAT Vocabulary']);
     $handle = fopen(storage_path() . '/app/Elite SAT Vocabulary.txt', 'r');
     while ($line = fgets($handle)) {
         $this->handleLine($line);
     }
 }
Exemplo n.º 2
0
 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;
         }
     }
 }
Exemplo n.º 3
0
 /**
  * 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)]);
 }
Exemplo n.º 4
0
 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]);
     }
 }
Exemplo n.º 5
0
<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', function () {
    return view('index');
});
Route::get('/api/card/{card}', function ($cardID) {
    return \App\Card::find($cardID);
});
Route::get('/api/deck/{deck}', function ($deck) {
    return \App\Deck::with("cards")->find($deck);
});
Route::get("/api/deck/class/{class}", function ($class) {
    return \App\Deck::where("playerClass", "=", $class)->get();
});
Exemplo n.º 6
0
 public function getTrains()
 {
     return Deck::create($this->trains, [Deck::DISCARD => 0, Deck::DISPLAY => 6]);
 }
Exemplo n.º 7
0
 /**
  * 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']);
 }
Exemplo n.º 8
0
 public function setTrainDeckAttribute($value)
 {
     Deck::serialize($value);
     $this->attributes['train_deck'] = $value;
 }
Exemplo n.º 9
0
 public function globalDecks(Request $request)
 {
     $decks = \App\Deck::all();
     return $decks;
 }