From b584bf354ecca0e39c26245f18bb1674346a7ed0 Mon Sep 17 00:00:00 2001 From: Paul Kevan <2290623+pkevan@users.noreply.github.com> Date: Wed, 3 Jul 2024 14:03:23 +0100 Subject: [PATCH] Add contributors report, and allow data to be downloaded. (#267) * Add contributors report, and allow data to be downloaded. --- plugins/wporg-5ftf/includes/reports.php | 121 +++++++++++++++++++++++ plugins/wporg-5ftf/includes/xprofile.php | 20 ++++ 2 files changed, 141 insertions(+) diff --git a/plugins/wporg-5ftf/includes/reports.php b/plugins/wporg-5ftf/includes/reports.php index 44853402..cd68c652 100644 --- a/plugins/wporg-5ftf/includes/reports.php +++ b/plugins/wporg-5ftf/includes/reports.php @@ -17,6 +17,7 @@ add_action( 'admin_menu', __NAMESPACE__ . '\add_admin_pages' ); add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\enqueue_assets' ); add_action( 'admin_init', __NAMESPACE__ . '\export_csv' ); +add_action( 'admin_init', __NAMESPACE__ . '\export_contributors_csv' ); /** * Register admin page. @@ -30,6 +31,15 @@ function add_admin_pages() { '5ftf_company_report', __NAMESPACE__ . '\render_company_report_page' ); + + add_submenu_page( + 'edit.php?post_type=5ftf_pledge', + 'Contributor Report', + 'Contributor Report', + 'manage_options', + '5ftf_contributor_report', + __NAMESPACE__ . '\render_contributor_report_page' + ); } /** @@ -150,6 +160,91 @@ function render_company_report_page() { 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 +
+ + +User id | +Username | +Company | +Hours | +Teams | +Full Name | +Last login | +Status | +|
---|---|---|---|---|---|---|---|---|
' . absint( $user_id ) . ' | '; + echo '' . esc_html( $c->post_title ) . ' | '; + echo '' . esc_html( $pledge_company_title ) . ' | '; + echo '' . esc_html( $xprofile['hours_per_week'] ) . ' | '; + echo '' . esc_html( $teams ) . ' | '; + echo '' . esc_html( $user->display_name ) . ' | '; + echo '' . esc_html( $user->user_email ) . ' | '; + echo '' . esc_html( $last_login ) . ' | '; + echo '' . esc_html( $c->post_status ) . ' | '; + echo '