本文整理汇总了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);
}
}