public static function unlikePost($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) { $like_data = DB::table('likes')->select('id')->where('post_id', $post_id)->where('user_id', $user_id)->first(); $like_id = DB::table('likes')->select('id')->where('post_id', $post_id)->where('user_id', $user_id)->delete(); $Ninput['sender_id'] = $user_id; $Ninput['receiver_id'] = Posts::getPostOwner($post_id); $Ninput['type_id'] = $like_data->id; $Ninput['type'] = 'like'; Notifications::RemoveNotification($Ninput); if ($like_id) { return Response::json(array('status' => '1', 'msg' => 'Post Unliked'), 200); } } else { return Response::json(array('status' => '0', 'msg' => "Token Expired"), 200); } } }
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); } } }