Making WordPress.org

Changeset 7516


Ignore:
Timestamp:
07/28/2018 12:46:28 AM (7 years ago)
Author:
coreymckrill
Message:

WordCamp Reports: Add WordCamp Details report

This is the first iteration of a report that allows WPCS staff to download a
spreadsheet of WordCamps and related data.

Location:
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-reports
Files:
7 added
3 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-reports/classes/report/class-base.php

    r6662 r7516  
    135135
    136136    /**
    137      * Filter the report data prior to caching and compiling.
    138      *
    139      * @param array $data The data to filter.
    140      *
    141      * @return array
    142      */
    143     protected function filter_data_fields( array $data ) {
     137     * Determine the data fields safelist based on the context of the report.
     138     *
     139     * @return array The list of fields that are safe to include.
     140     */
     141    protected function get_data_fields_safelist() {
    144142        $safelist = $this->public_data_fields;
    145143
     
    147145            $safelist = array_merge( $safelist, $this->private_data_fields );
    148146        }
     147
     148        return $safelist;
     149    }
     150
     151    /**
     152     * Filter the report data prior to caching and compiling.
     153     *
     154     * @param array $data The data to filter.
     155     *
     156     * @return array
     157     */
     158    protected function filter_data_fields( array $data ) {
     159        $safelist = $this->get_data_fields_safelist();
    149160
    150161        array_walk( $data, function ( &$row ) use ( $safelist ) {
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-reports/classes/report/class-wordcamp-status.php

    r6662 r7516  
    77defined( 'WPINC' ) || die();
    88
     9use Exception;
     10use WordCamp\Reports;
     11use function WordCamp\Reports\Validation\validate_wordcamp_status;
    912use WordCamp_Loader;
    10 use WordCamp\Reports;
    1113
    1214/**
     
    101103        // Report-specific options.
    102104        $options = wp_parse_args( $options, array(
    103             'status_subset' => array(),
     105            'status_subset' => [],
    104106        ) );
    105107
    106108        parent::__construct( $start_date, $end_date, $options );
    107109
    108         if ( 'any' === $status ) {
    109             $status = '';
    110         }
    111 
    112         if ( $status && $this->validate_status_input( $status ) ) {
    113             $this->status = $status;
    114         }
    115     }
    116 
    117     /**
    118      * Validate the given status ID string.
    119      *
    120      * @param string $status The status ID to filter for in the report.
    121      *
    122      * @return bool True if the status ID is valid. Otherwise false.
    123      */
    124     protected function validate_status_input( $status ) {
    125         if ( is_array( $this->options['status_subset'] ) && ! empty( $this->options['status_subset'] ) ) {
    126             if ( ! in_array( $status, $this->options['status_subset'], true ) ) {
    127                 $this->error->add( 'invalid_status', 'Please enter a valid status ID.' );
    128 
    129                 return false;
    130             }
    131 
    132             return true;
    133         }
    134 
    135         if ( ! in_array( $status, array_keys( WordCamp_Loader::get_post_statuses() ), true ) ) {
    136             $this->error->add( 'invalid_status', 'Please enter a valid status ID.' );
    137 
    138             return false;
    139         }
    140 
    141         return true;
     110        if ( $status && 'any' !== $status ) {
     111            try {
     112                $this->status = validate_wordcamp_status( $status, $options );
     113            } catch ( Exception $e ) {
     114                $this->error->add(
     115                    self::$slug . '-status-error',
     116                    $e->getMessage()
     117                );
     118            }
     119        }
    142120    }
    143121
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-reports/index.php

    r7465 r7516  
    3232
    3333/**
     34 * Get the path for the includes directory.
     35 *
     36 * @return string Path with trailing slash.
     37 */
     38function get_includes_dir_path() {
     39    return trailingslashit( PLUGIN_DIR ) . 'includes/';
     40}
     41
     42/**
    3443 * Get the path for the views directory.
    3544 *
     
    5766    return trailingslashit( PLUGIN_URL ) . 'assets/';
    5867}
     68
     69/**
     70 * Autoload all the files in the includes directory.
     71 *
     72 * @return void
     73 */
     74function load_includes() {
     75    foreach ( glob( get_includes_dir_path() . '*.php' ) as $filename ) {
     76        if ( is_readable( $filename ) ) {
     77            include_once ( $filename );
     78        }
     79    }
     80}
     81
     82add_action( 'plugins_loaded', __NAMESPACE__ . '\load_includes' );
    5983
    6084/**
     
    110134        __NAMESPACE__ . '\Report\Payment_Activity',
    111135        __NAMESPACE__ . '\Report\Sponsorship_Grants',
     136        __NAMESPACE__ . '\Report\WordCamp_Details',
    112137        __NAMESPACE__ . '\Report\WordCamp_Status',
    113138        __NAMESPACE__ . '\Report\Meetup_Groups',
Note: See TracChangeset for help on using the changeset viewer.