Changeset 7978 for sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-event/tracker.php
- Timestamp:
- 12/17/2018 07:34:25 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-event/tracker.php
r7977 r7978 9 9 10 10 add_shortcode( SHORTCODE_SLUG, __NAMESPACE__ . '\render_status_shortcode' ); 11 add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\enqueue_scripts' );12 11 13 12 /** 14 13 * Render the [application-tracker] shortcode. 15 14 */ 16 function render_status_shortcode() { 15 function render_status_shortcode( $atts = [] ) { 16 $application_type = 'wordcamp'; 17 if ( isset ( $atts['type'] ) ) { 18 $application_type = $atts['type']; 19 } 20 enqueue_scripts( $application_type ); 17 21 return '<div id="wpc-application-tracker">Loading WordCamp Application Tracker...</div>'; 18 22 } … … 38 42 $wpdb->prepare( 39 43 " 40 SELECT DISTINCT post_id 44 SELECT DISTINCT post_id, MAX( meta_value ) as last_updated 41 45 FROM {$wpdb->prefix}postmeta 42 46 WHERE … … 44 48 AND 45 49 meta_value >= %d 50 GROUP BY post_id 46 51 ", 47 52 $inactive_timestamp 48 53 ) 49 54 ); 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 } 51 59 52 60 $raw_posts = get_posts( … … 54 62 'post_type' => WCPT_POST_TYPE_ID, 55 63 'post_status' => $shown_statuses, 56 'posts_per_page' => -1,64 'posts_per_page' => 1000, 57 65 'order' => 'ASC', 58 66 'orderby' => 'post_title', 59 'post__in' => $wordcamp_post_ids,67 'post__in' => array_keys ( $wordcamp_post_obj ), 60 68 ) 61 69 ); 62 70 63 71 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 ]; 65 73 66 74 $wordcamps[] = array( … … 78 86 79 87 /** 80 * Get the timestamp of the last time the post status changed88 * Get the columns headers for WordCamp 81 89 * 82 * @param int $post_id 83 * 84 * @return int 90 * @return array 85 91 */ 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; 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 ); 96 100 } 97 101 98 102 /** 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`. 100 107 */ 101 function enqueue_scripts( ) {108 function enqueue_scripts( $application_type ) { 102 109 global $post; 103 110 … … 117 124 ); 118 125 119 if ( ! is_a( $post, 'WP_POST' ) || ! has_shortcode( $post->post_content, SHORTCODE_SLUG ) ) {120 return;121 }122 123 126 wp_enqueue_script( 'wpc-application-tracker' ); 124 127 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' ); 134 129 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 } 136 151 } 137 152 138 /**139 * Get the columns headers140 *141 * @return array142 */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.