Example #1
0
 public static function getPostDetail($input)
 {
     $validation = Validator::make($input, Posts::$likePostRules);
     if ($validation->fails()) {
         return Response::json(array('status' => '0', 'msg' => $validation->getMessageBag()->first()), 200);
     } else {
         $access_token = $input['token'];
         $post_id = $input['post_id'];
         $current_time = new DateTime();
         $user_id = Users::getUserIdByToken($access_token);
         $vid_path = "https://s3-us-west-2.amazonaws.com/cbrealestate/connected_uploads/";
         if ($user_id) {
             $post_data = DB::table('posts')->selectRaw("users.*,users.id as uid,posts.*,posts.id as pid,(SELECT count(likes.id) from likes where likes.post_id=posts.id) \n\t\t\t\t\t\tas likes_count,(select count(likes.id) from likes where likes.post_id=posts.id and likes.user_id='{$user_id}') as is_liked,comments.id as cid,\n\t\t\t\t\t\tcomments.user_id as c_uid,comments.*,(select users.full_name from users where users.id=comments.user_id) as un,\n\t\t\t\t\t\t(select users.user_type from users where users.id=comments.user_id) as utype,\n\t\t\t\t\t\t(SELECT group_concat(CONCAT('#',skillset.skill) SEPARATOR ' ') from skillset JOIN post_skillset ON post_skillset.skillset_id=skillset.id WHERE post_skillset.post_id=posts.id) as skills,\n\t\t\t\t\t\t(SELECT users.profile_pic from users where users.id=comments.user_id) as c_profile_pic,\n\t\t\t\t\t\tCASE \n\t\t\t\t\t\t  WHEN DATEDIFF(NOW(),posts.created_at) != 0 THEN CONCAT(DATEDIFF(NOW(),posts.created_at) ,'d ago')\n\t\t\t\t\t\t  WHEN HOUR(TIMEDIFF(NOW(),posts.created_at)) != 0 THEN CONCAT(HOUR(TIMEDIFF(NOW(),posts.created_at)) ,'h ago')\n\t\t\t\t\t\t  WHEN MINUTE(TIMEDIFF(NOW(),posts.created_at)) != 0 THEN CONCAT(MINUTE(TIMEDIFF(NOW(),posts.created_at)) ,'m ago')\n\t\t\t\t\t\t  ELSE\n\t\t\t\t\t\t\t CONCAT(SECOND(TIMEDIFF(NOW(),posts.created_at)) ,' s ago')\n\t\t\t\t\t\tEND as post_time,\n\t\t\t\t\t\tCASE \n\t\t\t\t\t\t  WHEN DATEDIFF(NOW(),comments.created_at) != 0 THEN CONCAT(DATEDIFF(NOW(),comments.created_at) ,'d ago')\n\t\t\t\t\t\t  WHEN HOUR(TIMEDIFF(NOW(),comments.created_at)) != 0 THEN CONCAT(HOUR(TIMEDIFF(NOW(),comments.created_at)) ,'h ago')\n\t\t\t\t\t\t  WHEN MINUTE(TIMEDIFF(NOW(),comments.created_at)) != 0 THEN CONCAT(MINUTE(TIMEDIFF(NOW(),comments.created_at)) ,'m ago')\n\t\t\t\t\t\t  ELSE\n\t\t\t\t\t\t\t CONCAT(SECOND(TIMEDIFF(NOW(),comments.created_at)) ,' s ago')\n\t\t\t\t\t\tEND as comment_time ")->leftJoin('users', 'users.id', '=', 'posts.user_id')->leftJoin('comments', 'posts.id', '=', 'comments.post_id')->Where('posts.id', '=', $post_id)->get();
             $final = array();
             $result = array();
             if ($post_data) {
                 foreach ($post_data as $key => $value) {
                     if (!isset($final[$value->pid])) {
                         $final[$value->pid] = array('user_id' => $value->uid, 'user_type' => $value->user_type, 'full_name' => $value->full_name ? $value->full_name : "", 'latitude' => $value->lat ? $value->lat : "", 'longitude' => $value->lng ? $value->lng : "", 'profile_pic' => $value->profile_pic ? Users::getFormattedImage($value->profile_pic) : "", 'min_age' => $value->min_age, 'max_age' => $value->max_age, 'longitude' => $value->lng ? $value->lng : "0", "post_id" => $value->pid ? $value->pid : "", "skills" => $value->skills ? $value->skills : "", 'post_latitude' => $value->post_lat ? $value->post_lat : "0", 'post_longitude' => $value->post_lng ? $value->post_lng : "0", "post_title" => $value->title ? $value->title : "", "post_description" => $value->post_desc ? $value->post_desc : "", 'post_image' => $value->post_image ? Users::getFormattedImage($value->post_image) : "", 'post_video' => $value->post_video ? $vid_path . $value->post_video : "", 'post_time' => $value->post_time ? $value->post_time : "", 'likes_count' => $value->likes_count ? $value->likes_count : '0', 'is_liked' => $value->is_liked ? $value->is_liked : '0', 'comments' => array());
                     }
                     if (!isset($final[$value->pid]['comments'][$value->cid])) {
                         if ($value->cid) {
                             $final[$value->pid]['comments'][] = array("comment_id" => $value->cid, "user_id" => $value->c_uid ? $value->c_uid : "", "name" => $value->un ? $value->un : "", "user_type" => $value->utype ? $value->utype : "", 'profile_pic' => $value->c_profile_pic ? Users::getFormattedImage($value->c_profile_pic) : "", 'comment' => $value->comment ? $value->comment : "", 'comment_time' => $value->comment_time ? $value->comment_time : "");
                         }
                     }
                 }
             }
             if ($final) {
                 foreach ($final as $key => $val) {
                     $data2 = array();
                     $result[] = $val;
                 }
             }
             if ($result) {
                 return Response::json(array('status' => '1', 'msg' => 'Post Details', 'result' => $result), 200);
             } else {
                 return Response::json(array('status' => '2', 'msg' => 'No Post Found'), 200);
             }
         } else {
             return Response::json(array('status' => '0', 'msg' => "Token Expired"), 200);
         }
     }
 }
