예제 #1
0
        if (is_user_logged_in()) {
            return get_current_user_id();
        } else {
            return self::get_client_ip();
        }
    }
    public static function set_vote($vote, $metric, $context_id, $user_id)
    {
        $metric_type = Evaluate_Metrics::get_metric_types()[$metric['type']];
        $old_vote = $metric_type->get_vote($metric, $context_id, $user_id);
        $vote = $metric_type->validate_vote($vote, $old_vote, $metric['options']);
        $metric_type->set_vote($vote, $metric, $context_id, $user_id);
        $score = $metric_type->get_score($metric['metric_id'], $context_id);
        $score = $metric_type->modify_score($score, $vote, $old_vote, $metric, $context_id);
        return array('count' => $score['count'], 'average' => $score['average'], 'data' => $score['data'], 'vote' => $vote);
    }
    public static function clear_votes($metric_id = null, $context = null)
    {
        global $wpdb;
        $where = array();
        if ($metric_id != null) {
            $where['metric_id'] = $metric_id;
        }
        if ($context != null) {
            $where['context_id'] = $context;
        }
        $wpdb->delete(Evaluate::$voting_table, $where);
    }
}
Evaluate_Voting::init();