Exemplo n.º 1
0
 public function getNotification()
 {
     $off = Input::get('off');
     $notifications = Notification::whereUserId(Auth::user()->id)->where('seen', '!=', 2)->orderBy('updated_at', 'desc')->skip(Input::get('off'))->take('18446744073709551615')->get();
     if (count($notifications) == 0) {
         return '404';
     }
     $date = Carbon::parse(Input::get('date'));
     $data['notifications'] = null;
     $i = 0;
     $size = 0;
     foreach ($notifications as $notification) {
         $dec = 1;
         if ($notification->type == 1) {
             $like = Like::wherePostId($notification->post_id)->get()->count() - $notification->like;
             // $dislike = Dislike::wherePostId($notification->post_id)->get()->count() - $notification->dislike;
             if ($like > 0) {
                 // $ss = $like == 1? '': 's';
                 $msg = $like;
                 // $msg = 'You have <b>'.$msg.'</b> in your Post';
             } else {
                 $dec = 0;
             }
             $post = Post::find($notification->post_id)->post;
             $post = ' "' . str_limit($post, 20, '...') . '"';
         } elseif ($notification->type == 2) {
             $dislike = Dislike::wherePostId($notification->post_id)->get()->count() - $notification->dislike;
             if ($dislike > 0) {
                 // $ss = $dislike == 1 ? '': 's';
                 $msg = $dislike;
                 //.' new dislike'.$ss;
                 // $msg = 'You have <b>'.$msg.'</b> in your Post';
             } else {
                 $dec = 0;
             }
             $post = Post::find($notification->post_id)->post;
             $post = ' "' . str_limit($post, 20, '...') . '"';
         } elseif ($notification->type == 3) {
             $comment = Comment::wherePostId($notification->post_id)->get()->count() - $notification->comment;
             if ($comment > 0) {
                 $msg = $comment;
             } else {
                 $dec = 0;
             }
             $post = Post::find($notification->post_id)->post;
             $post = ' "' . str_limit($post, 20, '...') . '"';
         } elseif ($notification->type == 4) {
             $post = Post::find($notification->post_id)->post;
             $post = ' "' . str_limit($post, 20, '...') . '"';
             $msg = $notification->like;
         } elseif ($notification->type == 5) {
             $post = Comment::find($notification->dislike);
             if ($post) {
                 $post = $post->comment;
                 $post = ' "' . str_limit($post, 20, '...') . '"';
                 $msg = $notification->like;
             } else {
                 $notification->delete();
                 $dec = 0;
             }
         }
         if ($dec) {
             if ($i == 10) {
                 $data['hasMore'] = true;
                 break;
             }
             $message = ['id' => $notification->id, 'type' => $notification->type, 'message' => ['count' => $msg, 'post' => $post], 'seen' => $notification->seen, 'ago' => Carbon::parse($notification->updated_at)->diffForHumans()];
             // $data['notifications'][$i]['id'] = $notification->id;
             // $data['notifications'][$i]['msg'] = $msg.'<br/>'.$post;
             // $data['notifications'][$i]['ago'] = Carbon::parse($notification->updated_at)->diffForHumans();
             $data['notifications'][$i] = $message;
             if ($notification->seen == 0) {
                 $size++;
             }
             // $data['notifications'][$i]['seen'] = $notification->seen;
             $difference = $date->diff($notification->updated_at)->days;
             if ($difference >= 1) {
                 //echo $notification->updated_at.'<br>';
                 $date = Carbon::parse($notification->updated_at);
                 //echo $i.'<br>';
                 $data['notifications'][$i]['mark'] = true;
                 //$notification->updated_at;
             } else {
                 $data['notifications'][$i]['mark'] = false;
             }
             $i++;
         }
         $off++;
         // if($i == 10) break;
     }
     // return json_encode();
     // $view['msg'] = $data;//View::make('ajax.notification')->withData($data)->render();
     $data['length'] = $i;
     $data['off'] = $off;
     $data['date'] = $date . '';
     return Response::json($data);
 }
Exemplo n.º 2
-1
 public function viewNotification($id)
 {
     try {
         $notification = Notification::find($id);
         if ($notification) {
             $notification->seen = 2;
             if ($notification->type == 1) {
                 $notification->like = Like::wherePostId($notification->post_id)->get()->count();
                 $notification->dislike = Dislike::wherePostId($notification->post_id)->get()->count();
             } elseif ($notification->type == 2) {
                 $notification->comment = Comment::wherePostId($notification->post_id)->get()->count();
                 //$notification->save();
             }
             $notification->save();
             return Redirect::to('/singlepost/' . $notification->post_id);
         }
         return "Unauthorized Access Of Notification";
     } catch (Exception $e) {
     }
     return "Unauthorized Access Of Notification";
 }