Exemple #1
0
 public function getTodayVotessCountAttribute()
 {
     $order = Order::today();
     if ($order == null) {
         return '0';
     }
     return Vote::where('order_id', '=', $order->id)->where('place_id', '=', $this->id)->count();
 }
 public static function canVote($photo_id)
 {
     $canVote = true;
     $oneHourAgo = date('Y-m-d H:i:s', time() - 60 * 60);
     $votes = Vote::where('user_id', \Auth::user()->id)->where('photo_id', $photo_id)->where('created_at', '>', $oneHourAgo)->get();
     if ($votes->count() > 0) {
         $canVote = false;
     }
     return $canVote;
 }
 public function postVoteDream(Request $req)
 {
     $dream = $req->input('dream');
     if (Vote::where('id_dream', $dream)->where('cookie', $this->userService->cookie())->count() > 0) {
         return response()->json(['status' => 'ERROR', 'data' => '', 'messages' => 'Ati votat deja.']);
     }
     $vote = new Vote();
     $vote->id_dream = $dream;
     $vote->cookie = $this->userService->cookie();
     $vote->save();
     $dream = Dream::find($dream);
     $dream->votes += 1;
     $dream->save();
     return response()->json(['status' => 'OK', 'data' => $dream->votes, 'messages' => 'Proiect votat.']);
 }
Exemple #4
0
 public function count()
 {
     return Vote::where('order_id', '=', $this->order_id)->count();
 }
Exemple #5
0
 public function getCountVotesAttribute()
 {
     return Vote::where('order_id', '=', $this->id)->get();
 }
Exemple #6
0
 public static function myVote($me)
 {
     return Vote::where('user_id', '=', $me->id)->where('order_id', '=', Order::today()->id)->first();
 }
 public function getAllPhotos()
 {
     $rankings = isset($this->rankings) ? $this->rankings : \Input::get('rankings');
     $friends = isset($this->friends) ? $this->friends : null;
     $photo_id = \Input::get('photo_id');
     $photos = $this->queryPhotos($rankings, $friends);
     if ($photo_id) {
         $found = false;
         while (!$found) {
             $photos->each(function ($photo) use(&$found, $photo_id) {
                 if ($photo->id == $photo_id) {
                     $found = true;
                 }
             });
             if (!$found) {
                 $isLastPage = $photos->currentPage() == $photos->lastPage();
                 $input = \Input::all();
                 $input['page'] = $isLastPage ? 1 : $photos->currentPage() + 1;
                 \Input::replace($input);
                 $photos = $this->queryPhotos($rankings, $friends);
                 $found = $isLastPage ? true : $found;
             }
         }
     }
     $photos->each(function ($photo) {
         // get photo votes
         $photo->votes_count = new \stdClass();
         $photo->votes_count->aggregate = Vote::where('photo_id', $photo->id)->count();
         $photo->votes_count->photo_id = $photo->id;
     });
     $photos = $this->formatPhotoCollection($photos);
     if ($rankings) {
         $p = $photos->all();
         usort($p, function ($a, $b) {
             if ($a['votes_count']->aggregate == $b['votes_count']->aggregate) {
                 return 0;
             }
             return $a['votes_count']->aggregate > $b['votes_count']->aggregate ? -1 : 1;
         });
         $photos->splice(0, $photos->count());
         foreach ($p as $element) {
             $photos->push($element);
         }
         $photos->splice(10, $photos->count() - 10);
         $p = $photos;
         unset($photos);
         $photos['data'] = $p;
     }
     return $photos;
 }
Exemple #8
0
 public function getVotes($ip = NULL, $id = NULL)
 {
     return $id == NULL ? Vote::all() : Vote::where('ip_address', '=', $ip)->where('id_post', '=', $id)->get();
 }
 public function getChiTiet($id)
 {
     $brands = $this->brands;
     $socho = $this->sochoxe;
     $tintucs = $this->tintucs;
     $binhluans = Comment::where('xe_id', $id)->orderBy('id', 'desc')->paginate(3);
     foreach ($binhluans as $key => $value) {
         if ($value->nguoidung_id != NULL) {
             $user = User::where('nguoidung_id', $value->nguoidung_id)->get()->first();
             $value->nguoidung_id = $user->tendaydu;
         }
     }
     //dd($binhluans);
     // xe hiện tại
     $xe = Cars::where('xe_id', $id)->get()->first();
     // tên lái xe theo xe
     $tenlaixe = TaiXe::where('taixe_id', $xe->tai_xe_id)->get()->first();
     $xekhac = Cars::whereNotIn('xe_id', [$id])->where(function ($query) use($xe) {
         $query->where('socho_xe', $xe->socho_xe)->orWhere('hang_id', $xe->hang_id);
     })->get();
     //dd($xekhac);
     //dd($xe); die();
     $vote_id = Vote::where('cars_id', $id)->get()->first();
     if ($vote_id->sovotes != 0) {
         $roundVote = round($vote_id->tongdiem / $vote_id->sovotes, 1);
     } else {
         $roundVote = 0;
     }
     //dd($vote_id);
     return view('frontend.pages.chitiet', compact('vote_id', 'binhluans', 'xe', 'socho', 'brands', 'tintucs', 'tenlaixe', 'xekhac', 'roundVote'));
 }