Ejemplo n.º 1
0
 public function getThumbsDown($id)
 {
     try {
         $valid_ip = Thumb::where('ip', '=', Puskice::getIP())->where('object_type', '=', 5)->where('object_id', '=', $id)->first();
         if ($valid_ip != null) {
             throw new Exception("Error valid IP", 1);
         }
         $news = News::findOrFail($id);
         $news->thumbs_down++;
         $news->save();
         $thumb = new Thumb();
         $thumb->ip = Puskice::getIP();
         $thumb->object_id = $news->id;
         $thumb->object_type = 5;
         $thumb->save();
         $thumbs = array();
         if (Cookie::get('ps_thumbs')) {
             $cookie = Cookie::get('ps_thumbs');
             $thumbs = unserialize($cookie);
             if (isset($thumbs['page'][$news->id])) {
                 return Response::json(array('status' => 'fail', 'message' => __("Већ сте оценили ову вест")));
             }
         }
         $thumbs['page'][$news->id] = 'down';
         Cookie::queue('ps_thumbs', serialize($thumbs), 2628000);
         return Response::json(array('status' => 'success', 'message' => _("Ваш глас је забележен. Хвала на труду"), 'thumbsUp' => $news->thumbs_up, 'thumbsDown' => $news->thumbs_down));
     } catch (Exception $e) {
         return Response::json(array('status' => 'fail', 'message' => _("Већ сте оценили ову страницу")));
     }
 }
Ejemplo n.º 2
0
 public function getThumbsDown($id)
 {
     try {
         $this->googleAnalytics('/comments/thumbs-down/' . $id);
         $valid_ip = Thumb::where('ip', '=', Puskice::getIP())->where('object_type', '=', 2)->where('object_id', '=', $id)->first();
         if ($valid_ip != null) {
             throw new Exception("Error valid IP", 1);
         }
         $comment = Comment::findOrFail($id);
         $comment->thumbs_down++;
         $comment->save();
         $thumb = new Thumb();
         $thumb->ip = Puskice::getIP();
         $thumb->object_id = $comment->id;
         $thumb->object_type = 2;
         $thumb->save();
         $thumbs = array();
         if (Cookie::get('ps_thumbs')) {
             $cookie = Cookie::get('ps_thumbs');
             $thumbs = unserialize($cookie);
             if (isset($thumbs['comments'][$comment->id])) {
                 return Response::json(array('status' => 'fail', 'message' => __("Већ сте оценили овај коментар")));
             }
         }
         $thumbs['comments'][$comment->id] = 'down';
         Cookie::queue('ps_thumbs', serialize($thumbs), 2628000);
         return Response::json(array('status' => 'success', 'message' => _("Ваш глас је забележен. Хвала на труду"), 'thumbsUp' => $comment->thumbs_up, 'thumbsDown' => $comment->thumbs_down));
     } catch (Exception $e) {
         return Response::json(array('status' => 'fail', 'message' => _("Већ сте оценили овај коментар")));
     }
 }