Beispiel #1
0
/**
 * Fixes review overall rating.
 *
 * @since 1.0.0
 * @package GeoDirectory
 * @global object $wpdb WordPress Database object.
 */
function geodir_fix_review_overall_rating()
{
    global $wpdb;
    $all_postypes = geodir_get_posttypes();
    if (!empty($all_postypes)) {
        foreach ($all_postypes as $key) {
            // update each GD CTP
            $reviews = $wpdb->get_results("SELECT post_id FROM " . $wpdb->prefix . "geodir_" . $key . "_detail d");
            if (!empty($reviews)) {
                foreach ($reviews as $post_id) {
                    geodir_update_postrating($post_id->post_id, $key);
                }
            }
        }
    }
}
Beispiel #2
0
/**
 * Delete review details when deleting comment.
 *
 * @since 1.0.0
 * @package GeoDirectory
 * @param int $comment_id The comment ID.
 * @global object $wpdb WordPress Database object.
 */
function geodir_comment_delete_comment($comment_id)
{
    global $wpdb;
    $review_info = geodir_get_review($comment_id);
    if ($review_info) {
        geodir_update_postrating($review_info->post_id);
    }
    $wpdb->query($wpdb->prepare("DELETE FROM " . GEODIR_REVIEW_TABLE . " WHERE comment_id=%d", array($comment_id)));
}
/**
 * Review manager update rating for a post.
 *
 * @since 1.0.0
 * @package GeoDirectory_Review_Rating_Manager
 *
 * @param int $post_id The post ID.
 * @param array $ratings The rating information.
 * @param float $overall overall rating.
 */
function geodir_reviewrating_update_postrating($post_id = 0, $ratings, $overall)
{
    geodir_reviewrating_update_postrating_all($post_id);
    return;
    // DISABLED FOR NOW, WE WILL JUST CALL AN OVERAL UPDATE FUNCTION ON COMMENT SAVE. geodir_reviewrating_update_postrating_all
    global $wpdb, $plugin_prefix;
    $post = get_post($post_id);
    $post_ratings = array();
    $post_ratings = geodir_reviewrating_get_post_rating($post_id);
    //print_r($post_ratings);exit;
    $old_ratings = $post_ratings;
    $new_ratings = array();
    //print_r($ratings);exit;
    if (!empty($ratings)) {
        $r_count = count($ratings);
        foreach ($ratings as $rating_id => $rating_value) {
            $rating_info = geodir_reviewrating_rating_categories($rating_id);
            if (!empty($post_ratings) && array_key_exists($rating_id, $old_ratings)) {
                $new_rating_value = (double) $old_ratings[$rating_id]['r'] + (double) $rating_value;
                $new_ratings[$rating_id]['c'] = $new_rating_value;
                $new_ratings[$rating_id]['r'] = (double) $old_ratings[$rating_id]['c'] + 1;
            } else {
                $new_ratings[$rating_id]['c'] = (double) $r_count;
                $new_ratings[$rating_id]['r'] = (double) $rating_value;
            }
        }
    }
    //update rating
    geodir_update_postrating($post_id, $post->post_type);
}