Example #2
0
 public static function SetNotificationStatus($input)
 {
     $validation = Validator::make($input, Notifications::$NotifyRules);
     if ($validation->fails()) {
         return Response::json(array('status' => '0', 'msg' => $validation->getMessageBag()->first()), 200);
     } else {
         $access_token = $input['token'];
         $notification_id = $input['notification_id'];
         $current_time = new DateTime();
         $user_id = Users::getUserIdByToken($access_token);
         if ($user_id) {
             $notification_data = DB::table('notification')->select('*')->where('id', $notification_id)->first();
             if ($notification_data) {
                 DB::table('notification')->where('id', $notification_id)->update(['is_read' => '1']);
                 return Response::json(array('status' => '1', 'msg' => 'Notification Read'), 200);
             } else {
                 return Response::json(array('status' => '0', 'msg' => 'Notification doesnot exists'), 200);
             }
         } else {
             return Response::json(array('status' => '0', 'msg' => "Token Expired"), 200);
         }
     }
 }
Example #3
0
    public static function getFriends($input)
    {
        $validation = Validator::make($input, Posts::$FeedRules);
        if ($validation->fails()) {
            return Response::json(array('status' => '0', 'msg' => $validation->getMessageBag()->first()), 200);
        } else {
            $access_token = $input['token'];
            $user_id = Users::getUserIdByToken($access_token);
            if ($user_id) {
                $follower_data = DB::table('follow')->selectRaw('users.id,users.full_name,users.phone_number,ifnull((users.place),"") as place, users.user_type,users.profile_pic,
									ifnull((SELECT status from follow WHERE follow.follow_by=' . $user_id . ' AND follow.follow_to=users.id),"0") as is_followed')->leftJoin('users', 'users.id', '=', 'follow.follow_by')->where('follow_to', $user_id)->get();
                $following_data = DB::table('follow')->selectRaw('users.id,users.full_name,users.phone_number,ifnull((users.place),"") as place,users.user_type,users.profile_pic,
									ifnull((SELECT status from follow WHERE follow.follow_by=' . $user_id . ' AND follow.follow_to=users.id),"0") as is_followed')->leftJoin('users', 'users.id', '=', 'follow.follow_to')->where('follow_by', $user_id)->get();
                foreach ($follower_data as $row) {
                    $row->profile_pic = $row->profile_pic ? Users::getFormattedImage($row->profile_pic) : "";
                }
                foreach ($following_data as $row) {
                    $row->profile_pic = $row->profile_pic ? Users::getFormattedImage($row->profile_pic) : "";
                }
                return Response::json(array('status' => '1', 'msg' => 'Friends List', 'followers' => $follower_data, 'following' => $following_data), 200);
            } else {
                return Response::json(array('status' => '0', 'msg' => "Token Expired"), 200);
            }
        }
    }