Making WordPress.org


Ignore:
Timestamp:
05/31/2018 12:38:17 AM (8 years ago)
Author:
coreymckrill
Message:

WordCamp tickets: Enable allergy/accessibility fields for summarizing & exports

Make Life-threatening allergy and Accessibility needs available from the
dropdown in the Summarize tool, and add columns for them in the CSV export.

Without these, it's difficult for the organizer to quickly get a list of
attendees who have marked "yes" for either of these questions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/camptix-tweaks/addons/accommodations.php

    r7228 r7253  
    2020    const SLUG = 'accommodations';
    2121
     22    public $label = '';
     23
    2224    public $question = '';
    2325
     
    2830     */
    2931    public function camptix_init() {
     32        $this->label = __( 'Accessibility needs', 'wordcamporg' );
     33
    3034        $this->question = __( 'Do you have any accessibility needs, such as a sign language interpreter or wheelchair access, to participate in WordCamp?', 'wordcamporg' );
    3135
     
    4953        // Metabox
    5054        add_filter( 'camptix_metabox_attendee_info_additional_rows', array( $this, 'add_metabox_row' ), 12, 2 );
     55
     56        // Reporting
     57        add_filter( 'camptix_summary_fields', array( $this, 'add_summary_field' ) );
     58        add_action( 'camptix_summarize_by_' . self::SLUG, array( $this, 'summarize' ), 10, 2 );
     59        add_filter( 'camptix_attendee_report_extra_columns', array( $this, 'add_export_column' ) );
     60        add_filter( 'camptix_attendee_report_column_value_' . self::SLUG, array( $this, 'add_export_column_value' ), 10, 2 );
    5161
    5262        // Privacy
     
    343353
    344354    /**
     355     * Add an option to the `Summarize by` dropdown.
     356     *
     357     * @param array $fields
     358     *
     359     * @return array
     360     */
     361    public function add_summary_field( $fields ) {
     362        $fields[ self::SLUG ] = $this->label;
     363
     364        return $fields;
     365    }
     366
     367    /**
     368     * Callback to summarize the answers for this field.
     369     *
     370     * @param array   $summary
     371     * @param WP_Post $attendee
     372     */
     373    public function summarize( &$summary, $attendee ) {
     374        /** @var $camptix CampTix_Plugin */
     375        global $camptix;
     376
     377        $answer = get_post_meta( $attendee->ID, 'tix_' . self::SLUG, true );
     378
     379        if ( isset( $this->options[ $answer ] ) ) {
     380            $camptix->increment_summary( $summary, $this->options[ $answer ] );
     381        } else {
     382            $camptix->increment_summary( $summary, __( 'No answer', 'wordcamporg' ) );
     383        }
     384    }
     385
     386    /**
     387     * Add a column to the CSV export.
     388     *
     389     * @param array $columns
     390     *
     391     * @return array
     392     */
     393    public function add_export_column( $columns ) {
     394        $columns[ self::SLUG ] = $this->label;
     395
     396        return $columns;
     397    }
     398
     399    /**
     400     * Add the human-readable value of the field to the CSV export.
     401     *
     402     * @param string  $value
     403     * @param WP_Post $attendee
     404     *
     405     * @return string
     406     */
     407    public function add_export_column_value( $value, $attendee ) {
     408        $value = get_post_meta( $attendee->ID, 'tix_' . self::SLUG, true );
     409
     410        if ( isset( $this->options[ $value ] ) ) {
     411            return $this->options[ $value ];
     412        }
     413
     414        return '';
     415    }
     416
     417    /**
    345418     * Include the new field in the personal data exporter.
    346419     *
Note: See TracChangeset for help on using the changeset viewer.