コード例 #1
0
 public function store(Request $request)
 {
     if (!($count = $this->redis->get(COUNTER_KEY))) {
         $count = Votes::count();
     }
     $vote = new Votes();
     $vote->ip_address = $request->getClientIp();
     if ($vote->save()) {
         $count = (int) $count + 1;
         $this->redis->set(COUNTER_KEY, $count);
     }
     // Set session
     session(['voted' => true]);
     $total = str_pad($count, 6, 0, STR_PAD_LEFT);
     echo $total;
 }
コード例 #2
0
ファイル: Votes.php プロジェクト: JolitaGrazyte/webdev_examen
 public static function winners($p)
 {
     $winners = Votes::whereHas('image', function ($q) use($p) {
         $q->where('created_at', '>', $p['start'])->where('created_at', '<=', $p['end']);
     })->with('image.author')->select('image_id', DB::raw('COUNT(image_id) as count'))->groupBy('image_id')->orderBy('count', 'desc')->take(3)->get();
     return $winners;
 }
コード例 #3
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $user = User::where('role', 0)->first();
     $past_period = Period::past()->latest('end')->first();
     //        dd(Carbon::now('Europe/Brussels')->format('Y-m-d H'));
     //        dd($isTrue = $past_period->end->format('Y-m-d H'));
     //        dd($isTrue = $past_period->end->format('Y-m-d H') == Carbon::now('Europe/Brussels')->format('Y-m-d H'));
     $isTrue = $past_period->end->format('Y-m-d H') == Carbon::now('Europe/Brussels')->format('Y-m-d H');
     if ($isTrue) {
         $winners['Period ' . $past_period->id . ' (' . $past_period->start . ' - ' . $past_period->end . ')'] = Votes::winners($past_period);
         $data = ['winners' => $winners, 'user' => $user];
         Mail::send('emails.notification', $data, function ($m) use($user) {
             $m->from('*****@*****.**', 'Zeal Optics')->to($user->email, $user->username)->subject('Ski Goggles Game Winners!');
         });
     }
 }
コード例 #4
0
 public function postVotes(Request $request)
 {
     $img_id = $request->get('image_id');
     $ip = $request->getClientIp();
     $exist = Votes::where('ip', $ip)->where('image_id', $img_id)->exists();
     if (!$exist) {
         $vote = Votes::create($request->all());
         $vote->ip = $ip;
         $vote->save();
         Session::flash('message', "Thank you for voting!");
         Session::flash('alert-class', 'alert-success');
     } else {
         Session::flash('message', "No cheating !!! You can't vote for the same image more then ONE time!!!");
         Session::flash('alert-class', 'alert-warning');
     }
     return redirect()->route('home');
 }
コード例 #5
0
ファイル: HomeController.php プロジェクト: usragung/E-Vote
 public function checkVoteStatus($username)
 {
     $vote = Votes::where(['username' => $username])->get();
     return $vote;
 }
コード例 #6
0
ファイル: Page.php プロジェクト: alex4ndru/proiectbitacad
 public function servePetitiiVoteAgainst($id)
 {
     $data = Request::all();
     $citizen = Auth::user()->toArray();
     $where = ['citizenId' => $citizen['id'], 'petitionId' => $id];
     $votedBefore = Citizensvotes::where($where)->get()->first();
     if ($votedBefore === null) {
         //inregistrare vot in lista
         $row = new Votes();
         $row->petitionId = $id;
         $row->voteNo = 1;
         $row->save();
         //marcare citizen ca a votat pe aceasta petitie
         $row = new Citizensvotes();
         $row->citizenId = $citizen['id'];
         $row->petitionId = $id;
         $row->save();
         return redirect('petitii')->with(['userName' => $this->userName, 'logIn' => $this->logIn, 'logOut' => $this->logOut]);
     } else {
         echo "can't vote again !";
     }
 }
コード例 #7
0
 /**
  *  Method to post vote for answers.
  * @param Request $request
  * @return \Illuminate\Http\RedirectResponse
  */
 public function postVote(Request $request)
 {
     $user = Auth::user();
     $vote = new Votes();
     $voteable_id = $request->get('voteable_id');
     $exist = $vote->voteExists($user->id, $voteable_id, 'App\\Post');
     if (!$exist) {
         $vote = $vote->create(['voteable_id' => $voteable_id, 'voteable_type' => 'App\\Post']);
         $user->votes()->save($vote);
         Session::flash('message', "Thank you for voting!");
         Session::flash('alert-class', 'alert-success');
     } else {
         Session::flash('message', "Maybe you have forgotten, but you already have voted for this question.");
         Session::flash('alert-class', 'alert-warning');
     }
     return redirect()->back();
 }
コード例 #8
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $vote = Votes::findOrFail($id);
     $vote->delete();
     return redirect()->back();
 }
コード例 #9
0
 public function getDownvotes($id)
 {
     $proposition = Proposition::find($id);
     $downvotes = 0;
     $downvotes = Votes::wherePropositionIdAndVoteValue($proposition->propositionId(), 0)->get();
     $downvotesSum = 0;
     foreach ($downvotes as $downvote) {
         $downvotesSum++;
     }
     return $downvotesSum;
 }
コード例 #10
0
 /**
  * Update to increase the downvotes of a link.
  *
  * @param  int  $id
  * @return Response
  */
 public function downvote($id)
 {
     //retrieve entry for current link
     if (is_null(Votes::where(['userid' => Auth::user()->id, 'linkid' => $id])->first())) {
         $link = Links::find($id);
         $link->downvotes += 1;
         $link->save();
         $newVote = Votes::create(['linkid' => $id, 'userid' => Auth::user()->id, 'vote' => -1]);
         $newVote->save();
     } else {
         return redirect()->action('LinkController@index')->withErrors(['You have already voted.']);
     }
     return redirect()->action('LinkController@index');
 }