public_facing_options['public_facing_volunteering_enabled'] == 'on'){ add_filter('manage_users_custom_column', array(&$this, 'handle_ad_user_volunteer_count_column'), 10, 3); } //@todo this is last because of an unresolves situation where only the last column prints. add_filter('manage_users_custom_column', array(&$this, 'handle_ad_user_type_column'), 10, 3); } function add_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; } 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; } 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 */ function average_words( $user_id ) { $num_posts = get_usernumposts($user_id); if($num_posts){ return $this->count_total_words($user_id) / $num_posts; } return 0; } function handle_ad_user_total_words_column( $default, $column_name, $user_id ) { if ( $column_name == __( '_ad_user_total_words' ) ) { return $this->count_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. */ function count_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 $post_id_results = $wpdb->get_results("SELECT $wpdb->posts.ID as post_id FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->postmeta.meta_key = '_ad_participant_$user->ID'", ARRAY_N); $post_ids = array(); if(!$post_id_results){ return 0; } foreach($post_id_results 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; } } // Add up all of the word counts we stashed in the postmeta during save_post foreach($posts_to_consider as $post_id){ $total_words += (int)get_post_meta($post_id, '_ad_word_count', true); } return $total_words; } function handle_ad_user_volunteer_count_column( $default, $column_name, $user_id ) { global $assignment_desk, $wpdb; if ( $column_name == __( '_ad_user_volunteer_count' ) ) { $count = 0; $volunteered_for = get_usermeta($user_id, '_ad_volunteer'); if($volunteered_for){ $count = count($volunteered_for); } return $count; } return $default; } function handle_ad_user_pitches_count_column( $default, $column_name, $user_id ) { global $assignment_desk, $wpdb; if ( $column_name == __( '_ad_user_pitch_count' ) ) { $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; } return $default; } 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); // 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')); ?>
| User Type |
Indicate whether the user is a $user_type_term) : ?> = 2) { break; } echo $user_type_term->name . ', '; if ($key == 1) { echo 'etc.'; } ?> |
|---|