Ejemplo n.º 1
0
 public function add($userId, $reason = "")
 {
     $result = array("error" => true, "error_code" => ERROR_UNKNOWN);
     $currentTime = time();
     $ip_addr = helper::ip_addr();
     $u_agent = helper::u_agent();
     $stmt = $this->db->prepare("INSERT INTO profile_blacklist (blockedByUserId, blockedUserId, reason, createAt, ip_addr, u_agent) value (:blockedByUserId, :blockedUserId, :reason, :createAt, :ip_addr, :u_agent)");
     $stmt->bindParam(":blockedByUserId", $this->requestFrom, PDO::PARAM_INT);
     $stmt->bindParam(":blockedUserId", $userId, PDO::PARAM_INT);
     $stmt->bindParam(":reason", $reason, PDO::PARAM_STR);
     $stmt->bindParam(":createAt", $currentTime, PDO::PARAM_INT);
     $stmt->bindParam(":ip_addr", $ip_addr, PDO::PARAM_STR);
     $stmt->bindParam(":u_agent", $u_agent, PDO::PARAM_STR);
     if ($stmt->execute()) {
         $result = array("error" => false, "error_code" => ERROR_SUCCESS);
         $my_profile = new profile($this->db, $this->requestFrom);
         if ($my_profile->is_friend_exists($userId)) {
             $friends = new friends($this->db, $this->requestFrom);
             $friends->remove($userId);
             unset($friends);
         } else {
             if ($my_profile->is_follower_exists($userId)) {
                 // Unfollow
                 $my_profile->addFollower($userId);
             }
             $profile = new profile($this->db, $userId);
             if ($profile->is_follower_exists($this->requestFrom)) {
                 $profile->addFollower($this->requestFrom);
             }
             unset($profile);
         }
         unset($my_profile);
     }
     return $result;
 }
Ejemplo n.º 2
0
 public function remove($friendId)
 {
     $result = array("error" => true, "error_code" => ERROR_UNKNOWN);
     $my_profile = new profile($this->db, $this->profileId);
     if ($my_profile->is_friend_exists($friendId)) {
         $currentTime = time();
         $stmt = $this->db->prepare("UPDATE friends SET removeAt = (:removeAt) WHERE friendTo = (:friendTo) AND friend = (:friend) AND removeAt = 0");
         $stmt->bindParam(":friendTo", $this->profileId, PDO::PARAM_INT);
         $stmt->bindParam(":friend", $friendId, PDO::PARAM_INT);
         $stmt->bindParam(":removeAt", $currentTime, PDO::PARAM_INT);
         if ($stmt->execute()) {
             $result = array("error" => false, "error_code" => ERROR_SUCCESS);
             $stmt2 = $this->db->prepare("UPDATE friends SET removeAt = (:removeAt) WHERE friend = (:friend) AND friendTo = (:friendTo) AND removeAt = 0");
             $stmt2->bindParam(":friend", $this->profileId, PDO::PARAM_INT);
             $stmt2->bindParam(":friendTo", $friendId, PDO::PARAM_INT);
             $stmt2->bindParam(":removeAt", $currentTime, PDO::PARAM_INT);
             $stmt2->execute();
             $account = new account($this->db, $this->profileId);
             $account->updateCounters();
             unset($account);
             $account = new account($this->db, $friendId);
             $account->updateCounters();
         }
     }
     return $result;
 }