Example #1
0
 public function deleteFriend($userID, $friendUserID)
 {
     DB::transaction(function () use($userID, $friendUserID) {
         $friendModel = Friend::where('user_id', '=', $userID)->where('friend_user_id', '=', $friendUserID)->delete();
         $inverseFriendModel = Friend::where('user_id', '=', $friendUserID)->where('friend_user_id', '=', $userID)->delete();
     });
     return true;
 }
Example #2
0
 public function getSinglePost($slug)
 {
     try {
         $slug = trim($slug);
         $post = Post::where('slug', $slug)->first();
         if (!$post) {
             $post = Post::findOrFail($slug);
             return Redirect::to(URL::action('BlogController@getSinglePost', array($post->slug)));
         }
         // redirect to relative $id and $slug
         // if ($slug !== $post->slug) {
         // return Redirect::to(URL::action ('BlogController@getSinglePost', array($id, $post->slug)));
         // }
         /// TODO: check is published
         // check privacy
         if (Auth::check()) {
             if ($post->created_by != Auth::user()->id) {
                 switch ($post->privacy_level) {
                     case Post::_PRIVATE:
                         throw new Exception("Privacy Error");
                         break;
                     case Post::_FRIEND:
                         $can_see = Friend::where('user_id', $post->created_by)->where('friend_id', Auth::user()->id)->where('type', Friend::ACCEPTED)->first();
                         if (is_null($can_see)) {
                             throw new Exception("Privacy Error");
                         }
                         break;
                     case Post::_CUSTOM:
                         $can_see = DB::table('friend_post')->where('post_id', $post->id)->where('friend_id', Auth::user()->id)->first();
                         if (is_null($can_see)) {
                             throw new Exception("Privacy Error");
                         }
                         break;
                     case Post::_PUBLIC:
                     default:
                         break;
                 }
                 $post->can_comment = Auth::user()->friendship($post->user) == Friend::ACCEPTED;
             }
         } else {
             if ($post->privacy_level != Post::_PUBLIC) {
                 throw new Exception("Privacy Error");
             }
             $post->can_comment = false;
         }
         $tags = $post->tags()->get();
         //get comments info
         $comments = $post->comments()->orderBy('created_at', 'DESC')->simplePaginate(18);
         $commentsData = new \Illuminate\Database\Eloquent\Collection();
         $commentsData = $commentsData->merge($comments);
         // TODO get all comments then analyze for nested comments
         foreach ($commentsData as $comment) {
             if ($comment->parrent_id > 0) {
                 $p = null;
                 foreach ($commentsData as $c) {
                     if ($c->id == $comment->parrent_id) {
                         $p = $c;
                         break;
                     }
                 }
                 if (!$p) {
                     $commentsData = $commentsData->merge($comment->parents());
                 }
             }
         }
         foreach ($commentsData as $comment) {
             if ($comment->parrent_id > 0) {
                 foreach ($commentsData as $c) {
                     if ($c->id == $comment->parrent_id) {
                         $c->child_comments[] = $comment;
                         break;
                     }
                 }
             }
         }
         //get user info (who created this post)
         $post['username'] = $post->user->username;
         $post['avatar'] = $post->user->image;
         $this->layout->content = View::make('posts.entry', array('post' => $post, 'comments' => $comments, 'commentsData' => $commentsData, 'tags' => $tags));
     } catch (Exception $e) {
         throw $e;
     }
 }
Example #3
0
 public function postRejectAllRequest()
 {
     $user_id = Auth::user()->id;
     $requests = Friend::where('user_id', $user_id)->where('type', Friend::REQUESTING)->get();
     foreach ($requests as $request) {
         $request->delete();
     }
     return Response::json(array('status', 'Rejected'));
 }
 public function waitingPages($id)
 {
     $friends = Friend::where('friend_id', $id)->where('active', 0)->count();
     return ceil($friends / 10);
 }
 public function friendshipExists($user, $friendUser)
 {
     return !Friend::where('user_id', '=', $user->id)->where('friend_user_id', '=', $friendUser->id)->get()->isEmpty();
 }
Example #6
0
 public function friendship($friend)
 {
     try {
         $friendship = Friend::where(function ($query) use($friend) {
             $query->where('user_id', $this->id)->where('friend_id', $friend->id);
         })->orWhere(function ($query) use($friend) {
             $query->where('user_id', $friend->id)->where('friend_id', $this->id);
         })->firstOrFail();
         return $friendship->type;
     } catch (Exception $e) {
         return Friend::STRANGER;
     }
 }
 public function getFollowingCount($id)
 {
     return Friend::where('follower_user_id', $id)->count();
 }