コード例 #1
2
ファイル: VoteController.php プロジェクト: WPTEbilkent/WPTE
 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);
         }
     }
 }
コード例 #2
0
ファイル: VoteController.php プロジェクト: enhive/vev
 public function destroy(Post $post)
 {
     $vote = Vote::where(['post_id' => $post->id, 'user_id' => Auth::user()->id])->first();
     $vote->delete();
     $post->decrement('vote_count');
     return response([]);
 }
コード例 #3
0
 /**
  * Store a newly created resource in storage. Requires a post with 'comment_id' and 'position'
  *
  * @return Response
  */
 public function store()
 {
     //Check user permissions
     if (!Auth::user()->can('create-comment_votes')) {
         abort(401, 'You do not have permission to vote on a comment');
     }
     //Check validation
     $input = Request::all();
     if (!isset($input['comment_id'])) {
         abort(422, 'comment_id is required');
     }
     //Gets the comment that is to be voted on
     $comment = Comment::find($input['comment_id']);
     //Does the fields specified as fillable in the model
     if (!$comment) {
         abort(403, 'There is no comment with the id of ' . $input['comment_id']);
     }
     //Check logged in user has voted, and on this comment's motion
     $vote = Vote::where('user_id', Auth::user()->id)->where('motion_id', $comment->motion_id)->first();
     if (!$vote) {
         abort(403, 'User must vote before posting comment');
     }
     $commentVote = new CommentVote($input);
     $commentVote->comment_id = $comment->id;
     $commentVote->vote_id = $vote->id;
     if (!$commentVote->save()) {
         abort(403, $commentVote->errors);
     }
     return $commentVote;
 }
コード例 #4
0
 public function showByUser($user_id)
 {
     //directly copied pasted from list controller.
     $list = Vote::where('user_id', '=', $user_id)->get();
     $user_list = [];
     foreach ($list as $pro) {
         $product_id = $pro->product_id;
         $product = Product::find($product_id);
         if ($product != null) {
             $created_by = $product['created_by'];
             $category = Category::find($product['category_id']);
             $category = $category['category'];
             $user = User::find($created_by);
             array_add($product, 'category', $category);
             array_add($product, 'created_by_name', $user['name']);
             $initial = explode(".", $product['image_url']);
             $thumbFirst = "";
             for ($i = 0; $i < sizeof($initial) - 1; $i++) {
                 $thumbFirst = $thumbFirst . $initial[$i];
             }
             $thumbnail = $thumbFirst . '-200x200.' . $initial[sizeof($initial) - 1];
             array_add($product, 'thumbnail', $thumbnail);
             array_push($user_list, $product);
         }
     }
     return $user_list;
     //        return response()->json([
     //                'upvotted'=>$user_list]
     //        );
 }
コード例 #5
0
 public function store($topicId, Request $request)
 {
     $data = ['user_id' => Auth::user()->id, 'topic_id' => $topicId];
     if (Vote::where($data)->count() > 0) {
         return response('', 204);
     }
     Vote::create($data);
     return response('', 200);
 }
コード例 #6
0
 public function displayTab($nameTitle)
 {
     $name = Song_data::where('song', $nameTitle)->get();
     $id = Song_data::where('song', $nameTitle)->pluck('id');
     $voteCount = Vote::where('votable_id', $id)->where('votable_type', 'App\\Song_data')->sum('vote');
     $title1 = $nameTitle;
     $title = 'Tab';
     return view('viewTab')->with('LastTenTabs', $name)->with('title1', $title1)->with('title', $title)->with('voteCount', $voteCount);
 }
コード例 #7
0
ファイル: Vote.php プロジェクト: jenidarnold/racquetball
 /**
  *  Get votes for all skills
  */
 public static function hasVote($voter_id, $skill_id, $player1, $player2)
 {
     $vote = Vote::where('voter_id', '=', $voter_id)->where('skill_id', '=', $skill_id)->where('for_id', '=', $player1)->where('against_id', '=', $player2)->count();
     if ($vote > 0) {
         return "true";
     } else {
         return "false";
     }
 }
コード例 #8
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index($user)
 {
     $limit = Request::get('limit') ?: 100;
     if (Auth::user()->id != $user->id && !$user->public && !Auth::user()->can('show-votes')) {
         //Not the current user, or public and not an admin
         abort(401, "You do not have permission to view this non-public user's votes");
     }
     $votes = Vote::where('user_id', $user->id)->active()->with('motion')->paginate($limit);
     return $votes;
 }
