public function remove($giftId) { $result = array("error" => true, "error_code" => ERROR_UNKNOWN); $giftInfo = $this->info($giftId); if ($giftInfo['error'] === true) { return $result; } if ($giftInfo['giftTo'] != $this->requestFrom) { return $result; } $currentTime = time(); $stmt = $this->db->prepare("UPDATE gifts SET removeAt = (:removeAt) WHERE id = (:giftId)"); $stmt->bindParam(":giftId", $giftId, PDO::PARAM_INT); $stmt->bindParam(":removeAt", $currentTime, PDO::PARAM_INT); if ($stmt->execute()) { $result = array("error" => false, "error_code" => ERROR_SUCCESS); $account = new account($this->db, $giftInfo['giftTo']); $account->updateCounters(); unset($account); $notify = new notify($this->db); $notify->removeNotify($giftInfo['giftTo'], $giftInfo['giftFrom'], NOTIFY_TYPE_GIFT, $giftInfo['id']); unset($notify); } return $result; }
public function addFollower($follower_id) { $result = array("error" => true, "error_code" => ERROR_UNKNOWN); $account = new account($this->db, $this->id); $account->setLastActive(); unset($account); if ($this->is_friend_exists($follower_id)) { return $result; } if ($this->is_follower_exists($follower_id)) { $stmt = $this->db->prepare("DELETE FROM profile_followers WHERE follower = (:follower) AND follow_to = (:follow_to)"); $stmt->bindParam(":follower", $follower_id, PDO::PARAM_INT); $stmt->bindParam(":follow_to", $this->id, PDO::PARAM_INT); $stmt->execute(); $result = array("error" => false, "error_code" => ERROR_SUCCESS, "follow" => false, "followersCount" => 0); $notify = new notify($this->db); $notify->removeNotify($this->id, $follower_id, NOTIFY_TYPE_FOLLOWER, 0); unset($notify); } else { $create_at = time(); $stmt = $this->db->prepare("INSERT INTO profile_followers (follower, follow_to, create_at) value (:follower, :follow_to, :create_at)"); $stmt->bindParam(":follower", $follower_id, PDO::PARAM_INT); $stmt->bindParam(":follow_to", $this->id, PDO::PARAM_INT); $stmt->bindParam(":create_at", $create_at, PDO::PARAM_INT); $stmt->execute(); $blacklist = new blacklist($this->db); $blacklist->setRequestFrom($this->id); if (!$blacklist->isExists($follower_id)) { $account = new account($this->db, $this->id); if ($account->getAllowFollowersGCM() == ENABLE_FOLLOWERS_GCM) { $gcm = new gcm($this->db, $this->id); $gcm->setData(GCM_NOTIFY_FOLLOWER, "You have new follower", 0); $gcm->send(); } unset($account); $notify = new notify($this->db); $notify->createNotify($this->id, $follower_id, NOTIFY_TYPE_FOLLOWER, 0); unset($notify); } unset($blacklist); $result = array("error" => false, "error_code" => ERROR_SUCCESS, "follow" => true, "followersCount" => 0); } return $result; }