diff --git a/plugins/wporg-5ftf/assets/css/admin.css b/plugins/wporg-5ftf/assets/css/admin.css index 0645c5b..acb98c8 100755 --- a/plugins/wporg-5ftf/assets/css/admin.css +++ b/plugins/wporg-5ftf/assets/css/admin.css @@ -75,3 +75,17 @@ .contributor-list .button-link-delete .dashicons { margin-top: -2px; } + +table#wporg-5ftf-company-report, #wporg-5ftf-company-report th, #wporg-5ftf-company-report td { + border: 1px solid #000; + border-collapse: collapse; + padding: 5px; +} + + + +#wporg-5ftf-company-report td.center { + text-align: center; +} + + diff --git a/plugins/wporg-5ftf/includes/reports.php b/plugins/wporg-5ftf/includes/reports.php new file mode 100644 index 0000000..1b205b5 --- /dev/null +++ b/plugins/wporg-5ftf/includes/reports.php @@ -0,0 +1,177 @@ +id ) { + wp_enqueue_style( '5ftf-admin' ); + } + } +} + +/** + * Render results and download button. + */ +function render_company_report_page() { + + $status = sanitize_title( $_GET['status'] ); + + 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' => 250, // set to 250 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 ( 250 == count( $pledges ) ) { + echo '

WARNING: pledge limit reached, check the code query.

'; + } + ?> + +

+ Total: + Status: + All + Draft + Publish + Deactivated +

+ +
+ + + + +
+ + + + + + + + + + + + + + + + ID, '5ftf_org-domain', true ); + $pledge_url = get_post_meta( $pledge->ID, '5ftf_org-url', 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_url, $email, $date_created, $date_modified ); + } + echo '
CompanyStatusTotal HoursContributorsUsernamesTeam(s)URLPledge URLEmailPledge createdPledge 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_url ) . '' . 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 ); +} + +/** + * 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(); +} diff --git a/plugins/wporg-5ftf/index.php b/plugins/wporg-5ftf/index.php index 5744f10..9b91fa6 100755 --- a/plugins/wporg-5ftf/index.php +++ b/plugins/wporg-5ftf/index.php @@ -28,13 +28,14 @@ function load() { require_once get_includes_path() . 'authentication.php'; require_once get_includes_path() . 'contributor.php'; require_once get_includes_path() . 'email.php'; - require_once get_includes_path() . 'pledge.php'; - require_once get_includes_path() . 'pledge-meta.php'; - require_once get_includes_path() . 'pledge-form.php'; - require_once get_includes_path() . 'xprofile.php'; require_once get_includes_path() . 'endpoints.php'; require_once get_includes_path() . 'miscellaneous.php'; + require_once get_includes_path() . 'pledge.php'; + require_once get_includes_path() . 'pledge-form.php'; + require_once get_includes_path() . 'pledge-meta.php'; + require_once get_includes_path() . 'reports.php'; require_once get_includes_path() . 'stats.php'; + require_once get_includes_path() . 'xprofile.php'; // The logger expects things like `$_POST` which aren't set during unit tests. if ( ! $running_unit_tests ) {