コード例 #9
0
 /**
  * A funciton that usually runs recursively up the vote chain
  *
  * @param  VoteCreated  $event
  * @return void
  */
 public function handle($event)
 {
     $vote = $event->vote;
     // \DB::enableQueryLog();
     //DB::enableQueryLogging();
     // \DB::table('votes')->where('deferred_to_id',$vote->user_id)->where('motion_id',$vote->motion_id)->update(['position'=>$vote->position]);
     $deferredVotes = Vote::where('deferred_to_id', $vote->user_id)->where('motion_id', $vote->motion_id)->get();
     //update(['position'=>$vote->position]);
     //  echo print_r(\DB::getQueryLog());
     foreach ($deferredVotes as $deferredVote) {
         // echo "\br HERE ".$deferredVote;
         $deferredVote->position = $vote->position;
         $deferredVote->save();
     }
 }
コード例 #10
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index($motion)
 {
     $passiveVotes = Vote::where('motion_id', $motion->id)->cast()->passive()->get()->groupBy('deferred_to_id');
     $votesCount = array();
     $totalVotes = Vote::where('motion_id', $motion->id)->cast()->count();
     foreach ($passiveVotes as $id => $vote) {
         $count = count($vote);
         $votesCount[$vote[0]->position]['passive']['number'] = $count;
         $votesCount[$vote[0]->position]['passive']['percent'] = floor($count / $totalVotes * 100);
     }
     $activeVotes = Vote::where('motion_id', $motion->id)->cast()->active()->get()->groupBy('position');
     foreach ($activeVotes as $id => $vote) {
         $count = count($vote);
         $votesCount[strval($id)]['active']['number'] = $count;
         $votesCount[strval($id)]['active']['percent'] = floor($count / $totalVotes * 100);
     }
     return $votesCount;
 }
コード例 #11
0
 public function postSubmitVote(Request $request)
 {
     return redirect()->action('HomeController@getGameOver');
     if (!Auth::id()) {
         return response()->json(['message' => 'user not found'], 400);
     }
     $profile = Profile::where('id', '=', $request->input('profileId'))->first();
     if (!$profile || $profile->isActive != 1) {
         return response()->json(['message' => 'profile not found'], 400);
     }
     $vote = Vote::where(['user_id' => Auth::id(), 'profile_id' => $request->input('profileId')])->first();
     if (!$vote || $vote->isActive == 1) {
         return response()->json(['message' => 'cannot change vote'], 400);
     }
     $vote->isActive = 1;
     $vote->save();
     return response()->json(['message' => 'validEntry'], 201);
 }
コード例 #12
0
ファイル: VoteController.php プロジェクト: dwoodard/IserveU
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     //Check if the user has permission to cast votes
     if (!Auth::user()->can('create-votes')) {
         abort(401, 'You do not have permission to create a vote');
     }
     //Check if vote exists
     $vote = Vote::where('user_id', Auth::user()->id)->where('motion_id', Request::input('motion_id'))->first();
     if ($vote) {
         $vote->position = Request::input('position');
     } else {
         $vote = new Vote(Request::all());
         $vote->user_id = Auth::user()->id;
     }
     if (!$vote->save()) {
         abort(403, $vote->errors);
     }
     return $vote;
 }
コード例 #13
0
ファイル: MotionController.php プロジェクト: dwoodard/IserveU
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show(Motion $motion)
 {
     if (Auth::check()) {
         Vote::where('motion_id', $motion->id)->where('user_id', Auth::user()->id)->update(['visited' => true]);
     }
     return $motion;
 }
コード例 #14
0
ファイル: NominationController.php プロジェクト: rxfu/vote
 public function getEdit($id)
 {
     $nomination = Nomination::find($id);
     $votes = Vote::where('is_active', '=', true)->get();
     return view('nomination.edit', ['title' => '编辑' . $nomination->title, 'nomination' => $nomination, 'votes' => $votes]);
 }
