get_var($wpdb->prepare("SELECT count FROM $wpdb->term_taxonomy WHERE taxonomy = '%s' AND term_id = %d", $assignment_desk->custom_taxonomies->assignment_status_label, $status->term_id)); $count = $count ? $count : 0; return $count; } /** * Count the unpublished posts assigned to the current user. * Users coauthors if enabled. * @param term $status The term from the assignment_status taxonomy. * @return int the number of unpublished posts of that assignment_status assigned to the current user */ function count_user_posts_by_assignment_status( $status ) { global $current_user, $wpdb, $assignment_desk; get_currentuserinfo(); $count = 0; // Query for all the unpublished posts where $current_user is a coauthor. // Then tally up the count for the status. if ( $assignment_desk->coauthors_plus_exists() ){ $posts = $wpdb->get_results("SELECT * FROM $wpdb->posts LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id) LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_taxonomy.term_taxonomy_id = $wpdb->term_relationships.term_taxonomy_id) LEFT JOIN $wpdb->terms ON($wpdb->terms.term_id = $wpdb->term_taxonomy.term_id) WHERE $wpdb->posts.post_status != 'publish' AND $wpdb->posts.post_status != 'inherit' AND $wpdb->posts.post_status != 'trash' AND $wpdb->posts.post_status != 'auto-draft' AND $wpdb->term_taxonomy.taxonomy = 'author' AND $wpdb->terms.name = '$current_user->user_login'"); foreach ( $posts as $post ){ $post_assignment_status = wp_get_object_terms($post->ID, $assignment_desk->custom_taxonomies->assignment_status_label); if ( $post_assignment_status && $post_assignment_status[0]->term_id == $status->term_id ){ $count++; } } } else { // Slightly easier without coauthors. // Just query for the count. $count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id) LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_taxonomy.term_taxonomy_id = $wpdb->term_relationships.term_taxonomy_id) WHERE $wpdb->posts.post_author = '$current_user->ID' AND $wpdb->posts.post_status != 'publish' AND $wpdb->posts.post_status != 'inherit' AND $wpdb->posts.post_status != 'trash' AND $wpdb->posts.post_status != 'auto-draft' AND $wpdb->term_taxonomy.taxonomy = '{$assignment_desk->custom_taxonomies->assignment_status_label}' AND $wpdb->term_taxonomy.term_id = $status->term_id "); } return $count; } /** * Display the Assignment Desk dashboard widget. */ function widget() { global $assignment_desk, $current_user, $wpdb; get_currentuserinfo(); $assignment_statuses = $assignment_desk->custom_taxonomies->get_assignment_statuses(); if ( $_REQUEST['ad-dashboard-assignment-messages'] ) { foreach( $_REQUEST['ad-dashboard-assignment-messages'] as $message ) { echo "
$message
"; } } ?>

define_editor_permissions) ) { // Count all posts with a certain status $counts[$assignment_status->term_id] = $this->count_posts_by_assignment_status($assignment_status); } else { // Count all posts that this user can edit with a certain status $counts[$assignment_status->term_id] = $this->count_user_posts_by_assignment_status($assignment_status); } $total_unpublished_assignments += $counts[$assignment_status->term_id]; } if ( $total_unpublished_assignments ) { foreach ( $assignment_statuses as $assignment_status ) { // if ( $counts[$assignment_status->term_id] ) { $url = admin_url() . "edit.php?ad-assignment-status=$assignment_status->term_id"; echo ""; echo ""; // } } } else { echo ""; } ?>
" . $counts[$assignment_status->term_id] . "$assignment_status->name
" . _('No assigned stories.') . "
define_editor_permissions) ) : ?>

'publish', 'monthnum' => date('M'))); echo ""; echo ""; ?>
$q->found_posts" . __('Published this month') . "
get_results("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_ad_participant_{$current_user->ID}' ORDER BY post_id"); if ( !$participant_posts ){ $participant_posts = array(); } $roles = $assignment_desk->custom_taxonomies->get_user_roles(); $max_pending = 5; foreach( $participant_posts as $post ){ foreach( $roles as $user_role ) { // Get all of the roles this user has for this post $participant_record = get_post_meta($post->post_id, "_ad_participant_role_$user_role->term_id", true); if($participant_record) { foreach ($participant_record as $user_id => $status ){ if( $user_id == $current_user->ID && $status == 'pending' ){ $pending_posts[] = array($post->post_id, $user_role); $max_pending--; } } } } if(!$max_pending){ break; } } $count_pending = count($pending_posts); if ( $count_pending ) { echo "
"; echo "

$count_pending pending assignment"; echo ($count_pending != 1)? 's': ''; echo "

"; echo "
"; foreach($pending_posts as $pending) { $post = get_post($pending[0]); echo ""; echo ""; echo ""; echo ""; echo ""; } echo "
{$post->post_title} | {$pending[1]->name}Accept "; echo "Decline "; echo "ID}-summary').slideToggle();\">Details
"; echo "
"; } } /** * Confirm or decline a story assignment. */ function respond_to_story_invite(){ global $current_user, $assignment_desk, $coauthors_plus, $user_ID; $response = $_GET['participant_response']; $post_id = (int)$_GET['post_id']; $role_id = (int)$_GET['role_id']; get_currentuserinfo(); if ( !$current_user->ID || !$user_ID || !$post_id || !$role_id ) { $_REQUEST['ad-dashboard-assignment-messages'][] = _('Unauthorized assignment response. This is fishy.'); } $_REQUEST['ad-dashboard-assignment-messages'] = array(); if ( $response && $post_id && $role_id ) { $participant_record = get_post_meta($post_id, "_ad_participant_role_$role_id", true); // Are we waiting for a response from this user for this post/role? if ( $participant_record && $participant_record[$current_user->ID] == 'pending' ) { $participant_record[$current_user->ID] = $response; if ( $response == 'accepted' ) { // Add as a coauthor if ( $assignment_desk->coauthors_plus_exists() ) { $coauthors_plus->add_coauthors($post_id, array($current_user->user_login), true); } // Add as author else { wp_update_post(array( 'ID' => $post_id, $author => $current_user->user_login )); } $_REQUEST['ad-dashboard-assignment-messages'][] = _('Thank you.'); $user_participant = get_post_meta($post_id, "_ad_participant_$current_user->ID", true); if ( !$user_participant ) { $user_participant = array(); } $user_participant[] = $role_id; update_post_meta($post_id, "_ad_participant_$current_user->ID", $user_participant); } else if($response == 'declined'){ $_REQUEST['ad-dashboard-assignment-messages'][] = _("Sorry."); } } update_post_meta($post_id, "_ad_participant_role_$role_id", $participant_record); } } } ?>