當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Vote::delete_comment_vote方法代碼示例

本文整理匯總了PHP中Vote::delete_comment_vote方法的典型用法代碼示例。如果您正苦於以下問題:PHP Vote::delete_comment_vote方法的具體用法?PHP Vote::delete_comment_vote怎麽用?PHP Vote::delete_comment_vote使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Vote的用法示例。


在下文中一共展示了Vote::delete_comment_vote方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: Vote

  /**
   * return "OK" only delete
   *        > 0 - usual behavior: first delete then insert
   *        0  error
   */
	function insert_vote($value = 0) {
		global $current_user, $db;

		if (!$value) $value = $current_user->user_karma;

		$vote = new Vote('comments', $this->id, $current_user->user_id);

    $result = 'CREATE'; // vote doesn't exits?

		if ($old_value = $vote->exists(false)) { // save old vote value
      $result = 'REPLACE';
      $vote->delete_comment_vote($old_value); // always destroy current vote

      // check if they have the same sign
      if ($value * $old_value > 0) {
        return Array('DELETE',$old_value); // equal => only delete
      }
		}

		// Affinity
		if ($current_user->user_id != $this->author
				&& ($affinity = User::get_affinity($this->author, $current_user->user_id)) ) {
			if ($value < -1 && $affinity < 0) {
					$value = round(min(-1, $value *  abs($affinity/100)));
			} elseif ($value > 1 && $affinity > 0) {
					$value = round(max($value * $affinity/100, 1));
			}
		}

    $value>0?$svalue='+'.$value:$svalue=$value;

		$vote->value = $value;
		$db->transaction();
		if($vote->insert()) {
			if ($current_user->user_id != $this->author) {
        //echo "update comments set comment_votes=comment_votes+1, comment_karma=comment_karma$svalue, comment_date=comment_date where comment_id=$this->id";
				$db->query("update comments set comment_votes=comment_votes+1, comment_karma=comment_karma$svalue, comment_date=comment_date where comment_id=$this->id");
			}
		} else {
			$vote->value = false;
		}
		$db->commit();

    if ($result == 'CREATE') {
      return Array($result, $vote->value);
    } else { // replace
      return Array($result, $old_value);
    }
	}
開發者ID:rasomu,項目名稱:chuza,代碼行數:54,代碼來源:comment.php


注:本文中的Vote::delete_comment_vote方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。