Exemplo n.º 1
0
function addFriendRequest()
{
    $rm = new Response_Methods();
    if ($_SERVER['REQUEST_METHOD'] == "GET") {
        $result = $rm->inValidServerMethod();
        return $result;
    }
    //Check request url is https or not
    if (!empty($_SERVER["HTTPS"])) {
        if ($_SERVER["HTTPS"] !== "off") {
            $userId = trim($_POST['userId']);
            $friendId = trim($_POST['friendId']);
            if ($userId == "" || $friendId == "") {
                $result = $rm->fields_validation();
                return $result;
            } else {
                if ($userId == $friendId) {
                    $result = $rm->friendRequestFailforSameUser();
                    return $result;
                } else {
                    $checkFriend = $rm->checkExistingFriendShip($userId, $friendId);
                    if ($checkFriend > 0) {
                        $result = $rm->friendshipAlreadyExists();
                        return $result;
                    }
                    date_default_timezone_set('Asia/Calcutta');
                    $createdDate = date('Y-m-d H:i:s');
                    $getList = array();
                    //preparing list and inserting values in friends_t table
                    $getInsertFieldValue['friend_one'] = $userId;
                    $getInsertFieldValue['friend_two'] = $friendId;
                    $getInsertFieldValue['created_date_f'] = $createdDate;
                    $lastInserted_friend_id = $rm->insert_record($getInsertFieldValue, 'friends_t');
                    if (!empty($lastInserted_friend_id)) {
                        $deviceId = $rm->idToValue('device_id_f', 'user_details_t', 'user_id', $friendId);
                        //getting deviceId
                        if ($deviceId) {
                            $message = "You have received a friend request in petbesties.";
                            $rm->sendPushNotification($deviceId, $message);
                        }
                        $result = $rm->friendRequestSuccess();
                        return $result;
                    } else {
                        $result = $rm->friendRequestFail();
                        return $result;
                    }
                }
            }
            // end of else first
        } else {
            $result = $rm->ssl_error();
            return $result;
        }
    } else {
        $result = $rm->ssl_error();
        return $result;
    }
}
 public function getSingleUserSearchDetails($USERID, $loggedInUserId)
 {
     $sqlFetchAllUsers = "SELECT U.user_id, U.user_name_f, U.profile_pic_f,MAX(N.like_count_f) as like_count FROM user_details_t U left join news_feeds_t N on N.user_id_fk = U.user_id where U.user_id={$USERID}";
     $errorSuccessCode = 20;
     //echo $sqlFetchAllUsers;
     $dataResultSet = mysql_query($sqlFetchAllUsers, $GLOBALS['link']);
     $rm = new Response_Methods();
     $getGrpDetails = array();
     $getArrayList = array();
     if (mysql_num_rows($dataResultSet) > 0) {
         while ($row = mysql_fetch_array($dataResultSet)) {
             $friend_user_id = $row['user_id'];
             $user_name = $row['user_name_f'];
             $profile_pic = $row['profile_pic_f'];
             $like_count = $row['like_count'];
             $getGrpDetails['user_id'] = $friend_user_id;
             $getGrpDetails['user_name'] = $user_name;
             $getGrpDetails['profile_pic_url'] = $profile_pic;
             $getGrpDetails['like_count'] = $like_count;
             $aboutUser = $rm->idToValue('description_f', 'user_details_t', 'user_id', $friend_user_id);
             //getting user description
             if ($aboutUser) {
                 $getGrpDetails['about_user'] = $aboutUser;
             } else {
                 $getGrpDetails['about_user'] = "******";
             }
             //setting default description text
             $checkFriend = $rm->checkExistingFriendShip($loggedInUserId, $USERID);
             //checking friend relation
             if ($checkFriend == 0) {
                 $getGrpDetails['friend_status'] = "-1";
             } else {
                 $friendStatus = $rm->getFriendStatus($loggedInUserId, $USERID);
                 $getGrpDetails['friend_status'] = $friendStatus;
             }
             $checkFollow = $rm->checkExistingFollow($loggedInUserId, $USERID);
             //check whether any follow relationship exists between them
             if ($checkFollow > 0) {
                 $getGrpDetails['follow_status'] = "1";
             } else {
                 $getGrpDetails['follow_status'] = "0";
             }
             $followArray = $rm->followerFollowingCount($USERID);
             $getGrpDetails['followersCount'] = $followArray['followers'];
             $getGrpDetails['followingCount'] = $followArray['following'];
             array_push($getArrayList, $getGrpDetails);
         }
         //print_r($getArrayList);
         $newData = json_encode($getArrayList);
         $newData = str_replace('\\/', '/', $newData);
         $newData = substr($newData, 1, strlen($newData) - 2);
         $newData = "{\"data\":{\"Error_Code\":\"{$errorSuccessCode}\",\"Error_Msg\":\"Single User Details\",\"result\":" . $newData . "}}";
         return $newData;
     } else {
         $errorCode = "0";
         $errorMsg = "No Users Found";
         $newData = "{\"data\":{\"Error_Code\":\"" . $errorCode . "\",\"Error_Msg\":\"" . $errorMsg . "\"}}";
         //Json Format Response
         return $newData;
         //Login Unsuccessful
     }
 }