Changeset 7979
- Timestamp:
- 12/17/2018 07:34:32 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
r7978 r7979 23 23 24 24 /** 25 * Get camps that are active enough to be shown on the tracker25 * Get applications that are active enough to be shown on the tracker 26 26 * 27 * @param string $application_type Type of application. Could be `wordcamp` or `meetup`. 27 28 * @return array 28 29 */ 29 function get_active_ wordcamps() {30 function get_active_events( $application_type ) { 30 31 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(); 34 36 $inactive_timestamp = strtotime( '60 days ago' ); 37 $post_type = ''; 35 38 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 } 40 48 41 $wordcamp_post_objs = $wpdb->get_results( 49 $shown_statuses = array_keys( $statuses ); 50 51 $event_post_objs = $wpdb->get_results( 42 52 $wpdb->prepare( 43 53 " … … 45 55 FROM {$wpdb->prefix}postmeta 46 56 WHERE 47 meta_key like '_status_change_log_$ wordcamp_post_type%'57 meta_key like '_status_change_log_$post_type%' 48 58 AND 49 59 meta_value >= %d … … 53 63 ) 54 64 ); 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; 58 69 } 59 70 60 71 $raw_posts = get_posts( 61 72 array( 62 'post_type' => WCPT_POST_TYPE_ID,73 'post_type' => $post_type, 63 74 'post_status' => $shown_statuses, 64 75 'posts_per_page' => 1000, 65 76 'order' => 'ASC', 66 77 'orderby' => 'post_title', 67 'post__in' => array_keys ( $ wordcamp_post_obj),78 'post__in' => array_keys ( $event_posts ), 68 79 ) 69 80 ); 70 81 71 82 foreach ( $raw_posts as $key => $post ) { 72 $last_update_timestamp = $ wordcamp_post_obj[ $post->ID ];83 $last_update_timestamp = $event_posts[ $post->ID ]; 73 84 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 } 82 103 } 83 104 84 return $ wordcamps;105 return $events; 85 106 } 86 107 … … 90 111 * @return array 91 112 */ 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 ); 113 function 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 } 100 131 } 101 132 … … 128 159 wp_enqueue_style( 'wpc-application-tracker' ); 129 160 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 ); 151 170 } 152 171
Note: See TracChangeset
for help on using the changeset viewer.