Making WordPress.org

Changeset 7979


Ignore:
Timestamp:
12/17/2018 07:34:32 AM (8 years ago)
Author:
vedjain
Message:

WCPT Application Tracker: Add support for Meetup applications

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-event/tracker.php

    r7978 r7979  
    2323
    2424/**
    25  * Get camps that are active enough to be shown on the tracker
     25 * Get applications that are active enough to be shown on the tracker
    2626 *
     27 * @param string $application_type Type of application. Could be `wordcamp` or `meetup`.
    2728 * @return array
    2829 */
    29 function get_active_wordcamps() {
     30function get_active_events( $application_type ) {
    3031        global $wpdb;
    31         $wordcamps          = array();
    32         $statuses           = WordCamp_Loader::get_post_statuses();
    33         $milestones         = WordCamp_Loader::map_statuses_to_milestones();
     32        $events             = array();
     33        $shown_statuses     = array();
     34        $statuses           = array();
     35        $milestones         = array();
    3436        $inactive_timestamp = strtotime( '60 days ago' );
     37        $post_type          = '';
    3538
    36         $shown_statuses = $statuses;
    37         unset( $shown_statuses[ WCPT_FINAL_STATUS ] );
    38         $shown_statuses = array_keys( $shown_statuses );
    39         $wordcamp_post_type = WCPT_POST_TYPE_ID;
     39        if ( 'wordcamp' === $application_type ) {
     40                $statuses = WordCamp_Loader::get_post_statuses();
     41                $milestones = WordCamp_Loader::map_statuses_to_milestones();
     42                unset( $shown_statuses[ WCPT_FINAL_STATUS ] );
     43                $post_type = WCPT_POST_TYPE_ID;
     44        } elseif ( 'meetup' === $application_type ) {
     45                $statuses = \Meetup_Loader::get_post_statuses();
     46                $post_type = WCPT_MEETUP_SLUG;
     47        }
    4048
    41         $wordcamp_post_objs = $wpdb->get_results(
     49        $shown_statuses = array_keys( $statuses );
     50
     51        $event_post_objs = $wpdb->get_results(
    4252                $wpdb->prepare(
    4353                        "
     
    4555                        FROM {$wpdb->prefix}postmeta
    4656                        WHERE
    47                                 meta_key like '_status_change_log_$wordcamp_post_type%'
     57                                meta_key like '_status_change_log_$post_type%'
    4858                        AND
    4959                                meta_value >= %d
     
    5363                )
    5464        );
    55         $wordcamp_post_obj = array();
    56         foreach ( $wordcamp_post_objs as $wordcamp_post ) {
    57                 $wordcamp_post_obj[ $wordcamp_post->post_id ] = $wordcamp_post->last_updated;
     65
     66        $event_posts = array();
     67        foreach ( $event_post_objs as $event_post ) {
     68                $event_posts[ $event_post->post_id ] = $event_post->last_updated;
    5869        }
    5970
    6071        $raw_posts = get_posts(
    6172                array(
    62                         'post_type'      => WCPT_POST_TYPE_ID,
     73                        'post_type'      => $post_type,
    6374                        'post_status'    => $shown_statuses,
    6475                        'posts_per_page' => 1000,
    6576                        'order'          => 'ASC',
    6677                        'orderby'        => 'post_title',
    67                         'post__in'       => array_keys ( $wordcamp_post_obj ),
     78                        'post__in'       => array_keys ( $event_posts ),
    6879                )
    6980        );
    7081
    7182        foreach ( $raw_posts as $key => $post ) {
    72                 $last_update_timestamp = $wordcamp_post_obj[ $post->ID ];
     83                $last_update_timestamp = $event_posts[ $post->ID ];
    7384
    74                 $wordcamps[] = array(
    75                         'city'       => $post->post_title,
    76                         'cityUrl'    => filter_var( get_post_meta( $post->ID, 'URL', true ), FILTER_VALIDATE_URL ),
    77                         'applicant'  => get_post_meta( $post->ID, 'Organizer Name', true ),
    78                         'milestone'  => $milestones[ $post->post_status ],
    79                         'status'     => $statuses[ $post->post_status ],
    80                         'lastUpdate' => time() - $last_update_timestamp,
    81                 );
     85                if ( 'wordcamp' === $application_type ) {
     86                        $events[] = array(
     87                                'city'       => $post->post_title,
     88                                'cityUrl'    => filter_var( get_post_meta( $post->ID, 'URL', true ), FILTER_VALIDATE_URL ),
     89                                'applicant'  => esc_html( get_post_meta( $post->ID, 'Organizer Name', true ) ),
     90                                'milestone'  => $milestones[ $post->post_status ],
     91                                'status'     => $statuses[ $post->post_status ],
     92                                'lastUpdate' => time() - $last_update_timestamp,
     93                        );
     94                } elseif ( 'meetup' === $application_type ) {
     95                        $events[] = array(
     96                                'city'       => $post->post_title,
     97                                'cityUrl'    => filter_var( get_post_meta( $post->ID, 'Meetup URL', true ), FILTER_VALIDATE_URL ),
     98                                'applicant'  => esc_html( get_post_meta( $post->ID, 'Organizer Name', true ) ),
     99                                'status'     => $statuses[ $post->post_status ],
     100                                'lastUpdate' => time() - $last_update_timestamp,
     101                        );
     102                }
    82103        }
    83104
    84         return $wordcamps;
     105        return $events;
    85106}
    86107
     
    90111 * @return array
    91112 */
    92 function get_wordcamp_display_columns() {
    93         return array(
    94                 'city'       => 'City',
    95                 'applicant'  => 'Applicant',
    96                 'milestone'  => 'Milestone',
    97                 'status'     => 'Status',
    98                 'lastUpdate' => 'Updated',
    99         );
     113function get_display_columns( $application_type ) {
     114        switch ( $application_type ) {
     115                case 'wordcamp':
     116                        return array(
     117                                'city'       => 'City',
     118                                'applicant'  => 'Applicant',
     119                                'milestone'  => 'Milestone',
     120                                'status'     => 'Status',
     121                                'lastUpdate' => 'Updated',
     122                        );
     123                case 'meetup':
     124                        return array(
     125                                'city' => 'City',
     126                                'applicant' => 'Applicant',
     127                                'status' => 'Status',
     128                                'lastUpdate' => 'Updated',
     129                        );
     130        }
    100131}
    101132
     
    128159        wp_enqueue_style( 'wpc-application-tracker' );
    129160
    130         if ( 'wordcamp' === $application_type ) {
    131                 wp_localize_script(
    132                         'wpc-application-tracker',
    133                         'wpcApplicationTracker',
    134                         array(
    135                                 'applications'     => get_active_wordcamps(),
    136                                 'displayColumns'   => get_wordcamp_display_columns(),
    137                                 'initialSortField' => 'city',
    138                         )
    139                 );
    140         } elseif ( 'meetup' === $application_type ) {
    141                 wp_localize_script(
    142                         'wpc-application-tracker',
    143                         'wpcApplicationTracker',
    144                         array(
    145                                 'applications',
    146                                 'displayColumns',
    147                                 'initialSortField',
    148                         )
    149                 );
    150         }
     161        wp_localize_script(
     162                'wpc-application-tracker',
     163                'wpcApplicationTracker',
     164                array(
     165                        'applications'     => get_active_events( $application_type ),
     166                        'displayColumns'   => get_display_columns( $application_type ),
     167                        'initialSortField' => 'city',
     168                )
     169        );
    151170}
    152171
Note: See TracChangeset for help on using the changeset viewer.