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 "
"; } } ?>| " . $counts[$assignment_status->term_id] . " | "; echo "$assignment_status->name |
| " . _('No assigned stories.') . " |
| $q->found_posts | "; echo "" . __('Published this month') . " |
$count_pending pending assignment"; echo ($count_pending != 1)? 's': ''; echo "
"; echo "| {$post->post_title} | {$pending[1]->name} | "; echo "Accept "; echo "Decline "; echo "ID}-summary').slideToggle();\">Details | "; echo "
| "; echo " | |