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 +
+ + + +Company | +Status | +Total Hours | +Contributors | +Usernames | +Team(s) | +URL | +Pledge URL | +Pledge created | +Pledge updated | +|
---|---|---|---|---|---|---|---|---|---|---|
' . esc_html( $pledge->post_title ) . ' | '; + echo '' . esc_html( $pledge->post_status ) . ' | '; + echo '' . esc_html( $hours ) . ' | '; + echo '' . esc_html( $contributors ) . ' | '; + echo '' . esc_html( $usernames ) . ' | '; + echo '' . esc_html( $teams ) . ' | '; + echo '' . esc_html( $company_url ) . ' | '; + echo '' . esc_html( $pledge_url ) . ' | '; + echo '' . esc_html( $email ). ' | '; + echo '' . esc_html( $date_created ) . ' | '; + echo '' . 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 ) {