Esempio n. 1
2
 function changeVote()
 {
     $user_id = Auth::user()->id;
     $content_id = Input::get('content_id');
     $content = Input::get('content');
     $vote = Input::get('vote');
     if (!($vote == 1 || $vote == -1)) {
         return back();
     } else {
         $voteObject = Vote::where('user_id', $user_id)->where('content_id', $content_id)->where('content', $content)->first();
         if ($voteObject) {
             $results[] = ['message' => "Daha önce oy verilmiş!", 'vote' => $voteObject->vote, 'div_id' => 'vote_' . $content . '_' . $content_id];
             return Response::json($results);
         } else {
             $votes = Vote::where('content_id', $content_id)->where('content', $content)->get(['vote']);
             if ($votes) {
                 $oldVote = 0;
                 foreach ($votes as $vote_t) {
                     $oldVote += $vote_t['vote'];
                 }
             } else {
                 $oldVote = 0;
             }
             $newVote = new Vote();
             $newVote->user_id = $user_id;
             $newVote->content_id = $content_id;
             $newVote->content = $content;
             $newVote->vote = $oldVote + $vote;
             $newVote->save();
             $results[] = ['message' => 0, 'vote' => $newVote->vote, 'div_id' => 'vote_' . $content . '_' . $content_id];
             return Response::json($results);
         }
     }
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $vote = new Vote();
     $vote->ip = "192.168.56.100";
     $vote->competitors()->associate(1);
     // $vote->users()->associate(1);
     $vote->save();
 }
 public function first($id)
 {
     $user = DB::table('votes')->where('user_id', '=', Auth::user()->id)->where('artikel_id', '=', $id)->first();
     if (is_null($user)) {
         $vote = new Vote();
         $vote->artikel_id = $id;
         $vote->user_id = Auth::user()->id;
         $vote->save();
     }
 }
Esempio n. 4
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store($aid, $vote1)
 {
     $id = Auth::id();
     $vote2 = Vote::all();
     foreach ($vote2 as $v) {
         if ($v->aid == $aid && $v->id == $id) {
             $voter = Vote::find($v->id);
             $voter->delete();
         }
     }
     $vote = new Vote();
     $vote->aid = $aid;
     $vote->id = $id;
     $vote->value = $vote1;
     $vote->save();
     return redirect()->back();
 }
Esempio n. 5
0
 public function vote($subName, $slug, $value)
 {
     if (!in_array($value, [-1, 0, 1])) {
         abort(400);
     }
     $sub = Sub::where('name', $subName)->firstOrFail();
     $post = Post::where('slug', $slug)->where('sub_id', $sub->id)->firstOrFail();
     try {
         $vote = $post->votes()->where('user_id', auth()->id())->firstOrFail();
     } catch (ModelNotFoundException $e) {
         $vote = new Vote();
     }
     $vote->value = $value;
     $vote->user()->associate(auth()->user());
     $vote->voteable()->associate($post);
     $vote->save();
     $post->score += $value;
     $post->save();
 }
Esempio n. 6
0
 public function postSave(Request $request)
 {
     $inputs = $request->all();
     $vote = new Vote();
     $vote->title = $inputs['title'];
     $vote->description = $this->nl2p($inputs['description']);
     $vote->template_id = $inputs['template'];
     $vote->is_active = $inputs['is_active'];
     $vote->user_id = Auth::user()->id;
     if ($vote->save()) {
         return redirect('vote/list')->with('status', '投票添加成功');
     } else {
         return back()->withErrors('投票添加失败');
     }
 }
Esempio n. 7
0
 public function voteTabDown($id)
 {
     $t = Song_data::findOrFail($id);
     $idUser = \Auth::user()->id;
     var_dump($id);
     var_dump($idUser);
     $checkVote = Vote::where('votable_id', $id)->where('user_id', $idUser)->where('votable_type', 'App\\Song_data')->get();
     if ($checkVote->isEmpty()) {
         $v = new Vote();
         $v->vote = -1;
         $v->user()->associate(\Auth::user());
         $v->votable_id = $id;
         $v->votable_type = "App\\Song_data";
         $v->save();
     } else {
         $checkVote = Vote::where('votable_id', $id)->where('user_id', $idUser)->where('votable_type', 'App\\Song_data')->where('vote', 1)->first();
         $checkVote->vote = -1;
         $checkVote->save();
     }
 }
 /**
  * Downvoting answer
  *
  * @param Question $question
  * @param Answer   $answer
  */
 public function answerDownvote(Question $question, Answer $answer)
 {
     if (!Auth::check()) {
         return Redirect::route("ask.show", [$question->id, $question->slug]);
     }
     if ($answer->votes->where("user_id", Auth::user()->id)->count() > 0) {
         return Redirect::route("ask.show", [$question->id, $question->slug]);
     }
     $vote = new Vote();
     $vote->user_id = Auth::user()->id;
     $vote->answer_id = $answer->id;
     $vote->type = false;
     $vote->save();
     return Redirect::route("ask.show", [$question->id, $question->slug]);
 }
