Ejemplo n.º 1
0
 public static function getFeeds($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'];
         $post_id = $input['post_id'];
         $skillsets = isset($input['skillset']) ? $input['skillset'] : "";
         $min_age = isset($input['min_age']) ? $input['min_age'] : "";
         $max_age = isset($input['max_age']) ? $input['max_age'] : "";
         $discovery_radius = isset($input['discovery_radius']) ? $input['discovery_radius'] : '0';
         $final = array();
         $result = array();
         $current_time = new DateTime();
         $ageClause = "";
         $skillsetclause = "";
         $distanceClause = "";
         $vid_path = "https://s3-us-west-2.amazonaws.com/cbrealestate/connected_uploads/";
         $user_id = Users::getUserIdByToken($access_token);
         if ($user_id) {
             $user_latlong = Users::getUserLatLong($user_id);
             $latitude = $user_latlong->lat;
             $longitude = $user_latlong->lng;
             $all_skillset = Users::Getskillset();
             if ($post_id) {
                 $whereclause = 'posts.id <' . $post_id;
             } else {
                 $whereclause = 'posts.id >' . $post_id;
             }
             if ($skillsets) {
                 $skills = str_replace('"', "", $skillsets);
                 $skillsetclause = " posts.id IN (SELECT post_id FROM post_skillset WHERE skillset_id IN ({$skills})) OR ";
             }
             if ($min_age && $max_age) {
                 $ageClause = "AND temp.min_age>=" . $min_age . " AND temp.max_age<=" . $max_age;
             }
             if ($discovery_radius) {
                 $distanceClause = " WHERE temp.distance <= " . $discovery_radius;
             }
             $feed_data = DB::select("SELECT temp.* FROM (SELECT users.user_type,users.full_name,users.profile_pic,users.lat,users.lng,users.id as uid,posts.*,posts.id as pid,(select count(likes.id) from likes where likes.post_id=posts.id) as likes_count,\n\t\t\t\t\t\t\t\t\t(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,comments.user_id as c_uid,\n\t\t\t\t\t\t\t\t\tcomments.comment,(select users.full_name from users where users.id=comments.user_id) as un,\n\t\t\t\t\t\t\t\t\t(SELECT FLOOR(DATEDIFF( NOW(),users.dob) / 365.25)) as age,\n\t\t\t\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\t\t\t(SELECT users.user_type from users where users.id=comments.user_id) as cutype,\n\t\t\t\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\t\t\t\tTRUNCATE(( 3961 * acos( cos( radians( " . $latitude . " ) ) * cos( radians( `post_lat` ) ) * cos( radians( `post_lng` ) - radians( " . $longitude . " ) ) + sin( radians( " . $latitude . " ) ) * sin( radians( `post_lat` ) ) ) ),2) AS distance,\n\t\t\t\t\t\t\t\t\tCASE \n\t\t\t\t\t\t\t\t\tWHEN DATEDIFF(UTC_TIMESTAMP(),posts.created_at) != 0 THEN CONCAT(DATEDIFF(UTC_TIMESTAMP(),posts.created_at) ,'d ago')\n\t\t\t\t\t\t\t\t\tWHEN HOUR(TIMEDIFF(UTC_TIMESTAMP(),posts.created_at)) != 0 THEN CONCAT(HOUR(TIMEDIFF(UTC_TIMESTAMP(),posts.created_at)) ,'h ago')\n\t\t\t\t\t\t\t\t\tWHEN MINUTE(TIMEDIFF(UTC_TIMESTAMP(),posts.created_at)) != 0 THEN CONCAT(MINUTE(TIMEDIFF(UTC_TIMESTAMP(),posts.created_at)) ,'m ago')\n\t\t\t\t\t\t\t\t\tELSE\n\t\t\t\t\t\t\t\t\tCONCAT(SECOND(TIMEDIFF(UTC_TIMESTAMP(),posts.created_at)) ,' s ago')\n\t\t\t\t\t\t\t\t\tEND as post_time,\n\t\t\t\t\t\t\t\t\tCASE \n\t\t\t\t\t\t\t\t\tWHEN DATEDIFF(UTC_TIMESTAMP(),comments.created_at) != 0 THEN CONCAT(DATEDIFF(UTC_TIMESTAMP(),comments.created_at) ,'d ago')\n\t\t\t\t\t\t\t\t\tWHEN HOUR(TIMEDIFF(UTC_TIMESTAMP(),comments.created_at)) != 0 THEN CONCAT(HOUR(TIMEDIFF(UTC_TIMESTAMP(),comments.created_at)) ,'h ago')\n\t\t\t\t\t\t\t\t\tWHEN MINUTE(TIMEDIFF(UTC_TIMESTAMP(),comments.created_at)) != 0 THEN CONCAT(MINUTE(TIMEDIFF(UTC_TIMESTAMP(),comments.created_at)) ,'m ago')\n\t\t\t\t\t\t\t\t\tELSE\n\t\t\t\t\t\t\t\t\tCONCAT(SECOND(TIMEDIFF(UTC_TIMESTAMP(),comments.created_at)) ,' s ago')\n\t\t\t\t\t\t\t\t\tEND as comment_time from `posts` left join `users` on `users`.`id` = `posts`.`user_id` \n\t\t\t\t\t\t\t\t\tleft join `comments` on `comments`.`post_id` = `posts`.`id` where " . $whereclause . " and \n\t\t\t\t\t\t\t\t\t(" . $skillsetclause . " posts.user_id IN (select follow.follow_to from follow WHERE follow.follow_by=" . $user_id . " and follow.status=1) or posts.user_id = " . $user_id . ")) as temp " . $distanceClause . " " . $ageClause . " ORDER BY `temp`.`pid` DESC");
             // $feed_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) as 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,comments.user_id as c_uid,
             // 	comments.*,(select users.full_name from users where users.id=comments.user_id) as un,
             // 	(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,
             // 	(select users.user_type from users where users.id=comments.user_id) as cutype,
             // 	(select users.profile_pic from users where users.id=comments.user_id) as c_profile_pic,
             // 	TRUNCATE(( 3961 * acos( cos( radians( ".$latitude." ) ) * cos( radians( `post_lat` ) ) * cos( radians( `post_lng` ) - radians( ".$longitude." ) ) + sin( radians( ".$latitude." ) ) * sin( radians( `post_lat` ) ) ) ),2) AS distance,
             // 	CASE
             // 	  WHEN DATEDIFF(UTC_TIMESTAMP(),posts.created_at) != 0 THEN CONCAT(DATEDIFF(UTC_TIMESTAMP(),posts.created_at) ,'d ago')
             // 	  WHEN HOUR(TIMEDIFF(UTC_TIMESTAMP(),posts.created_at)) != 0 THEN CONCAT(HOUR(TIMEDIFF(UTC_TIMESTAMP(),posts.created_at)) ,'h ago')
             // 	  WHEN MINUTE(TIMEDIFF(UTC_TIMESTAMP(),posts.created_at)) != 0 THEN CONCAT(MINUTE(TIMEDIFF(UTC_TIMESTAMP(),posts.created_at)) ,'m ago')
             // 	  ELSE
             // 		 CONCAT(SECOND(TIMEDIFF(UTC_TIMESTAMP(),posts.created_at)) ,' s ago')
             // 	END as post_time,
             // 	CASE
             // 	  WHEN DATEDIFF(UTC_TIMESTAMP(),comments.created_at) != 0 THEN CONCAT(DATEDIFF(UTC_TIMESTAMP(),comments.created_at) ,'d ago')
             // 	  WHEN HOUR(TIMEDIFF(UTC_TIMESTAMP(),comments.created_at)) != 0 THEN CONCAT(HOUR(TIMEDIFF(UTC_TIMESTAMP(),comments.created_at)) ,'h ago')
             // 	  WHEN MINUTE(TIMEDIFF(UTC_TIMESTAMP(),comments.created_at)) != 0 THEN CONCAT(MINUTE(TIMEDIFF(UTC_TIMESTAMP(),comments.created_at)) ,'m ago')
             // 	  ELSE
             // 		 CONCAT(SECOND(TIMEDIFF(UTC_TIMESTAMP(),comments.created_at)) ,' s ago')
             // 	END as comment_time")
             // 	->leftJoin('users','users.id','=','posts.user_id')
             // 	->leftJoin('comments','comments.post_id','=','posts.id')
             // 	->where(function($query) use($post_id) {
             // 		if($post_id)
             // 		$query->Where('posts.id','<',$post_id);
             // 		else
             // 		$query->Where('posts.id','>',$post_id);
             // 		})
             // 	->where(function($q) use($user_id){
             // 		 $q->WhereRaw('posts.user_id IN (select follow.follow_to from follow WHERE follow.follow_by='.$user_id.' and follow.status=1) ')
             // 			->orWhereRaw('posts.user_id = '.$user_id.'');
             // 		})
             // 	->orderBy('posts.id', 'DESC')
             // 	//->take(15)
             //  ->get();
             if ($feed_data) {
                 $profile_setup_status = Users::ProfileSetupStatus($user_id);
                 foreach ($feed_data as $key => $value) {
                     if (!isset($final[$value->pid])) {
                         $final[$value->pid] = array('user_id' => $value->uid, 'user_type' => $value->user_type, 'p_name' => $value->full_name, 'latitude' => $value->lat ? $value->lat : "0", 'profile_pic' => $value->profile_pic ? Users::getFormattedImage($value->profile_pic) : "", 'longitude' => $value->lng ? $value->lng : "0", "post_id" => $value->pid ? $value->pid : "", 'min_age' => $value->min_age, 'max_age' => $value->max_age, "post_latitude" => $value->post_lat ? $value->post_lat : '0', "post_longitude" => $value->post_lng ? $value->post_lng : '0', "post_title" => $value->title ? $value->title : "", "skills" => $value->skills ? $value->skills : "", "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', 'distance' => $value->distance ? $value->distance : '0', 'comments' => array());
                     }
                     if (!isset($final[$value->pid]['comments'][$value->cid])) {
                         if ($value->cid) {
                             $final[$value->pid]['comments'][] = array("comment_id" => $value->cid ? $value->cid : "", "user_id" => $value->c_uid ? $value->c_uid : "", "name" => $value->un ? $value->un : "", "user_type" => $value->cutype ? $value->cutype : "", '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;
                 }
             }
             $result = array_slice($result, 0, 15);
             if ($result) {
                 return Response::json(array('status' => '1', 'msg' => 'Records Found', 'data' => $result, 'all_skillset' => $all_skillset, 'profile_complete_status' => $profile_setup_status), 200);
             } else {
                 if ($latitude && $longitude) {
                     return Response::json(array('status' => '2', 'msg' => "No Record Found", 'all_skillset' => $all_skillset), 200);
                 } else {
                     return Response::json(array('status' => '3', 'msg' => "No Record Found", 'all_skillset' => $all_skillset), 200);
                 }
             }
         } else {
             return Response::json(array('status' => '0', 'msg' => "Token Expired"), 200);
         }
     }
 }
Ejemplo n.º 2
0
 public static function getUserProfile($input)
 {
     $validation = Validator::make($input, Posts::$UserPostsRules);
     if ($validation->fails()) {
         return Response::json(array('status' => '0', 'msg' => $validation->getMessageBag()->first()), 200);
     } else {
         $access_token = $input['token'];
         $other_id = $input['other_id'];
         $user_id = Users::getUserIdByToken($access_token);
         if ($user_id) {
             $user_details = Users::LoginTypeResponse($other_id);
             $user_posts = Posts::FetchPosts($user_id, $other_id);
             $friends = Users::GetFollowers($other_id);
             $skillset = Users::Getskillset();
             $user_skillset = Users::GetUserSkills($other_id);
             $follower_data = $friends['followers'];
             $following_data = $friends['following'];
             $profile_setup_status = Users::ProfileSetupStatus($user_id);
             $is_follow_status = Users::getIsFollow($user_id, $other_id);
             if ($user_details) {
                 return Response::json(array('status' => '1', 'msg' => 'User Details', 'profile_complete_status' => $profile_setup_status, 'result' => $user_details, 'user_posts' => $user_posts, 'followers' => $follower_data, 'following' => $following_data, 'all_skillset' => $skillset, 'user_skillset' => $user_skillset, 'is_follow_status' => $is_follow_status), 200);
             } else {
                 return Response::json(array('status' => '0', 'msg' => 'User Not Found'), 200);
             }
         } else {
             return Response::json(array('status' => '0', 'msg' => "Token Expired"), 200);
         }
     }
 }