コード例 #15
0
 public function postRemoveVote(Request $request)
 {
     if (!Auth::id()) {
         return response()->json(['message' => 'user not found'], 400);
     }
     $profile = Profile::where("id", "=", $request->input("profileId"))->first();
     if (!$profile || $profile->isActive != 1) {
         return response()->json(['message' => 'profile not found'], 400);
     }
     $vote = Vote::where(['user_id' => Auth::id(), 'profile_id' => $request->input("profileId")])->first();
     if (!$vote || $vote->isActive == 1) {
         return response()->json(['message' => 'cannot change vote'], 400);
     }
     unlink(public_path() . generatePhotoURL('full', $vote->photo, true));
     unlink(public_path() . generatePhotoURL('thumb_80', $vote->photo, true));
     unlink(public_path() . generatePhotoURL('thumb_132', $vote->photo, true));
     $profile->photo = '';
     $vote->save();
     return response()->json(['message' => 'removed'], 201);
 }
コード例 #16
0
 public function downvote($id)
 {
     if (Request::ajax()) {
         $post = Post::find($id);
         $_upvote_handle = Vote::where('object_id', '=', Auth::id())->where('type', '=', 'upvote')->where('post_id', '=', $id)->first();
         if ($_upvote_handle) {
             $_upvote_handle->delete();
             $_notification_handle = Notification::where('type', '=', 'post')->where('object_id', '=', $id)->where('sender_id', '=', Auth::id())->where('user_id', '=', $post->author_id)->first();
             $_notification_handle->delete();
         }
         $post->newVote()->withType('downvote')->regarding(Auth::user())->deliver();
         $user = Auth::user();
         $post_author = User::find($post->author_id);
         $post_author->newNotification()->withType('post')->withSender($user->id)->withSubject($user->name . ' ' . $user->surname . ' downvoted your post.')->withBody('"' . $post->body . '"')->regarding($post)->deliver();
         return array('data1' => $post->votes()->type('downvote')->get()->count(), 'data2' => $post->votes()->type('upvote')->get()->count());
     }
 }
コード例 #17
0
 public static function vote(Request $request)
 {
     $voted = $request->voted;
     $uservote = Vote::where('iduser', $request->iduser)->where('idproblem', $request->idproblem)->first();
     $problem = Problem::where('idproblem', $request->idproblem)->first();
     if (empty($uservote)) {
         //no vote has been added yet by this user for this problem
         $vote = array('iduser' => $request->iduser, 'idproblem' => $request->idproblem, 'choice' => $voted);
         $vote = Vote::create($vote);
         switch ($voted) {
             case -1:
                 $problem->votenegative++;
                 break;
             case 1:
                 $problem->votepositive++;
                 break;
         }
         $problem->save();
         return \Response::json('Done');
     } else {
         // user's changing his vote
         if ($voted == 1) {
             switch ($uservote->choice) {
                 case -1:
                     $problem->votenegative -= 1;
                     $problem->votepositive += 1;
                     $uservote->choice = 1;
                     break;
                 case 0:
                     $problem->votenegative += 1;
                     $uservote->choice = 1;
                     break;
                 case 1:
                     $problem->votepositive -= 1;
                     $uservote->choice = 0;
                     break;
             }
         } else {
             switch ($uservote->choice) {
                 case -1:
                     $problem->votenegative -= 1;
                     $uservote->choice = 0;
                     break;
                 case 0:
                     $problem->votenegative += 1;
                     $uservote->choice = -1;
                     break;
                 case 1:
                     $problem->votepositive -= 1;
                     $problem->votenegative += 1;
                     $uservote->choice = -1;
                     break;
             }
         }
         $problem->save();
         $uservote->save();
         return \Response::json('Updated');
     }
     return \Response::json('Error!');
 }
