public_facing_options['public_facing_volunteering_enabled']) && $assignment_desk->public_facing_options['public_facing_volunteering_enabled'] == 'on' ) { add_filter('manage_users_custom_column', array(&$this, 'handle_ad_user_volunteer_count_column'), 10, 3); } add_filter('manage_users_custom_column', array(&$this, 'handle_ad_user_type_column'), 10, 3); } /** * Add custom columns to the manage_users view. * @return array The columns */ function manage_user_columns($user_columns) { global $assignment_desk; $custom_fields_to_add = array( _('_ad_user_type') => __('User Type'), _('_ad_user_total_words') => __('Total Words'), _('_ad_user_average_words') => __('Average Words'), _('_ad_user_pitch_count') => __('Pitches'), ); if ( $assignment_desk->public_facing_options['public_facing_volunteering_enabled'] == 'on' ) { $custom_fields_to_add[_('_ad_user_volunteer_count')] = __('Volunteered'); } foreach ($custom_fields_to_add as $field => $title) { $user_columns[$field] = $title; } return $user_columns; } /** * Filter for displaying the user type custom column * @return string The content of the cell */ function handle_ad_user_type_column( $default, $column_name, $user_id ) { global $assignment_desk; if ( $column_name == __( '_ad_user_type' ) ) { $user_type_term_name = __('None assigned'); $user_type = (int)get_usermeta($user_id, $assignment_desk->option_prefix.'user_type', true); $term = get_term($user_type, $assignment_desk->custom_taxonomies->user_type_label); if($term->name){ $user_type_term_name = $term->name; } return $user_type_term_name; } return $default; } /** * Filter for displaying the average words custom column * @param string $default The content of the cell * @param string $column_name The name of the column * @param int $user_id The ID of the user * @return string the content of the cell */ function handle_ad_user_average_words_column( $default, $column_name, $user_id ) { if ( $column_name == __( '_ad_user_average_words' ) ) { return $this->average_words($user_id); } return $default; } /** * Returns the average words per post for this user * @return int The average words per post for the user */ function average_words( $user_id ) { $num_posts = get_usernumposts($user_id); if($num_posts){ return $this->total_words($user_id) / $num_posts; } return 0; } /** * Filter for displaying the total words custom column * @param string $default The content of the cell * @param string $column_name The name of the column * @param int $user_id The ID of the user * @return string The content of the cell */ function handle_ad_user_total_words_column( $default, $column_name, $user_id ) { if ( $column_name == __( '_ad_user_total_words' ) ) { return $this->total_words($user_id); } return $default; } /** * Returns the sum of the number of words in any published post where * user_id is a coauthor and an accepted participant in the writer role. * @param int $user_id The ID of the user * @return int The total words for all of the user's posts. */ function total_words($user_id){ global $assignment_desk, $wpdb; $total_words = 0; $user = get_userdata($user_id); // Get post ID's and participant records the post is published $participant_posts = $wpdb->get_results("SELECT $wpdb->posts.ID FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'post' AND $wpdb->postmeta.meta_key = '_ad_participant_$user->ID'", ARRAY_N); $post_ids = array(); if(!$participant_posts){ return 0; } foreach($participant_posts as $p){ $post_ids[] = $p[0]; } // @todo - Make this configurable. $writer_role = get_term_by('name', _('Writer'), $assignment_desk->custom_taxonomies->user_role_label); // Of all the posts where this user is a participant, which have writers associated with them? $participant_records = $wpdb->get_results("SELECT * FROM $wpdb->postmeta WHERE post_id IN (" . implode(', ', $post_ids) . ") AND meta_key = '_ad_participant_role_$writer_role->term_id'"); if(!$writer_role){ return 0; } // Accumulate post ids where this user is in the Writer role and they've accepted the assignment. $posts_to_consider = array(); foreach ( $participant_records as $record ) { $roles = maybe_unserialize($record->meta_value); if ( 'accepted' == $roles[$user->user_login] ) { $posts_to_consider[]= $record->post_id; } } $author_posts = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' AND post_author = $user->ID"); foreach( $author_posts as $post ) { $posts_to_consider[]= $post->ID; } // Add up all of the word counts we stashed in the postmeta during save_post foreach( $posts_to_consider as $post_id ) { $words = (int)get_post_meta($post_id, '_ad_word_count', true); if ( !$words ) { $words = str_word_count($wpdb->get_var("SELECT post_content FROM $wpdb->posts WHERE ID=$post_id")); } $total_words += $words; } return $total_words; } /** * Filter for displaying the volunteer count custom column * @param string $default The content of the cell * @param string $column_name The name of the column * @param int $user_id The ID of the user * @return string The content of the cell */ function handle_ad_user_volunteer_count_column( $default, $column_name, $user_id ) { global $assignment_desk, $wpdb; if ( $column_name == __( '_ad_user_volunteer_count' ) ) { return $this->volunteer_count($user_id); } return $default; } /** * Get the number of times a user has volunteered for a post. * @param int $user_id The ID of the user * @return int The number of times a user has volunteered for a post. */ function volunteer_count( $user_id ) { $count = 0; $volunteered_for = get_usermeta($user_id, '_ad_volunteer'); if($volunteered_for){ $count = count($volunteered_for); } return $count; } /** * Filter for displaying the pitch count custom column * @param string $default The content of the cell * @param string $column_name The name of the column * @param int $user_id The ID of the user * @return string The content of the cell */ function handle_ad_user_pitches_count_column( $default, $column_name, $user_id ) { global $assignment_desk, $wpdb; if ( $column_name == __( '_ad_user_pitch_count' ) ) { return $this->pitch_count($user_id); } return $default; } /** * Get the number of posts the user has pitched. * @param int $user_id The ID of the user * @return int The number of posts the user has pitched */ function pitch_count( $user_id ) { global $wpdb; $count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->postmeta WHERE meta_key='_ad_pitched_by' AND meta_value='$user_id'"); if(!$count){ $count = 0; } return $count; } /** * Add custom fields to the user profile form. */ function profile_options() { global $profileuser, $assignment_desk; $user_id = (int)$profileuser->ID; $user_type = (int)get_usermeta($user_id, $assignment_desk->option_prefix.'user_type', true); $current_user_type_term = get_term($user_type, $assignment_desk->custom_taxonomies->user_type_label); ?>

Assignment Desk Settings

define_editor_permissions) ){ // Need to have 'get'=>'all' so that it will retrieve a custom taxonomy $user_type_taxonomy = get_terms($assignment_desk->custom_taxonomies->user_type_label, array('get'=>'all')); ?> {$current_user_type_term->name}"; } ?>
User Type

Indicate whether the user is a $user_type_term) : ?> = 2) { break; } echo $user_type_term->name . ', '; if ($key == 1) { echo 'etc.'; } ?>

Statistics

Average Wordsaverage_words($profileuser->ID); ?>
Total Wordstotal_words($profileuser->ID); ?>
Pitchespitch_count($profileuser->ID); ?>
Volunteeredvolunteer_count($profileuser->ID); ?>
define_editor_permissions) ) { $user_type = (int)$_POST['assignment_desk-user_type']; update_usermeta($user_id, $assignment_desk->option_prefix.'user_type', $user_type); } } } } ?>