示例#1
0
 public static function getPopularPosts($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) {
             // $user_latlong=Users::getUserLatLong($user_id);
             $user_det = Users::getUserType($user_id);
             $user_type = $user_det->user_type;
             // $latitude=$user_latlong->lat;
             // $longitude=$user_latlong->lng;
             $vid_path = 'https://s3-us-west-2.amazonaws.com/cbrealestate/connected_uploads/';
             if ($user_type == 'employer') {
                 $popular_posts = DB::select("SELECT users.id,full_name,profile_pic,profile_thumb,profile_video,user_type,count(*) as follow_count FROM `users` JOIN follow ON follow.follow_to=users.id WHERE user_type='employer' AND profile_video!='' GROUP BY follow_to \n\t\t\t\t\t\t\t\t\tUNION\n\t\t\t\t\t\t\t\t\tSELECT users.id,full_name,profile_pic,profile_thumb,profile_video,user_type,0 as follow_count FROM `users` JOIN user_skillset ON user_skillset.user_id=users.id JOIN post_skillset ON post_skillset.skillset_id=user_skillset.skillset_id WHERE  profile_video!='' AND post_skillset.skillset_id IN (SELECT skillset_id from post_skillset WHERE post_skillset.user_id=" . $user_id . ")");
             } else {
                 $popular_posts = DB::select("SELECT users.id,full_name,profile_pic,profile_thumb,profile_video,user_type,0 as follow_count FROM `users` JOIN user_skillset ON user_skillset.user_id=users.id WHERE  profile_video!='' AND user_skillset.skillset_id IN (SELECT skillset_id FROM user_skillset WHERE user_skillset.user_id=" . $user_id . ")\n\t\t\t\t\t\t\t\t\t\t\t\tUNION\n\t\t\t\t\t\t\t\t\t\t\t\tSELECT users.id,full_name,profile_pic,profile_thumb,profile_video,user_type,0 as follow_count FROM `users` JOIN post_skillset ON post_skillset.user_id=users.id JOIN user_skillset ON user_skillset.skillset_id=post_skillset.skillset_id WHERE  profile_video!='' AND post_skillset.skillset_id IN (SELECT skillset_id from user_skillset WHERE user_skillset.user_id=" . $user_id . ")");
             }
             foreach ($popular_posts as $row) {
                 // $row->distance=$row->distance?$row->distance:"0";
                 $row->profile_pic = $row->profile_pic ? Users::getFormattedImage($row->profile_pic) : "";
                 $row->profile_thumb = $row->profile_thumb ? Users::getFormattedImage($row->profile_thumb) : "";
                 $row->profile_video = $row->profile_video ? $vid_path . $row->profile_video : "";
             }
             if ($popular_posts) {
                 return Response::json(array('status' => '1', 'msg' => 'Records Found', 'data' => $popular_posts), 200);
             } else {
                 return Response::json(array('status' => '2', 'msg' => "No Record Found"), 200);
             }
         } else {
             return Response::json(array('status' => '0', 'msg' => "Token Expired"), 200);
         }
     }
 }
示例#2
0
 public static function FollowUser($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);
         $current_time = new DateTime();
         if ($user_id) {
             $uname = Users::getUsername($user_id);
             $push_status = Users::getPushSettings($other_id);
             $user_det = Users::getUserType($user_id);
             $user_type = $user_det->user_type;
             $push_ids = Users::getUserPushIds($other_id);
             $reg_id = $push_ids->reg_id;
             $device_token = $push_ids->apn_id;
             $friend_data = DB::table('follow')->select('*')->where('follow_by', $user_id)->where('follow_to', $other_id)->first();
             $notify_message = $uname . " has started following you";
             $Ninput['sender_id'] = $user_id;
             $Ninput['receiver_id'] = $other_id;
             if ($friend_data) {
                 $Ninput['type_id'] = $friend_data->id;
             }
             $Ninput['type'] = 'follow';
             $Ninput['title'] = $notify_message;
             if (!$friend_data) {
                 $follow_id = DB::table('follow')->insertGetId(array('follow_by' => $user_id, 'follow_to' => $other_id, 'status' => '1', 'created_at' => $current_time));
                 $Ninput['type_id'] = $follow_id;
                 Notifications::addNotification($Ninput);
                 if ($push_status) {
                     Notifications::SendPushNotification($notify_message, $reg_id, $device_token, 5, $user_id, $user_type);
                 }
             } else {
                 $follow_id = DB::table('follow')->select('*')->where('follow_by', $user_id)->where('follow_to', $other_id)->delete();
                 Notifications::RemoveNotification($Ninput);
             }
             $friends = Users::GetFollowers($user_id);
             $follower_data = $friends['followers'];
             $following_data = $friends['following'];
             if ($follow_id) {
                 return Response::json(array('status' => '1', 'msg' => 'Friend List Updated', 'followers' => $follower_data, 'following' => $following_data), 200);
             } else {
                 return Response::json(array('status' => '0', 'msg' => "Error"), 200);
             }
         } else {
             return Response::json(array('status' => '0', 'msg' => "Token Expired"), 200);
         }
     }
 }