コード例 #18
0
    public function get()
    {
        $entry_id = Request::input('entry_id');
        $entry = Entry::where('id', '=', $entry_id)->first();
        if ($entry) {
            $my_teams = array();
            $global_moderator = false;
            $team_moderator = false;
            $entry_user = $entry->user()->first();
            $user = NULL;
            if (!Auth::check()) {
                if (!$entry->public) {
                    return json_encode(['status' => 'error', 'message' => 'Error. Logout and try again']);
                }
            } else {
                $entry_teams = $entry->teams()->get();
                $user = Auth::user();
                foreach ($entry_teams as $team) {
                    if ($entry->user_id == $user->id || !$team->pivot->removed_from_team) {
                        $check = $team->users()->where('user_id', '=', $user->id)->first();
                        if ($check) {
                            $role = $check->pivot->role;
                            $my_teams[] = ["name" => $team->name, "role" => $role];
                            if ($role && ($role == 'owner' || $role == 'moderator')) {
                                $team_moderator = true;
                            }
                        }
                    }
                }
                if (!$entry->public && !count($my_teams) && $entry->user_id != $user->id) {
                    return json_encode(['status' => 'error', 'message' => 'Error. Logout and try again']);
                }
                if ($entry->public && $user->moderator) {
                    $global_moderator = true;
                }
            }
            $body_rendered = $entry->body_rendered;
            $body = '
            <!DOCTYPE html>
            <html lang="en">
                <head>
                    <title>".$entry->title."</title>
                    <meta charset="utf-8" />
                    <meta name="viewport" content="width=device-width, initial-scale=1">
                    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
                    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap-theme.min.css">
                    <style>
                        code {
                            color: black;
                            background-color: #f5f5f5;
                            border-radius: 4px;
                            border: 1px solid #ccc;
                            padding: 1px 5px;
                        }
                        pre code {
                            border: none;
                        }

                        /* Pygmentize theme: Friendly */
                        .highlight .hll { background-color: #ffffcc }
                        .highlight .c { color: #60a0b0; font-style: italic } /* Comment */
                        .highlight .err { border: 1px solid #FF0000 } /* Error */
                        .highlight .k { color: #007020; font-weight: bold } /* Keyword */
                        .highlight .o { color: #666666 } /* Operator */
                        .highlight .cm { color: #60a0b0; font-style: italic } /* Comment.Multiline */
                        .highlight .cp { color: #007020 } /* Comment.Preproc */
                        .highlight .c1 { color: #60a0b0; font-style: italic } /* Comment.Single */
                        .highlight .cs { color: #60a0b0; background-color: #fff0f0 } /* Comment.Special */
                        .highlight .gd { color: #A00000 } /* Generic.Deleted */
                        .highlight .ge { font-style: italic } /* Generic.Emph */
                        .highlight .gr { color: #FF0000 } /* Generic.Error */
                        .highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */
                        .highlight .gi { color: #00A000 } /* Generic.Inserted */
                        .highlight .go { color: #808080 } /* Generic.Output */
                        .highlight .gp { color: #c65d09; font-weight: bold } /* Generic.Prompt */
                        .highlight .gs { font-weight: bold } /* Generic.Strong */
                        .highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
                        .highlight .gt { color: #0040D0 } /* Generic.Traceback */
                        .highlight .kc { color: #007020; font-weight: bold } /* Keyword.Constant */
                        .highlight .kd { color: #007020; font-weight: bold } /* Keyword.Declaration */
                        .highlight .kn { color: #007020; font-weight: bold } /* Keyword.Namespace */
                        .highlight .kp { color: #007020 } /* Keyword.Pseudo */
                        .highlight .kr { color: #007020; font-weight: bold } /* Keyword.Reserved */
                        .highlight .kt { color: #902000 } /* Keyword.Type */
                        .highlight .m { color: #40a070 } /* Literal.Number */
                        .highlight .s { color: #4070a0 } /* Literal.String */
                        .highlight .na { color: #4070a0 } /* Name.Attribute */
                        .highlight .nb { color: #007020 } /* Name.Builtin */
                        .highlight .nc { color: #0e84b5; font-weight: bold } /* Name.Class */
                        .highlight .no { color: #60add5 } /* Name.Constant */
                        .highlight .nd { color: #555555; font-weight: bold } /* Name.Decorator */
                        .highlight .ni { color: #d55537; font-weight: bold } /* Name.Entity */
                        .highlight .ne { color: #007020 } /* Name.Exception */
                        .highlight .nf { color: #06287e } /* Name.Function */
                        .highlight .nl { color: #002070; font-weight: bold } /* Name.Label */
                        .highlight .nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */
                        .highlight .nt { color: #062873; font-weight: bold } /* Name.Tag */
                        .highlight .nv { color: #bb60d5 } /* Name.Variable */
                        .highlight .ow { color: #007020; font-weight: bold } /* Operator.Word */
                        .highlight .w { color: #bbbbbb } /* Text.Whitespace */
                        .highlight .mf { color: #40a070 } /* Literal.Number.Float */
                        .highlight .mh { color: #40a070 } /* Literal.Number.Hex */
                        .highlight .mi { color: #40a070 } /* Literal.Number.Integer */
                        .highlight .mo { color: #40a070 } /* Literal.Number.Oct */
                        .highlight .sb { color: #4070a0 } /* Literal.String.Backtick */
                        .highlight .sc { color: #4070a0 } /* Literal.String.Char */
                        .highlight .sd { color: #4070a0; font-style: italic } /* Literal.String.Doc */
                        .highlight .s2 { color: #4070a0 } /* Literal.String.Double */
                        .highlight .se { color: #4070a0; font-weight: bold } /* Literal.String.Escape */
                        .highlight .sh { color: #4070a0 } /* Literal.String.Heredoc */
                        .highlight .si { color: #70a0d0; font-style: italic } /* Literal.String.Interpol */
                        .highlight .sx { color: #c65d09 } /* Literal.String.Other */
                        .highlight .sr { color: #235388 } /* Literal.String.Regex */
                        .highlight .s1 { color: #4070a0 } /* Literal.String.Single */
                        .highlight .ss { color: #517918 } /* Literal.String.Symbol */
                        .highlight .bp { color: #007020 } /* Name.Builtin.Pseudo */
                        .highlight .vc { color: #bb60d5 } /* Name.Variable.Class */
                        .highlight .vg { color: #bb60d5 } /* Name.Variable.Global */
                        .highlight .vi { color: #bb60d5 } /* Name.Variable.Instance */
                        .highlight .il { color: #40a070 } /* Literal.Number.Integer.Long */


                        html, body {
                            background-color:transparent;
                        }
                        h1 {
                            font-size:24px;
                        }
                        h2 {
                            font-size:22px;
                        }
                        h3 {
                            font-size:20px;
                        }
                        h4 {
                            font-size:18px;
                        }
                        h5 {
                            font-size:16px;
                        }
                        h6 {
                            font-size:14px;
                        }

                        h2.title {
                            padding-bottom:0px;
                            margin-bottom:2px;
                            margin-top:12px;
                        }

                        p.description {
                            padding-bottom:2px;
                            margin-top:3px;
                        }

                        .vote {
                            float:left;
                            width:48px;
                            text-align: center;
                            height:64px;
                            margin-left:-10px;
                            margin-top:1px;
                        }

                        .score {
                            line-height:12px;
                            font-size:18px;
                            padding-top: 1px;
                            margin-left:2px;
                        }

                        .arrow-up {
                            padding-top:9px;
                            cursor: pointer;
                        }
                        .arrow-down {
                            padding-top:3px;
                            cursor: pointer;
                        }
                        .arrow-up.voted {
                            color:green;
                        }
                        .arrow-down.voted {
                            color:red;
                        }
                        .noselect {
                            -webkit-touch-callout: none;
                            -webkit-user-select: none;
                            user-select:none;
                        }
                        .actions {
                            padding: 1px 4px;
                            font-size: 90%;
                            vertical-align:1px;
                            cursor: pointer;
                            white-space:nowrap;
                            box-shadow:none;
                            font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
                        }
                        .actions.edit {
                            background-color:#286090;
                        }
                        .actions.delete {
                            background-color:#c9302c;
                        }
                        .dash-internal {
                            color: inherit !important;
                            text-decoration: none !important;
                        }

                    </style>
                </head>
                <body>
                    <div class="container-fluid">';
            if ($entry->public || count($my_teams)) {
                $voted_up = "";
                $voted_down = "";
                if ($user) {
                    $vote = Vote::where('user_id', '=', $user->id)->where('entry_id', '=', $entry->id)->first();
                    if ($vote) {
                        $voted_up = $vote->type == 1 ? "voted" : "";
                        $voted_down = $vote->type == -1 ? "voted" : "";
                    }
                }
                $score = $entry->score > 999 ? 999 : $entry->score;
                $score = $score < -999 ? -999 : $score;
                $body .= '
                    <div class="vote noselect">
                        <a class="dash-internal" href="#dashInternalVoteUp"><div class="arrow-up glyphicon glyphicon-arrow-up ' . $voted_up . '"></div></a>
                        <div class="score">' . $score . '</div>
                        <a class="dash-internal" href="#dashInternalVoteDown"><div class="arrow-down glyphicon glyphicon-arrow-down ' . $voted_down . '"></div></a>
                    </div>';
            }
            $body .= '
                    <div><h2 class="title">' . htmlentities($entry->title, ENT_QUOTES) . '</h2>
                    <p class="description"><small>';
            $body .= $entry->public && !($entry->removed_from_public && $global_moderator) ? "Public annotation " : @"Private annotation ";
            $body .= 'by <u>' . htmlentities($entry_user->username, ENT_QUOTES) . '</u>';
            $team_string = "";
            $i = 0;
            foreach ($my_teams as $team) {
                ++$i;
                if (strlen($team_string)) {
                    $team_string .= count($my_teams) == $i ? " and " : ", ";
                }
                $team_string .= '<u>' . htmlentities($team['name'], ENT_QUOTES) . '</u>';
            }
            if (strlen($team_string)) {
                $body .= ' in ' . $team_string . '';
            }
            $body .= ' ';
            if ($user && $user->id == $entry->user_id) {
                $body .= '&nbsp;<a class="dash-internal" href="#dashInternalEdit"><kbd class="actions edit">Edit</kbd></a>';
                $body .= '&nbsp;<a class="dash-internal" href="#dashInternalDelete"><kbd class="actions delete">Delete</kbd></a>';
            } else {
                if ($global_moderator && $entry->public && !$entry->removed_from_public) {
                    $body .= '&nbsp;<a class="dash-internal" href="#dashInternalRemoveFromPublic"><kbd class="actions delete">Remove From Public</kbd></a>';
                }
                if ($team_moderator) {
                    $body .= '&nbsp;<a class="dash-internal" href="#dashInternalRemoveFromTeams"><kbd class="actions delete">Remove From Team';
                    if (count($my_teams) > 1) {
                        $body .= 's';
                    }
                    $body .= '</kbd></a>';
                }
            }
            $body .= '</small><p></div>
                    <p>' . $body_rendered . '</P>
                    </div>
                </body>
            </html>';
            return ["status" => "success", "body" => $entry->body, "body_rendered" => $body, "teams" => $my_teams, "global_moderator" => $global_moderator];
        }
        return json_encode(['status' => 'error', 'message' => 'Error. Logout and try again']);
    }
コード例 #19
0
ファイル: Product.php プロジェクト: ShehabSunny/ProductZap
 public static function add_created_by_and_category($products)
 {
     if (get_class($products) == 'App\\Product') {
         $product = $products;
         $created_by = $product['created_by'];
         $user = User::find($created_by);
         $category = Category::find($product['category_id']);
         $category = $category['category'];
         array_add($product, 'category', $category);
         array_add($product, 'created_by_name', $user['name']);
         array_add($product, 'temp', '');
         //return $product->image_url;
         $initial = explode(".", $product['image_url']);
         $thumbFirst = "";
         for ($i = 0; $i < sizeof($initial) - 1; $i++) {
             $thumbFirst = $thumbFirst . $initial[$i];
         }
         $thumbnail = $thumbFirst . '-200x200.' . $initial[sizeof($initial) - 1];
         $bigPic = $thumbFirst . '-400x400.' . $initial[sizeof($initial) - 1];
         array_add($product, 'thumbnail', $thumbnail);
         array_add($product, 'bigPic', $bigPic);
         //Complete this shit
         if (Auth::check()) {
             $user_id = Auth::user();
             $user_id = $user_id->id;
             $vote = Vote::where('user_id', '=', $user_id)->where('product_id', '=', $product['id'])->get();
             $list = Lists::where('user_id', '=', $user_id)->where('product_id', '=', $product['id'])->get();
             if ($vote->isEmpty() == False) {
                 array_add($product, 'can_vote', False);
             } else {
                 array_add($product, 'can_vote', True);
             }
             if ($list->isEmpty() == False) {
                 array_add($product, 'can_list', False);
             } else {
                 array_add($product, 'can_list', True);
             }
         } else {
             array_add($product, 'can_vote', False);
             array_add($product, 'can_list', False);
         }
         return $products;
     } else {
         $temp = '';
         foreach ($products as $product) {
             if ($product->created_at_date == $temp) {
                 array_add($product, 'date2', '');
             } else {
                 $monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
                 $date = explode('-', $product->created_at_date);
                 $tempDate = $product->created_at_date;
                 $day = date('l', strtotime($tempDate));
                 $dateM = ltrim($date[2], '0');
                 array_add($product, 'date2', $day . ',  ' . $dateM . 'th ' . $monthNames[intval($date[1]) - 1]);
                 $temp = $product->created_at_date;
             }
             //     $created_by = $product->created_by;
             //     $user = User::find($created_by);
             //     $category = Category::find($product->category_id);
             //     $category = $category['category'];
             //     array_add($product, 'category', $category);
             //     array_add($product, 'created_by_name', $user['name']);
             //     array_add($product, 'temp', '');
             //     $initial = explode(".", $product->image_url);
             //     $thumbFirst = "";
             //     for( $i=0; $i<sizeof($initial)-1; $i++ ){
             //         $thumbFirst = $thumbFirst.$initial[$i];
             //     }
             //      $thumbnail = $thumbFirst.'-200x200.'.$initial[sizeof($initial)-1];
             //  $bigPic = $thumbFirst.'-400x400.'.$initial[sizeof($initial)-1];
             // array_add($product, 'thumbnail', $thumbnail);
             // array_add($product, 'bigPic', $bigPic);
             //     if (Auth::check()) {
             //         $user_id = Auth::user();
             //         $user_id = $user_id->id;
             //         $vote = Vote::where('user_id', '=', $user_id)
             //             ->where('product_id', '=', $product->id)
             //             ->get();
             //         $list = Lists::where('user_id', '=', $user_id)
             //             ->where('product_id', '=', $product->id)
             //             ->get();
             //         if ($vote->isEmpty()==False){
             //             array_add($product, 'can_vote', False);
             //         }
             //         else{
             //             array_add($product, 'can_vote', True);
             //         }
             //         if ($list->isEmpty()==False){
             //             array_add($product, 'can_list', False);
             //         }
             //         else{
             //             array_add($product, 'can_list', True);
             //         }
             //     }
             //       else{
             //     array_add($product, 'can_vote', False);
             //     array_add($product, 'can_list', False);
             // }
         }
         return $products;
     }
 }
コード例 #20
0
ファイル: Vote.php プロジェクト: codeforest/nisam
 public function count()
 {
     return Vote::where('order_id', '=', $this->order_id)->count();
 }
コード例 #21
0
 /**
  * Deletes a vote from the database based on a given voting id & member id.
  * Used for deleting votes of members who were saved by pressing the next button
  * but were marked as absent afterwards.
  *
  * @return mixed
  */
 public function deleteVote()
 {
     $voting_id = Input::get('v_id');
     $member_id = Input::get('m_id');
     $votes = Vote::where(['voting_id' => $voting_id, 'member_id' => $member_id])->get();
     if ($votes->count() > 0) {
         foreach ($votes as $v) {
             $v->delete();
         }
     }
     // Return success json
     return Response::json('success', 200);
 }
コード例 #22
0
 public function getVotes()
 {
     $conditions = ["id_utilisateur" => $this->jure->id, "id_campagne" => $this->campagne->id_campagne];
     return Vote::where($conditions, false)->orderBy('position', 'asc')->get();
 }
コード例 #23
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();
     }
 }
コード例 #24
0
ファイル: QAController.php プロジェクト: WPTEbilkent/WPTE
 /**
  * Display the specified resource.
  *
  * @param  int $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     //Question  database tablosundan ilgili id ile veriyi(soruyu) cekiyor.
     $question = Questions::findOrNew($id);
     $votes = Vote::where('content_id', $id)->where('content', 'question')->get(['vote']);
     if ($votes) {
         $vote = 0;
         foreach ($votes as $vote_t) {
             $vote += $vote_t['vote'];
         }
         $question['vote'] = $vote;
     } else {
         $question['vote'] = 0;
     }
     //Answers tablosundan ilgili questionla ilgili var ise cevaplari(Answers) buluyor ve getiriyor.
     $answers = Answers::where('question_id', $id)->get();
     foreach ($answers as $answer) {
         $answer_votes = Vote::where('content_id', $answer->id)->where('content', 'q_answer')->get(['vote']);
         if ($answer_votes) {
             $vote = 0;
             foreach ($answer_votes as $vote_t) {
                 $vote += $vote_t['vote'];
             }
             $answer['vote'] = $vote;
         } else {
             $answer['vote'] = 0;
         }
     }
     //Gerekli view a aldigi verilerle birlikte gonderiyor ve sayfa aciliyor.
     return view('QA.show')->with('question', $question)->with('answers', $answers);
 }
コード例 #25
0
ファイル: PollController.php プロジェクト: emadmrz/Hawk
 public function vote(Poll $poll, Request $request)
 {
     $user = Auth::user();
     if (Vote::where('user_id', $user->id)->where('poll_id', $poll->id)->exists()) {
         return ['hasCallback' => 0, 'callback' => '', 'hasMsg' => 1, 'msgType' => 'danger', 'msg' => 'you have beed voted', 'returns' => ''];
     }
     Vote::create(['user_id' => $user->id, 'poll_id' => $poll->id, 'parameter_id' => $request->input('vote')]);
     Parameter::find($request->input('vote'))->addVote();
     $parameters = $poll->parameters()->get();
     $total_votes = $parameters->sum('num_vote');
     if ($total_votes == 0) {
         $total_votes = 1;
     }
     return ['hasCallback' => 1, 'callback' => 'poll_voted', 'hasMsg' => 1, 'msg' => 'Voted Successfull', 'returns' => ['total_votes' => $total_votes, 'parameters' => $parameters]];
 }
コード例 #26
0
ファイル: MotionController.php プロジェクト: vitz3/IserveU
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show(Motion $motion)
 {
     if (Auth::check()) {
         Vote::where('motion_id', $motion->id)->where('user_id', Auth::user()->id)->update(['visited' => true]);
     }
     if (!Auth::user()->can('create-motions') && ($motion->status === 'draft' || $motion->status === 'review')) {
         abort(403, 'Forbidden access point.');
     }
     // runs this through the transformer
     return $this->motionTransformer->transform($motion->toArray());
 }
コード例 #27
0
ファイル: VoteController.php プロジェクト: rxfu/vote
 public function getIndex()
 {
     $votes = Vote::where('is_active', '=', '1')->orderBy('updated_at')->get();
     return view('vote.index', ['votes' => $votes]);
 }
コード例 #28
0
 /**
  * Get the votes for this post
  *
  * @param  User  $user
  * @return Integer
  */
 public function forPost(Post $post)
 {
     return Vote::where('post_id', $post->id)->get();
 }
コード例 #29
0
 public function vote($id, Request $request)
 {
     $request->setTrustedProxies(array('192.0.0.1', '10.0.0.0/8'));
     $competitor = Competitor::findOrFail($id);
     //check if there is no vote for this particular competitor on current ip adress
     if (!Vote::where('ip', '=', $request->getClientIp())->where('competitor_id', '=', $id)->exists()) {
         echo 'nice';
         $vote = new Vote();
         $vote->ip = $request->getClientIp();
         $vote->competitor_id = $id;
         $vote->save();
         return redirect()->route('otherCompetitors');
     }
     return redirect()->back()->withErrors(['you have already voted for this competitor.']);
 }
コード例 #30
0
ファイル: routes.php プロジェクト: jenidarnold/racquetball
        $row['ranking_date'] = $n->ranking_date;
        $row["{$compare_player_1->first_name}"] = intval($n->c1_ranking);
        $row["{$player->first_name}"] = intval($n->my_ranking);
        $row["{$compare_player_2->first_name}"] = intval($n->c2_ranking);
        array_push($arr_compare, $row);
    }
    $rankings = ["National" => $arr_national, "State" => $arr_state, "Compare" => $arr_compare];
    return $rankings;
});
Route::get('api/vote/castvote', function () {
    $skill_id = (int) Input::get('skillID');
    $voter_id = (int) Input::get('voterID');
    $for_id = (int) Input::get('forID');
    $against_id = (int) Input::get('againstID');
    //if $sameVote exists, do nothing
    $sameVote = Vote::where('voter_id', '=', $voter_id)->where('skill_id', '=', $skill_id)->where('for_id', '=', $for_id)->where('against_id', '=', $against_id)->count();
    if ($sameVote == 0) {
        $vote = Vote::firstOrNew(array('voter_id' => $voter_id, 'skill_id' => $skill_id, 'for_id' => $against_id, 'against_id' => $for_id));
        $vote->voter_id = $voter_id;
        $vote->skill_id = $skill_id;
        $vote->for_id = $for_id;
        $vote->against_id = $against_id;
        $vote->save();
    }
    // get the reults
    $p1 = Vote::head2head($skill_id, $for_id, $against_id);
    $p2 = Vote::head2head($skill_id, $against_id, $for_id);
    $versus = array("p1" => $p1, "p2" => $p2);
    //dd($versus);
    return Response::json($versus);
});