id ) || ( '5ftf_pledge_page_5ftf_contributor_report' == $current_page->id ) ) { wp_enqueue_style( '5ftf-admin' ); } } } /** * Render results and download button. */ function render_company_report_page() { $status = sanitize_title( $_GET['status'] ); $pledge_limit = 500; if ( ! in_array( $status, array( 'draft', '5ftf-deactivated', 'publish' ) ) ) { $status = 'all'; } $pledges = get_posts( array( 'post_type' => '5ftf_pledge', 'post_status' => $status, 'posts_per_page' => $pledge_limit, // set to avoid unexpected memory overuse. 'orderby' => 'post_title', 'order' => 'ASC', ) ); // Add visible warning on page if we hit the upper limit of the query. if ( count( $pledges ) === $pledge_limit ) { echo '

WARNING: pledge limit reached, check the code query.

'; } ?>

Total: Status: All Draft Publish Deactivated

ID, '5ftf_org-domain', true ); $email = get_post_meta( $pledge->ID, '5ftf_org-pledge-email', true ); $date_created = substr( $pledge->post_date, 0, 10 ); $date_modified = substr( $pledge->post_modified, 0, 10 ); $team = XProfile\get_aggregate_contributor_data_for_pledge( $pledge->ID ); $hours = $team['hours']; $contributors = $team['contributors']; $all_contributors += $contributors; $users = Contributor\get_pledge_contributors( $pledge->ID, 'publish' ); $wporg_profiles = wp_list_pluck( $users, 'post_title' ); $usernames = implode( ', ', $wporg_profiles ); $teams = implode( ', ', str_replace( ' Team', '', $team['teams'] ) ); echo ''; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo ''; $export_data[] = array( $pledge->post_title, $pledge->post_status, $hours, $contributors, $usernames, $teams, $company_url, $pledge->guid, $email, $date_created, $date_modified ); } echo '
Company Status Total Hours Contributors Usernames Team(s) URL Pledge URL Email Pledge created Pledge updated
' . esc_html( $pledge->post_title ) . '' . esc_html( $pledge->post_status ) . '' . esc_html( $hours ) . '' . esc_html( $contributors ) . '' . esc_html( $usernames ) . '' . esc_html( $teams ) . '' . esc_html( $company_url ) . '' . esc_html( $pledge->guid ) . '' . esc_html( $email ). '' . esc_html( $date_created ) . '' . esc_html( $date_modified ) . '
'; echo '

Total contributors: ' . esc_html( $all_contributors ) . '

'; // Sets a transient to avoid double data lookup for export, might need to adjust timeout to longer. set_transient( 'wporg_5ftf_company_report_' . $status, $export_data, 60 ); } /** * Render results and download button. */ function render_contributor_report_page() { $status = sanitize_title( $_GET['status'] ?? '' ); $contributor_limit = 1500; if ( ! in_array( $status, array( 'pending', 'trash', 'publish' ) ) ) { $status = 'all'; } $contributors = get_posts( array( 'post_type' => '5ftf_contributor', 'post_status' => $status, 'posts_per_page' => $contributor_limit, // set to avoid unexpected memory overuse. 'orderby' => 'post_title', 'order' => 'ASC', ) ); // Add visible warning on page if we hit the upper limit of the query. if ( count( $contributors ) === $contributor_limit ) { echo '

WARNING: Contributor limit reached, check the code query.

'; } $all_contributor_data = XProfile\get_all_xprofile_contributors_indexed(); ?>

Total: Status: All Pending Publish Trash

post_parent ); $pledge_company_title = get_the_title( $pledge_company ) ?? 'unattached'; $user_id = get_post_meta( $c->ID, 'wporg_user_id', true ); $xprofile = $all_contributor_data[ $user_id ] ?? [ 'team_names' => [], 'hours_per_week' => 0, ]; $xprofile_teams = $xprofile['team_names'] ?? []; $user = get_user_by( 'ID', $user_id ); $user_display_name = $user->display_name ?? ''; $user_email = $user->user_email ?? ''; $last_login = get_user_meta( $user_id, 'last_logged_in', true ); $last_activity = get_user_meta( $user_id, 'last_activity_tracker', true ); $teams = str_replace( ' Team', '', implode( ',', $xprofile_teams ) ); echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; // Either output last activity or last login. if ( $last_activity > $last_login ) { echo ''; } else { echo ''; } echo ''; echo ''; $export_data[] = array( $user_id, $c->post_title, $pledge_company_title, $xprofile['hours_per_week'], $teams, $user_display_name, $user_email, $last_login, $c->post_status ); } echo '
User id Username Company Hours Teams Full Name Email Last activity (log in or tracked activity) Status
' . absint( $user_id ) . '' . esc_html( $c->post_title ) . '' . esc_html( $pledge_company_title ) . '' . esc_html( $xprofile['hours_per_week'] ) . '' . esc_html( $teams ) . '' . esc_html( $user_display_name ) . '' . esc_html( $user_email ) . '' . esc_html( $last_activity ) . '' . esc_html( $last_login ) . '' . esc_html( $c->post_status ) . '
'; set_transient( 'wporg_5ftf_contributor_report_' . $status, $export_data, 2 * MINUTE_IN_SECONDS ); } /** * CSV export runner, grabs data lazily from a transient. */ function export_csv() { if ( ! isset( $_POST['wporg-5ftf-cr'] ) || ! current_user_can( 'manage_options' ) || ! wp_verify_nonce( $_POST['_wpnonce'], '5ftf_download_company_report' ) ) { return; } $status = $_POST['status']; $data = get_transient( 'wporg_5ftf_company_report_' . $status ); $exporter = new Export_CSV( array( 'filename' => 'company-report-' . $status, 'headers' => array( 'Company', 'Status', 'Hours', 'Contributors', 'Users', 'Teams', 'Company URL', 'Pledge URL', 'Email', 'Created', 'Last updated' ), 'data' => $data, ) ); $exporter->emit_file(); } /** * Export contributors as a CSV, also from transient. */ function export_contributors_csv() { if ( ! isset( $_POST['wporg-5ftf-contr'] ) || ! current_user_can( 'manage_options' ) || ! wp_verify_nonce( $_POST['_wpnonce'], '5ftf_download_contributor_report' ) ) { return; } $status = $_POST['status']; $data = get_transient( 'wporg_5ftf_contributor_report_' . $status ); $exporter = new Export_CSV( array( 'filename' => 'contributor-report-' . $status, 'headers' => array( 'User id', 'Username', 'Company', 'Hours', 'Teams', 'Full Name', 'Email', 'Last Login', 'Status' ), 'data' => $data, ) ); $exporter->emit_file(); }