Esempio n. 9
0
 public function addVote(Request $request)
 {
     $this->validate($request, ['g-recaptcha-response' => 'required|recaptcha']);
     $id = $request->input('server_id');
     $settings = Setting::find(1);
     $interval = $settings->voteInterval;
     $ip = getHostByName(php_uname('n'));
     //Check if user alredy voted in 24h
     $vote = Vote::where('ip', $ip)->first();
     if ($vote != null) {
         if ($vote->updated_at->addHours($interval) > Carbon::now()) {
             //already voted
             return redirect('server/' . $id)->withErrors('You have already voted. Now you can vote after ' . $interval . ' hours from your voting time');
         }
     }
     //Deletes old record
     Vote::where('ip', $ip)->delete();
     $server = serverModel::where('id', $id)->first();
     $votes = $server->votes;
     $server->votes = $votes + 1;
     $server->save();
     $vote = new Vote();
     $vote->ip = $ip;
     $vote->save();
     return redirect('server/' . $id)->with('status', 'You have successfully voted!');
 }
 public function save()
 {
     if (Auth::check()) {
         $title = Request::input('title');
         $body = Request::input('body');
         $public = Request::input('public');
         $type = Request::input('type');
         $teams = Request::input('teams');
         $license = Request::input('license');
         $identifier_dict = Request::input('identifier');
         $anchor = Request::input('anchor');
         $entry_id = Request::input('entry_id');
         $user = Auth::user();
         if ($title !== '' && $body !== '' && $type !== '' && !empty($identifier_dict) && $anchor !== '') {
             $db_license = NULL;
             if ($public) {
                 if (isset($_ENV['AUTH_LICENSES']) && $_ENV['AUTH_LICENSES']) {
                     if (empty($license)) {
                         return json_encode(['status' => 'error', 'message' => 'Only paid users can create public annotations']);
                     }
                     $json_license = json_encode($license);
                     $db_license = License::where('license', '=', $json_license)->first();
                     if ($db_license) {
                         if ($db_license->banned_from_public) {
                             if (isset($license['is_beta']) && $license['is_beta']) {
                                 return json_encode(['status' => 'error', 'message' => "Beta users can't make public annotations"]);
                             }
                             return json_encode(['status' => 'error', 'message' => 'You are banned from making public annotations']);
                         }
                     } else {
                         if (isset($license['is_beta']) && $license['is_beta']) {
                             // skip check for beta users
                         } else {
                             if (isset($license['is_app_store']) && $license['is_app_store']) {
                                 if (!DashLicenseUtil::check_itunes_receipt($license)) {
                                     return json_encode(['status' => 'error', 'message' => 'Invalid license. Public annotation not allowed']);
                                 }
                             } else {
                                 if (!DashLicenseUtil::check_license($license)) {
                                     return json_encode(['status' => 'error', 'message' => 'Invalid license. Public annotation not allowed']);
                                 }
                             }
                         }
                         $db_license = new License();
                         $db_license->license = $json_license;
                         $db_license->save();
                     }
                 }
             }
             $identifier = Identifier::IdentifierFromDictionary($identifier_dict);
             $db_identifier = $identifier->find_in_db();
             if (!$db_identifier) {
                 $identifier->save();
                 $db_identifier = $identifier;
             }
             if ($public && $db_identifier->banned_from_public) {
                 return json_encode(['status' => 'error', 'message' => 'Public annotations are not allowed on this page']);
             }
             $entry = $entry_id ? Entry::where('id', '=', $entry_id)->first() : new Entry();
             if ($entry_id && (!$entry || $entry->user_id != $user->id)) {
                 return json_encode(['status' => 'error', 'message' => 'Error. Logout and try again']);
             }
             $entry->title = $title;
             $entry->body = $body;
             try {
                 $body = MarkdownExtra::defaultTransform($body);
             } catch (\RuntimeException $e) {
                 $message = $e->getMessage();
                 $start = strpos($message, 'no lexer for alias \'');
                 if ($start !== FALSE) {
                     $start += 20;
                     $end = strpos($message, '\'', $start);
                     if ($end !== FALSE) {
                         $lexer = substr($message, $start, $end - $start);
                         return json_encode(['status' => 'error', 'message' => 'Unknown syntax highlighting: ' . $lexer]);
                     }
                 }
                 throw $e;
             }
             $html_safe = new HTML_Safe();
             $html_safe->protocolFiltering = 'black';
             $body = $html_safe->parse($body);
             $body = str_replace('#dashInternal', '#', $body);
             $entry->body_rendered = $body;
             $entry->public = $public;
             $entry->type = $type;
             $entry->anchor = $anchor;
             $entry->user_id = $user->id;
             $entry->identifier_id = $db_identifier->id;
             if ($db_license) {
                 $entry->license_id = $db_license->id;
             }
             if (!$entry_id) {
                 $entry->score = 1;
             }
             $entry->save();
             if (!$entry_id) {
                 $vote = new Vote();
                 $vote->type = 1;
                 $vote->user_id = $user->id;
                 $vote->entry_id = $entry->id;
                 $vote->save();
             }
             $db_teams = $entry->teams();
             $already_assigned = array();
             foreach ($db_teams->get() as $team) {
                 if (!in_arrayi($team->name, $teams)) {
                     $db_teams->detach($team->id);
                 } else {
                     $already_assigned[] = $team->name;
                 }
             }
             foreach ($teams as $team) {
                 if (!in_arrayi($team, $already_assigned)) {
                     $db_team = Team::where('name', '=', $team)->first();
                     if ($db_team && $db_team->users()->where('user_id', '=', $user->id)->first()) {
                         $db_team->entries()->attach($entry->id);
                     }
                 }
             }
             return json_encode(['status' => 'success', 'entry' => $entry]);
         }
         return json_encode(['status' => 'error', 'message' => 'Oops. Unknown error']);
     }
     return json_encode(['status' => 'error', 'message' => 'Error. Logout and try again']);
 }
 public function vote(Request $request)
 {
     $imageId = $request->input('voteImageId');
     $image = Image::where('id', '=', $imageId)->first();
     $votes = Auth::user()->votes()->get();
     $voted = 0;
     foreach ($votes as $vote) {
         if ($vote->image_id == $imageId) {
             $image->vote_count = $image->vote_count - 1;
             $image->save();
             $vote->delete();
             $voted = 1;
         }
     }
     if ($voted == 1) {
         return Redirect::to('feed');
     } else {
         $newVote = new Vote();
         $newVote->user_id = Auth::user()->id;
         $newVote->image_id = $imageId;
         $newVote->save();
         $image->vote_count = $image->vote_count + 1;
         $image->save();
         return Redirect::to('feed');
     }
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit($id, Request $request)
 {
     //FXMM 03-12-2015: In this part we're having the validations of voters
     $value = 1;
     if ($id <= 0) {
         $value = -1;
         $id = $id * -1;
     }
     //lets check if we already voted for this url.
     $link = Link::find($id);
     $CurrentUser = $request->user();
     $votes = DB::table('uservotes')->select(DB::raw('count(*) as user_count'))->where('LinkID', '=', $link->id)->where('UserID', '=', $CurrentUser->id)->groupBy('UserID')->count();
     if ($votes == 0) {
         $link->Rating += $value;
         $link->save();
         $vote = new Vote();
         $vote->LinkID = $link->id;
         $vote->UserID = $CurrentUser->id;
         $vote->RatingValue = 1;
         $vote->save();
         //In case you haven't vote, the application will save your vote
         Session::flash('message', 'Rating succesfully saved! USER ID:' . $CurrentUser->id);
     } else {
         Session::flash('message', 'Cant be saved, already voted! USER ID: ' . $CurrentUser->id);
     }
     // redirect
     return Redirect::to('links');
 }
Esempio n. 13
0
 /**
  * Thumbs down a post
  *
  * @param  Request  $request
  * @return Response (JSON)
  */
 public function down(Request $request, Post $post)
 {
     $address = request()->ip();
     foreach ($this->votes->forPost($post) as $vote) {
         if ($vote->address === $address) {
             return response()->json(['votes' => $post->voteCount, 'error' => 'This IP Address has already voted on this post']);
         }
     }
     $vote = new Vote();
     $vote->address = $address;
     $vote->post_id = $post->id;
     $vote->save();
     $post->voteCount = $post->voteCount - 1;
     $post->save();
     return response()->json(['votes' => $post->voteCount]);
 }
Esempio n. 14
0
 /**
  * You can't delete a vote, just switch to abstain
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy(Vote $vote)
 {
     if (!Auth::user()->can('create-votes')) {
         abort(401, "user can not create or destroy votes");
     }
     if ($vote->user_id != Auth::user()->id) {
         abort(401, "User does not have permission to destroy another users vote");
     }
     $vote->position = 0;
     $vote->save();
     return $vote;
 }
Esempio n. 15
0
 public function vote(Request $request)
 {
     if ($request->anonymous) {
         $adventure = Adventure::findOrFail($request->id);
         $adventure->increment('anonymous_votes');
         $adventure->increment('all_votes');
         $adventure->save();
     } else {
         $adventure = Adventure::findOrFail($request->id);
         $adventure->increment('anonymous_votes');
         $adventure->increment('all_votes');
         $adventure->save();
         $vote = new Vote();
         $vote->adventure_id = $request->id;
         $vote->user_id = Auth::user()->id;
         $vote->save();
     }
     return redirect('adventures');
 }
 public function testajax()
 {
     $user = Competitor::all();
     $vote = new Vote();
     $vote->ip = "lolz nope";
     $vote->competitor_id = $user->first()->id;
     $vote->save();
     return json_encode($user);
 }
Esempio n. 17
0
 private function vote($topicId, $value)
 {
     if ($topicId) {
         $topic = Topic::find($topicId);
         $topic->vote = $topic->vote + 1;
         $topic->save();
         $vote = new Vote();
         $vote->topic_id = $topicId;
         $vote->voter_id = $this->user->id;
         $vote->value = $value;
         $vote->save();
         return response()->json($vote, 200);
     } else {
         return response()->json(['error' => "topicId not found!"], 404);
     }
 }