public function getApproveVote($voteId)
 {
     $vote = Vote::find($voteId);
     $vote->checked = 1;
     $vote->isActive = 1;
     $vote->save();
     return redirect('admin/votes');
 }
Esempio n. 2
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. 3
0
 /**
  * Store a newly created resource in storage. Requires the vote_id to be submitted
  *
  * @param int vote_id the comment will be attached to
  * @return Response
  */
 public function store()
 {
     if (!Auth::user()->can('create-comments')) {
         abort(401, 'You do not have permission to write a comment');
     }
     $vote = Vote::find(Request::get('vote_id'));
     if (!$vote) {
         abort(403, "There is no vote with the provided ID of (" . Request::get('vote_id') . ")");
     }
     if ($vote->user_id != Auth::user()->id) {
         abort(403, "You can not comment tied to another users vote");
     }
     $comment = Comment::onlyTrashed()->where('vote_id', $vote->id)->where('user_id', Auth::user()->id)->first();
     if ($comment) {
         $comment->forceDelete();
     }
     $comment = new Comment(Request::all());
     $comment->vote_id = $vote->id;
     if (!$comment->save()) {
         abort(403, $comment->errors);
     }
     return $comment;
 }
Esempio n. 4
0
 public function getChart($id)
 {
     $vote = Vote::find($id);
     $data['legend'] = $vote->title . '统计图';
     $data['series']['name'] = '票数';
     foreach ($vote->nominations as $nomination) {
         $data['categories'][] = $nomination->title;
         $data['series']['data'][] = $nomination->voters->count();
     }
     return response()->json($data);
 }
Esempio n. 5
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int $id
  * @return Response
  */
 public function destroy($id)
 {
     $vote = Vote::find((int) $id);
     if ($vote->debates->first()) {
         Post::create(['user_id' => Auth::user()->id, 'debate_id' => $vote->debates->first()->id, 'message' => '<p>Le vote a été annulé.</p>']);
     }
     Vote::destroy($vote->id);
     return back()->with('message', 'Vote supprimé avec succès.');
 }