Exemple #1
0
/**
 * Handles AJAX request for remove a reviewer to a post.
 */
function annowf_remove_reviewer()
{
    $response = annowf_remove_user('reviewer');
    $response['decrement'] = 0;
    if ($response['message'] == 'success') {
        $post_id = absint($_POST['post_id']);
        $user_id = absint($_POST['user_id']);
        // Send back to submitted state if we've removed all the reviewers
        if (count(anno_get_reviewers($post_id)) == 0) {
            update_post_meta($post_id, '_post_state', 'submitted');
        }
        // Check if the user had already left a review and send back in response to update dom appropriately
        $round = annowf_get_round($post_id);
        $reviews = get_post_meta($post_id, '_round_' . $round . '_reviewed', true);
        if (!is_array($reviews)) {
            $reviews = array();
        }
        if (in_array($user_id, $reviews)) {
            $key = array_search($user_id, $reviews);
            unset($reviews[$key]);
            update_post_meta($post_id, '_round_' . $round . '_reviewed', $reviews);
            $response['decrement'] = 1;
        }
        //Add to the audit log
        $current_user = wp_get_current_user();
        annowf_save_audit_item($post_id, $current_user->ID, 9, array($user_id));
    }
    echo json_encode($response);
    die;
}
/**
 * In Review state markup for minor actions.
 */
function annowf_minor_action_in_review_markup()
{
    if (anno_user_can('edit_post')) {
        global $post;
        $post_round = annowf_get_round($post->ID);
        annowf_minor_action_save_markup();
        annowf_minor_action_preview_markup();
        if ($post_round !== false) {
            // Return array of user ids who have given reviews for this round
            $round_reviewed = get_post_meta($post->ID, '_round_' . $post_round . '_reviewed', true);
            if (!is_array($round_reviewed)) {
                $round_reviewed = array();
            }
            $round_reviewed = count($round_reviewed);
            $reviewers = count(anno_get_reviewers($post->ID));
            ?>
			<p class="status-text">
<?php 
            printf(_x('%s of %s Reviews Complete', 'Article publishing box meta text', 'anno'), '<span id="anno-reviewed-count">' . $round_reviewed . '</span>', '<span id="anno-reviewers-count">' . $reviewers . '</span>');
        }
    } else {
        ?>
			<p class="status-text">
<?php 
        _ex('Submitted - In Review', 'Publishing box meta text', 'anno');
    }
    ?>
		</p>
<?php 
}
Exemple #3
0
/**
 * Get a user's review for a post for the current round.
 * @param int $post_id
 * @param int $user_id
 * @return int|bool Integer corresponding to the user's review (can be 0), false if none can be found
 */
function annowf_get_user_review($post_id, $user_id)
{
    $round = annowf_get_round($post_id);
    return get_user_meta($user_id, '_' . $post_id . '_review_' . $round, true);
}
/**
 * Processes an AJAX request when submitting a review from the dropdown.
 */
function anno_internal_comments_review_ajax()
{
    check_ajax_referer('anno_review', '_ajax_nonce-review');
    if (isset($_POST['post_id']) && isset($_POST['review'])) {
        global $current_user;
        $post_id = absint($_POST['post_id']);
        $review = $_POST['review'];
        $post_round = annowf_get_round($post_id);
        update_user_meta($current_user->ID, '_' . $post_id . '_review_' . $post_round, $review);
        $reviewed = get_post_meta($post_id, '_round_' . $post_round . '_reviewed', true);
        if (!is_array($reviewed)) {
            $reviewed = array();
        }
        // If review is set to none, remove the user from reviewed, otherwise update it with the current user.
        if ($review != 0) {
            // Keep track that this user has left a review on the post
            if (!in_array($current_user->ID, $reviewed)) {
                $reviewed[] = $current_user->ID;
                update_post_meta($post_id, '_round_' . $post_round . '_reviewed', array_unique($reviewed));
            }
            // Send notification
            $post = get_post(intval($post_id));
            annowf_send_notification('review_recommendation', $post, null, null, $current_user->ID);
            annowf_save_audit_item($post_id, $current_user->ID, 4, array($review));
        } else {
            $key = array_search($current_user->ID, $reviewed);
            if ($key !== false) {
                unset($reviewed[$key]);
                update_post_meta($post_id, '_round_' . $post_round . '_reviewed', array_unique($reviewed));
            }
        }
        echo $review;
    }
    die;
}