示例#1
0
 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 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;
 }
 public function like($fromUserId)
 {
     $result = array("error" => true, "error_code" => ERROR_UNKNOWN);
     $account = new account($this->db, $fromUserId);
     $account->setLastActive();
     unset($account);
     if ($this->is_like_exists($fromUserId)) {
         $removeAt = time();
         $stmt = $this->db->prepare("UPDATE profile_likes SET removeAt = (:removeAt) WHERE toUserId = (:toUserId) AND fromUserId = (:fromUserId) AND removeAt = 0");
         $stmt->bindParam(":fromUserId", $fromUserId, PDO::PARAM_INT);
         $stmt->bindParam(":toUserId", $toUserId, PDO::PARAM_INT);
         $stmt->bindParam(":removeAt", $removeAt, PDO::PARAM_INT);
         $stmt->execute();
         $notify = new notify($this->db);
         $notify->removeNotify($this->id, $fromUserId, NOTIFY_TYPE_LIKE, 0);
         unset($notify);
         $myLike = false;
     } else {
         $createAt = time();
         $ip_addr = helper::ip_addr();
         $stmt = $this->db->prepare("INSERT INTO profile_likes (toUserId, fromUserId, createAt, ip_addr) value (:toUserId, :fromUserId, :createAt, :ip_addr)");
         $stmt->bindParam(":toUserId", $this->id, PDO::PARAM_INT);
         $stmt->bindParam(":fromUserId", $fromUserId, PDO::PARAM_INT);
         $stmt->bindParam(":createAt", $createAt, PDO::PARAM_INT);
         $stmt->bindParam(":ip_addr", $ip_addr, PDO::PARAM_STR);
         $stmt->execute();
         $myLike = true;
         if ($this->id != $fromUserId) {
             $blacklist = new blacklist($this->db);
             $blacklist->setRequestFrom($this->id);
             if (!$blacklist->isExists($fromUserId)) {
                 $account = new account($this->db, $this->id);
                 if ($account->getAllowLikesGCM() == ENABLE_LIKES_GCM) {
                     $gcm = new gcm($this->db, $this->id);
                     $gcm->setData(GCM_NOTIFY_LIKE, "You have new like", 0);
                     $gcm->send();
                 }
                 unset($account);
                 $notify = new notify($this->db);
                 $notify->createNotify($this->id, $fromUserId, NOTIFY_TYPE_LIKE, 0);
                 unset($notify);
             }
             unset($blacklist);
         }
     }
     $account = new account($this->db, $this->id);
     $account->updateCounters();
     $likesCount = $account->getLikesCount();
     unset($account);
     $result = array("error" => false, "error_code" => ERROR_SUCCESS, "likesCount" => $likesCount, "myLike" => $myLike);
     return $result;
 }
 public function remove($photoId)
 {
     $result = array("error" => true);
     $photoInfo = $this->info($photoId);
     if ($photoInfo['error'] === true) {
         return $result;
     }
     if ($photoInfo['fromUserId'] != $this->requestFrom) {
         return $result;
     }
     $currentTime = time();
     $stmt = $this->db->prepare("UPDATE photos SET removeAt = (:removeAt) WHERE id = (:photoId)");
     $stmt->bindParam(":photoId", $photoId, PDO::PARAM_INT);
     $stmt->bindParam(":removeAt", $currentTime, PDO::PARAM_INT);
     if ($stmt->execute()) {
         $result = array("error" => false);
         $account = new account($this->db, $photoInfo['fromUserId']);
         $account->updateCounters();
         unset($account);
     }
     return $result;
 }