Example #1
0
 public function getFriends($userId)
 {
     $db_parse = new DbHandlerParse();
     $usersArray = array();
     $db_mark = new DbHandlerMark();
     $db_mark->run_sql("SELECT * FROM follow WHERE follower_user_id = '{$userId}'");
     $stmt = $this->conn->prepare("SELECT * FROM follow WHERE follower_user_id = ?");
     $stmt->bind_param("s", $userId);
     if ($stmt->execute()) {
         /* Store the result (to get properties) */
         $stmt->store_result();
         /* Get the number of rows */
         $num_of_rows = $stmt->num_rows;
         /* Bind the result to variables */
         $stmt->bind_result($id, $followerUserId, $followedUserId, $status, $createdAt);
         while ($stmt->fetch()) {
             //echo 'ID: '.$id.'<br>';
             //echo 'Follower: '.$followerUserId.'<br>';
             //echo 'Followed: '.$followedUserId.'<br>';
             //echo 'status: '.$status.'<br>';
             //echo 'Created: '.$createdAt.'<br><br>';
             //printf("Follower ID: %s  Created: %s", $followerUserId, $createdAt);
             array_push($usersArray, $db_parse->getUserById($followedUserId));
         }
         /* free results */
         $stmt->free_result();
     }
     $stmt->close();
     return $usersArray;
 }
Example #2
0
 /**
  * Destroy friendship between requesting user and requested user
  * @param String $userId user id to whom call belongs to
  * @param String $friendUserId user id of the requested user
  */
 public function destroyFriendShip($userId, $friendUserId)
 {
     // Verify that requested friend exists
     $db_parse = new DbHandlerParse();
     $isFriendExist = $db_parse->isUserIdExists($friendUserId);
     if (!$isFriendExist || empty($userId) || $userId == $friendUserId) {
         echo $isFriendExist;
         return NULL;
     }
     // Verify that already following
     $stmt = $this->conn->prepare("SELECT f.follower_user_id, f.followed_user_id, f.status, f.created from follow f WHERE f.follower_user_id = ? AND f.followed_user_id = ?");
     $stmt->bind_param("ss", $userId, $friendUserId);
     if ($stmt->execute()) {
         $ret = $stmt->get_result()->fetch_assoc();
         $stmt->close();
         if (empty($ret)) {
             //echo "user is not already following friend!";
             return NULL;
         }
     }
     $db_mark = new DbHandlerMark();
     $db_mark->run_sql("DELETE from follow WHERE follower_user_id = '{$userId}' AND followed_user_id = '{$friendUserId}'");
     $stmt = $this->conn->prepare("DELETE from follow WHERE follower_user_id = ? AND followed_user_id = ?");
     $stmt->bind_param("ss", $userId, $friendUserId);
     $result = $stmt->execute();
     $stmt->close();
     if ($result) {
         // follow row removed
         $stmt = $this->conn->prepare("SELECT f.follower_user_id, f.followed_user_id, f.status, f.created from follow f WHERE f.follower_user_id = ? AND f.followed_user_id = ?");
         $stmt->bind_param("ss", $userId, $friendUserId);
         if ($stmt->execute()) {
             $ret = $stmt->get_result()->fetch_assoc();
             $stmt->close();
             if (empty($ret)) {
                 //echo "user is no longer following friend!";
                 return TRUE;
             }
         } else {
             return NULL;
         }
     } else {
         // unfollow request failed
         //echo "uh oh, why can't you unfollow friend?";
         return NULL;
     }
 }