Making WordPress.org

Changeset 7978


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

WCPT Tracker: Refactor tracker.php to:

  1. Add support for type attribute in shortcode. This will be used to render WordCamp/Meetup tracking page.
  2. Use single query to fetch last_update timestamp as well along with post_ids that were active within last 60 days.
File:
1 edited

Legend:

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

    r7977 r7978  
    99
    1010add_shortcode( SHORTCODE_SLUG, __NAMESPACE__ . '\render_status_shortcode' );
    11 add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\enqueue_scripts' );
    1211
    1312/**
    1413 * Render the [application-tracker] shortcode.
    1514 */
    16 function render_status_shortcode() {
     15function render_status_shortcode( $atts = [] ) {
     16        $application_type = 'wordcamp';
     17        if ( isset ( $atts['type'] ) ) {
     18                $application_type = $atts['type'];
     19        }
     20        enqueue_scripts( $application_type );
    1721        return '<div id="wpc-application-tracker">Loading WordCamp Application Tracker...</div>';
    1822}
     
    3842                $wpdb->prepare(
    3943                        "
    40                         SELECT DISTINCT post_id
     44                        SELECT DISTINCT post_id, MAX( meta_value ) as last_updated
    4145                        FROM {$wpdb->prefix}postmeta
    4246                        WHERE
     
    4448                        AND
    4549                                meta_value >= %d
     50                        GROUP BY post_id
    4651                        ",
    4752                        $inactive_timestamp
    4853                )
    4954        );
    50         $wordcamp_post_ids = wp_list_pluck( $wordcamp_post_objs, 'post_id' );
     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;
     58        }
    5159
    5260        $raw_posts = get_posts(
     
    5462                        'post_type'      => WCPT_POST_TYPE_ID,
    5563                        'post_status'    => $shown_statuses,
    56                         'posts_per_page' => -1,
     64                        'posts_per_page' => 1000,
    5765                        'order'          => 'ASC',
    5866                        'orderby'        => 'post_title',
    59                         'post__in'       => $wordcamp_post_ids,
     67                        'post__in'       => array_keys ( $wordcamp_post_obj ),
    6068                )
    6169        );
    6270
    6371        foreach ( $raw_posts as $key => $post ) {
    64                 $last_update_timestamp = get_last_update_timestamp( $post->ID );
     72                $last_update_timestamp = $wordcamp_post_obj[ $post->ID ];
    6573
    6674                $wordcamps[] = array(
     
    7886
    7987/**
    80  * Get the timestamp of the last time the post status changed
     88 * Get the columns headers for WordCamp
    8189 *
    82  * @param int $post_id
    83  *
    84  * @return int
     90 * @return array
    8591 */
    86 function get_last_update_timestamp( $post_id ) {
    87         $last_update_timestamp = 0;
    88         $status_changes        = get_post_meta( $post_id, '_status_change' );
    89 
    90         if ( $status_changes ) {
    91                 usort( $status_changes, 'wcpt_sort_log_entries' );
    92                 $last_update_timestamp = $status_changes[0]['timestamp'];
    93         }
    94 
    95         return $last_update_timestamp;
     92function get_wordcamp_display_columns() {
     93        return array(
     94                'city'       => 'City',
     95                'applicant'  => 'Applicant',
     96                'milestone'  => 'Milestone',
     97                'status'     => 'Status',
     98                'lastUpdate' => 'Updated',
     99        );
    96100}
    97101
    98102/**
    99  * Enqueue scripts and styles
     103 * Enqueue scripts and styles.
     104 * Based on the event type passed, we will localize different data for Meetup and WordCamp events.
     105 *
     106 * @param string application_type Application type for the tracker table. Could be either `wordcamp` or `meetup`.
    100107 */
    101 function enqueue_scripts() {
     108function enqueue_scripts( $application_type ) {
    102109        global $post;
    103110
     
    117124        );
    118125
    119         if ( ! is_a( $post, 'WP_POST' ) || ! has_shortcode( $post->post_content, SHORTCODE_SLUG ) ) {
    120                 return;
    121         }
    122 
    123126        wp_enqueue_script( 'wpc-application-tracker' );
    124127
    125         wp_localize_script(
    126                 'wpc-application-tracker',
    127                 'wpcApplicationTracker',
    128                 array(
    129                         'applications'     => get_active_wordcamps(),
    130                         'displayColumns'   => get_display_columns(),
    131                         'initialSortField' => 'city',
    132                 )
    133         );
     128        wp_enqueue_style( 'wpc-application-tracker' );
    134129
    135         wp_enqueue_style( 'wpc-application-tracker' );
     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        }
    136151}
    137152
    138 /**
    139  * Get the columns headers
    140  *
    141  * @return array
    142  */
    143 function get_display_columns() {
    144         return array(
    145                 'city'       => 'City',
    146                 'applicant'  => 'Applicant',
    147                 'milestone'  => 'Milestone',
    148                 'status'     => 'Status',
    149                 'lastUpdate' => 'Updated',
    150         );
    151 }
Note: See TracChangeset for help on using the changeset viewer.