예제 #1
0
 public function scopeInVote($query)
 {
     $current = Voting::current();
     if ($current->count() > 0) {
         $current = $current->first();
         // $previous = Voting::where('ended', '<', $current->created_at);
         $query = $query->whereVoted(false)->where('created_at', '<=', $current->created_at);
         /*if ($previous->count() > 0) {
             $previous = $previous->first();
             $query = $query->where('created_at', '>', $previous->ended);
           }*/
         return $query->orderBy('created_at', 'desc');
     }
     return $query;
 }
예제 #2
0
 public function getStart()
 {
     // Needs logged in user with voting privileges
     if (!(Auth::check() && Auth::user()->canStartVoting())) {
         return Redirect::to('/');
     }
     $current = Voting::current()->get();
     if (count($current) == 0) {
         if (Song::requests()->count() > 0) {
             $voting = new Voting();
             $voting->created_by = Auth::user()->id;
             $voting->save();
         } else {
             Session::flash('error', 'Geen nummers om over te stemmen! D:');
         }
     }
     return Redirect::to('/vote');
 }
예제 #3
0
 function postEndVoting()
 {
     $search = Voting::current();
     if ($search->count() > 0) {
         $voting = $search->first();
         $voting->ended = date("Y-m-d H:i:s");
         $voting->save();
         return Response::json(true);
     }
     return Response::json(false);
 }