Example #1
0
 protected function getJsonView($data, \Request $request)
 {
     $json = array();
     $command = $request->getVar('command');
     $factory = new Factory();
     $lotteryFactory = new \tailgate\Factory\Lottery();
     switch ($command) {
         case 'list':
             $game = Factory::getCurrent();
             if ($game) {
                 if ($game->getLotteryRun()) {
                     $json['available_spots'] = count(\tailgate\Factory\Lottery::getAvailableSpots());
                     $lottery = new \tailgate\Factory\Lottery();
                     $json['winners'] = $lottery->getTotalWinners($game->getId());
                     $json['claimed'] = $lottery->totalSpotsClaimed($game->getId());
                 } else {
                     $json['available_spots'] = $lotteryFactory->totalAvailableSpots();
                 }
             }
             break;
         case 'getCurrent':
             $json = $factory->getCurrentAsArray();
             break;
         case 'getAvailableSpots':
             $json = array('available_spots' => $factory->totalAvailableSpots());
             break;
         case 'unixtime':
             $json['unixtime'] = strtotime(filter_input(INPUT_GET, 'date', FILTER_SANITIZE_STRING));
             break;
         default:
             throw new \Exception('Unknown command');
     }
     $view = new \View\JsonView($json);
     return $view;
 }