Making WordPress.org

Changeset 2622


Ignore:
Timestamp:
02/25/2016 11:15:39 PM (10 years ago)
Author:
kovshenin
Message:

WordCamp.org: Allow admins to export only approved payment requests.

Location:
sites/branches/wcb-payment-request-statuses/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments-network
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/branches/wcb-payment-request-statuses/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments-network

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • sites/branches/wcb-payment-request-statuses/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments-network/includes/payment-requests-dashboard.php

    r2617 r2622  
    335335        }
    336336
     337        $approved_only = ! empty( $_POST['wcpn_approved_only'] );
    337338        $start_date = strtotime( $_POST['wcpn_export_start_date'] . ' 00:00:00' );
    338339        $end_date   = strtotime( $_POST['wcpn_export_end_date']   . ' 23:59:59' );
     
    340341        $filename = sanitize_file_name( $filename );
    341342
    342         $report = self::generate_payment_report( $_POST['wcpn_date_type'], $start_date, $end_date, $export_type );
     343        $report = self::generate_payment_report( $_POST['wcpn_date_type'], $start_date, $end_date, $export_type, $approved_only );
    343344
    344345        if ( is_wp_error( $report ) ) {
     
    366367     * @return string | WP_Error
    367368     */
    368     protected static function generate_payment_report( $date_type, $start_date, $end_date, $export_type ) {
     369    protected static function generate_payment_report( $date_type, $start_date, $end_date, $export_type, $approved_only ) {
    369370        global $wpdb;
    370371
     
    396397            'end_date' => $end_date,
    397398            'export_type' => $export_type,
     399            'approved_only' => $approved_only,
    398400        );
    399401
     
    411413        $args = wp_parse_args( $args, array(
    412414            'request_indexes' => array(),
     415            'approved_only' => false,
    413416        ) );
    414417
     
    425428
    426429        foreach( $args['request_indexes'] as $index ) {
    427             fputcsv( $report, self::get_report_row( $index ) );
     430            $row = self::get_report_row( $index, $args );
     431            if ( ! empty( $row ) ) {
     432                fputcsv( $report, $row );
     433            }
    428434        }
    429435
     
    442448        $args = wp_parse_args( $args, array(
    443449            'request_indexes' => array(),
     450            'approved_only' => false,
    444451        ) );
    445452
     
    463470            switch_to_blog( $index->blog_id );
    464471            $post = get_post( $index->post_id );
     472
     473            if ( $args['approved_only'] && $post->post_status != 'wcb-approved' )
     474                continue;
    465475
    466476            if ( get_post_meta( $post->ID, '_camppayments_payment_method', true ) != 'Check' )
     
    550560        $args = wp_parse_args( $args, array(
    551561            'request_indexes' => array(),
     562            'approved_only' => false,
    552563        ) );
    553564
     
    616627            $post = get_post( $index->post_id );
    617628
     629            if ( $args['approved_only'] && $post->post_status != 'wcb-approved' )
     630                continue;
     631
    618632            if ( get_post_meta( $post->ID, '_camppayments_payment_method', true ) != 'Direct Deposit' )
    619633                continue;
     
    749763        $args = wp_parse_args( $args, array(
    750764            'request_indexes' => array(),
     765            'approved_only' => false,
    751766        ) );
    752767
     
    763778            switch_to_blog( $index->blog_id );
    764779            $post = get_post( $index->post_id );
     780
     781            if ( $args['approved_only'] && $post->post_status != 'wcb-approved' )
     782                continue;
    765783
    766784            // Only wires here.
     
    966984     *
    967985     * @param stdClass $index
     986     * @param array $args
    968987     *
    969988     * @return array
    970989     */
    971     protected static function get_report_row( $index ) {
     990    protected static function get_report_row( $index, $args ) {
    972991        switch_to_blog( $index->blog_id );
    973992
    974         $request          = get_post( $index->post_id );
     993        $request = get_post( $index->post_id );
     994        if ( $args['approved_only'] && $request->post_status != 'wcb-approved' )
     995            return null;
     996
    975997        $currency         = get_post_meta( $index->post_id, '_camppayments_currency',         true );
    976998        $category         = get_post_meta( $index->post_id, '_camppayments_payment_category', true );
     
    10431065            <?php wp_nonce_field( 'export', 'wcpn_request_export' ); ?>
    10441066
    1045             <p>
    1046                 This form will supply a CSV file with payment requests matching the parameters you select below.
    1047                 For example, all requests that were <code>paid</code> between <code><?php echo esc_html( $last_month ); ?></code> and <code><?php echo esc_html( $today ); ?></code>.
    1048             </p>
    1049 
    1050             <p>
    1051                 <label>
    1052                     Date type:
    1053                     <select name="wcpn_date_type">
    1054                         <option value="created">created</option>
    1055                         <option value="paid" selected>paid</option>
    1056                     </select>
    1057                 </label>
    1058             </p>
    1059 
    1060             <p>
    1061                 <label>
    1062                     Start date:
    1063                     <input type="date" name="wcpn_export_start_date" class="medium-text" value="<?php echo esc_attr( $last_month ); ?>" />
    1064                 </label>
    1065             </p>
    1066 
    1067             <p>
    1068                 <label>
    1069                     End date:
    1070                     <input type="date" name="wcpn_export_end_date" class="medium-text" value="<?php echo esc_attr( $today ); ?>" />
    1071                 </label>
    1072             </p>
    1073 
    1074             <p>
    1075                 <label>Export Type:
    1076                     <select name="wcpn_export_type">
    1077                         <?php foreach ( self::get_export_types() as $key => $export_type ) : ?>
    1078                         <option value="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $export_type['label'] ); ?></option>
    1079                         <?php endforeach; ?>
    1080                     </select>
    1081                 </label>
    1082 
    1083             <?php submit_button( 'Export' ); ?>
     1067            <h2>Export Settings</h2>
     1068
     1069            <table class="form-table">
     1070                <tr>
     1071                    <th><label>Approved Only</label></th>
     1072                    <td><label><input type="checkbox" name="wcpn_approved_only" value="1" checked> Export only requests marked as approved</label></td>
     1073                </tr>
     1074                <tr>
     1075                    <th><label>Date Type</label></th>
     1076                    <td>
     1077                        <select name="wcpn_date_type">
     1078                            <option value="created" selected>created</option>
     1079                            <option value="paid">paid</option>
     1080                        </select>
     1081                    </td>
     1082                </tr>
     1083                <tr>
     1084                    <th><label>Date Range</label></th>
     1085                    <td>
     1086                        <input type="date" name="wcpn_export_start_date" class="medium-text" value="<?php echo esc_attr( $last_month ); ?>" /> to
     1087                        <input type="date" name="wcpn_export_end_date" class="medium-text" value="<?php echo esc_attr( $today ); ?>" />
     1088                    </td>
     1089                </tr>
     1090                <tr>
     1091                    <th><label>Format</label></th>
     1092                    <td>
     1093                        <select name="wcpn_export_type">
     1094                            <?php foreach ( self::get_export_types() as $key => $export_type ) : ?>
     1095                            <option value="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $export_type['label'] ); ?></option>
     1096                            <?php endforeach; ?>
     1097                        </select>
     1098                    </td>
     1099                </tr>
     1100            </table>
     1101
     1102            <?php submit_button( 'Download Export' ); ?>
    10841103        </form>
    10851104
Note: See TracChangeset for help on using the changeset viewer.