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; } /** * Get the most recent unpublished posts for the current user * @author danielbachhuber * @return object $the_posts All of the posts */ function get_user_upcoming_posts( $args = null ) { global $current_user, $wpdb, $assignment_desk; get_currentuserinfo(); $defaults = array( 'user_id' => $current_user->ID, 'user_login' => $current_user->user_login, 'showposts' => 5, ); if ( $args ) { $args = array_merge( $defaults, $args ); } else { $args = $defaults; } if ( $assignment_desk->coauthors_plus_exists() ){ $the_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 = '{$args['user_login']}' LIMIT {$args['showposts']};"); } else { $the_posts = $wpdb->get_var("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) WHERE $wpdb->posts.post_author = '{$args['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 LIMIT {$args['showposts']};"); } return $the_posts; } /** * Display the Assignment Desk dashboard widget * @todo Historical data * @todo $_GET implementation * @todo AJAX implementation */ function widget() { global $assignment_desk, $current_user, $wpdb; get_currentuserinfo(); $assignment_statuses = $assignment_desk->custom_taxonomies->get_assignment_statuses(); $pending_posts = array(); $upcoming_posts = array(); $max_pending = 5; $max_upcoming = 10; // Find all of the posts this user participates in. $participant_posts = $wpdb->get_results("SELECT * FROM $wpdb->postmeta WHERE meta_key = '_ad_participant_{$current_user->ID}' ORDER BY post_id LIMIT 20;"); if ( !$participant_posts ){ $participant_posts = array(); } $default_roles = $assignment_desk->custom_taxonomies->get_user_roles(); // foreach ( $participant_posts as $post ) { foreach ( $default_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' && $max_pending ) { $pending_posts[] = array($post->post_id, $user_role); $max_pending--; $max_upcoming--; } else if ( $user_id == $current_user->ID && $status == 'accepted' && $max_upcoming ) { $upcoming_posts[$post->post_id]['roles'][] = $user_role; $max_upcoming--; } } } } } echo "
$summary
"; } echo ''; echo '';
if ( $assignment_desk->edit_flow_enabled() ) {
global $edit_flow;
// Edit Flow v0.6 and higher offers custom editorial metadata. Otherwise, fall back on old
if ( version_compare( '0.6', EDIT_FLOW_VERSION, '>=' ) ) {
$terms = $edit_flow->editorial_metadata->get_editorial_metadata_terms();
foreach ( $terms as $term ) {
$form_key = $edit_flow->editorial_metadata->get_postmeta_key( $term );
$saved_value = get_post_meta( $post->ID, $form_key, true );
if ( $saved_value ) {
$html_value = '';
// Give us different inputs based on the metadata type
switch ( $term_type = $edit_flow->editorial_metadata->get_metadata_type( $term ) ) {
case 'checkbox':
$html_value = ( $saved_value ) ? 'Yes' : 'No';
break;
case 'date':
$html_value = date_i18n( get_option( 'date_format' ), $saved_value );
break;
case 'location':
$html_value = $saved_value;
break;
case 'paragraph':
$html_value = $saved_value;
break;
case 'text':
$html_value = $saved_value;
break;
case 'user':
$html_value = get_the_author_meta( 'display_name', $saved_value );
break;
default:
$html_input = '';
break;
}
echo '' . $term->name . ': ' . $html_value . '
';
}
}
} else {
$description = get_post_meta( $post->ID, '_ef_description', true );
$location = get_post_meta( $post->ID, '_ef_location', true );
$duedate = get_post_meta( $post->ID, '_ef_duedate', true );
if ( $duedate ){
$duedate = date_i18n( get_option( 'date_format' ), $duedate );
}
if ( $description ) {
echo 'Description: ' . $description . '
';
}
if ( $duedate ) {
echo 'Due date: ' . $duedate . '
';
}
if ( $location ) {
echo 'Location: ' . $location . '
';
}
} // END - Check if Edit Flow v0.6+
} // END - if ( $assignment_desk->edit_flow_enabled() )
echo '
"; echo ""; echo ""; echo "Accept | Decline"; echo " | View Details"; echo "
"; echo '$summary
"; } echo ''; echo '';
if ( $assignment_desk->edit_flow_enabled() ) {
global $edit_flow;
// Edit Flow v0.6 and higher offers custom editorial metadata. Otherwise, fall back on old
if ( version_compare( '0.6', EDIT_FLOW_VERSION, '>=' ) ) {
$terms = $edit_flow->editorial_metadata->get_editorial_metadata_terms();
foreach ( $terms as $term ) {
$form_key = $edit_flow->editorial_metadata->get_postmeta_key( $term );
$saved_value = get_post_meta( $post->ID, $form_key, true );
if ( $saved_value ) {
$html_value = '';
// Give us different inputs based on the metadata type
switch ( $term_type = $edit_flow->editorial_metadata->get_metadata_type( $term ) ) {
case 'checkbox':
$html_value = ( $saved_value ) ? 'Yes' : 'No';
break;
case 'date':
$html_value = date_i18n( get_option( 'date_format' ), $saved_value );
break;
case 'location':
$html_value = $saved_value;
break;
case 'paragraph':
$html_value = $saved_value;
break;
case 'text':
$html_value = $saved_value;
break;
case 'user':
$html_value = get_the_author_meta( 'display_name', $saved_value );
break;
default:
$html_input = '';
break;
}
echo '' . $term->name . ': ' . $html_value . '
';
}
}
} else {
$description = get_post_meta( $post->ID, '_ef_description', true );
$location = get_post_meta( $post->ID, '_ef_location', true );
$duedate = get_post_meta( $post->ID, '_ef_duedate', true );
if ( $duedate ){
$duedate = date_i18n( get_option( 'date_format' ), $duedate );
}
if ( $description ) {
echo 'Description: ' . $description . '
';
}
if ( $duedate ) {
echo 'Due date: ' . $duedate . '
';
}
if ( $location ) {
echo 'Location: ' . $location . '
';
}
} // END - Check if Edit Flow v0.6+
} // END - if ( $assignment_desk->edit_flow_enabled() )
echo '
"; echo "View Details"; echo "
"; echo '