Пример #1
0
 public function getIndex()
 {
     // Needs logged in user with voting privileges
     if (!(Auth::check() && Auth::user()->canStartVoting())) {
         return Redirect::to('/');
     }
     $songs = Song::requests()->get();
     $current = Voting::current();
     if ($current->count() == 0) {
         return View::make('vote.index', array('songs' => $songs));
     } else {
         $songs = Song::inVote()->get();
         $voting = $current->first();
         $voting->created_by = User::find($voting->created_by)->username;
         // Randomize songs
         $songs = $songs->all();
         // Seed randomizer with voting ID to ensure consistent song order
         mt_srand($voting->id);
         $order = array_map(create_function('$val', 'return mt_rand();'), range(1, count($songs)));
         array_multisort($order, $songs);
         return View::make('vote.voting', array('css' => array('voting'), 'javascripts' => array('voting'), 'songs' => $songs, 'voting' => $voting));
     }
 }