示例#1
0
 public static function likePost($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);
         if ($user_id) {
             $uname = Users::getUsername($user_id);
             $other_id = Posts::getPostOwner($post_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;
             $post_data = DB::table('likes')->select('*')->where('post_id', $post_id)->where('user_id', $user_id)->first();
             if (!$post_data) {
                 $like_id = DB::table('likes')->insertGetId(array('user_id' => $user_id, 'post_id' => $post_id, 'created_at' => $current_time));
                 if ($user_id != $other_id) {
                     $post_desc = Posts::PostDesc($other_id, $post_id);
                     $notify_message = $uname . " liked your post";
                     $Ninput['sender_id'] = $user_id;
                     $Ninput['receiver_id'] = Posts::getPostOwner($post_id);
                     $Ninput['type_id'] = $like_id;
                     $Ninput['type'] = 'like';
                     $Ninput['title'] = $notify_message;
                     Notifications::addNotification($Ninput);
                     if ($push_status) {
                         Notifications::SendPushNotification($notify_message, '', $device_token, 2, $post_id, $user_id);
                         Notifications::SendPushNotification($notify_message, $reg_id, '', 2, $post_desc, $user_type);
                     }
                 }
                 if ($like_id) {
                     return Response::json(array('status' => '1', 'msg' => 'Post Liked'), 200);
                 } else {
                     return Response::json(array('status' => '0', 'msg' => "Error"), 200);
                 }
             } else {
                 return Response::json(array('status' => '2', 'msg' => 'Post Already liked by user'), 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);
         }
     }
 }