/** * If no ID is given, assumes global $post object is available * Otherwise takes the given ID, assumes basic WP info is already loaded */ public static function load_activity_meta($id = null) { global $wpdb; global $a; if (is_null($id)) { global $post; $a = $post; } else { $a = get_post($id); } $a->title = $a->post_title; /** * Load basic metadata */ $a->subtitle = get_post_meta($a->ID, '_activity_subtitle', true); $a->desc_short = get_post_meta($a->ID, '_activity_desc_short', true); $a->desc_long = get_post_meta($a->ID, '_activity_desc_long', true); $a->type = get_post_meta($a->ID, '_activity_type', true); $a->image = get_post_meta($a->ID, '_activity_image', true); $a->date = get_post_meta($a->ID, '_activity_date', true); $a->start_time = get_post_meta($a->ID, '_activity_start_time', true); $a->end_time = get_post_meta($a->ID, '_activity_end_time', true); $a->arrival_time = get_post_meta($a->ID, '_activity_arrival_time', true); $a->faculty = get_post_meta($a->ID, '_activity_faculty', true); $a->location = get_post_meta($a->ID, '_activity_location', true); $a->capacity = get_post_meta($a->ID, '_activity_capacity', true); $a->reg_opens = get_post_meta($a->ID, '_activity_reg_opens', true); $a->reg_closes = get_post_meta($a->ID, '_activity_reg_closes', true); $a->waitlist = get_post_meta($a->ID, '_activity_waitlist', true); $a->fee = get_post_meta($a->ID, '_activity_fee', true); $a->desc_fee = get_post_meta($a->ID, '_activity_desc_fee', true); $a->include_tax = get_post_meta($a->ID, '_activity_include_tax', true); $a->include_gratuity = get_post_meta($a->ID, '_activity_include_gratuity', true); $a->include_donation = get_post_meta($a->ID, '_activity_include_donation', true); $a->cancellation_terms = get_post_meta($a->ID, '_activity_cancellation_terms', true); $a->confirmation_subject = get_post_meta($a->ID, '_activity_confirmation_subject', true); $a->confirmation_copy = get_post_meta($a->ID, '_activity_confirmation_copy', true); $a->waitlist_subject = get_post_meta($a->ID, '_activity_waitlist_subject', true); $a->waitlist_copy = get_post_meta($a->ID, '_activity_waitlist_copy', true); $a->service_email = get_post_meta($a->ID, '_activity_service_email', true); $a->waitlist_terms = get_post_meta($a->ID, '_activity_waitlist_terms', true); $a->addon_group = get_post_meta($a->ID, '_activity_addon_group', true); $a->has_addons = false; if (!empty($a->addon_group)) { foreach ($a->addon_group as $addon) { if (isset($addon['title']) && $addon['title'] !== '') { $a->has_addons = true; } } } if ($a->image == '') { $a->image = AC::$default_activity_image; } $a->activity_type_obj = get_post($a->type); $a->activity_type = $a->activity_type_obj->post_title; $a->faculty_obj = get_post($a->faculty); if (isset($a->faculty_obj)) { $a->faculty_name = $a->faculty_obj->post_title; } $a->location_obj = get_post($a->location); $a->location_name = $a->location_obj->post_title; /** * Format dates as new variables */ $a->formatted_date = date(AC::$date_format, $a->date); $a->formatted_reg_opens = date(AC::$date_format, $a->reg_opens); $a->formatted_long_date = date(AC::$long_date_format, $a->date); $a->formatted_start_time = date(AC::$time_format, strtotime($a->start_time)); $a->formatted_end_time = date(AC::$time_format, strtotime($a->end_time)); $a->formatted_arrival_time = date(AC::$time_format, strtotime($a->arrival_time)); /** * Special backend title showing date */ $a->backend_title = '(' . $a->formatted_date . ') ' . $a->title; /** * update registrant count */ $reservations = get_posts(array('post_type' => 'reservation', 'meta_key' => '_reservation_activity', 'meta_value' => $a->ID, 'posts_per_page' => -1)); $a->registrant_count = 0; $a->total_fees = 0; $a->total_gratuities = 0; $a->total_addons = 0; $a->total_taxes = 0; foreach ($reservations as $reservation) { $r = AC::load_reservation_meta($reservation); $a->registrant_count += $r->registrant_count; $a->total_fees += $r->fee; $a->total_gratuities += $r->gratuity; $a->total_taxes += $r->tax; if (!empty(get_post_meta($reservation->ID, '_reservation_addon_group', true))) { foreach (get_post_meta($reservation->ID, '_reservation_addon_group', true) as $addon) { $a->total_addons += $addon['cost']; } } } /** * update pending count */ $a->pending_count = 0; $id = $a->ID; $pending = $wpdb->get_results("SELECT * FROM edgimo_pending_reservations WHERE activity_id = {$id}"); foreach ($pending as $p) { if (!AC::is_pending_reservation_expired($p)) { $a->pending_count += $p->count; } } /** * update seats available count */ $a->seats_available = $a->capacity - ($a->registrant_count + $a->pending_count); /** * Set the button text and activity status */ if ($a->reg_opens > time() || $a->reg_closes < time()) { if ($a->reg_opens > time()) { $a->status = 'pending'; $a->blurb_action = '<span class="btn btn-pending">Registration opens ' . $a->formatted_reg_opens . '</span>'; } if ($a->reg_closes < time()) { $a->status = 'closed'; $a->blurb_action = '<span class="btn btn-closed">Registration closed</span>'; } } else { if ($a->seats_available < 1 && !AC::current_user_has_pending_reservation() || get_post_meta($a->ID, '_activity_status', true) == 'closed') { if ($a->waitlist === 'yes') { $a->blurb_action = '<span class="btn btn-closed">Sold Out</span> <a class="btn btn-waitlist" href="' . get_permalink($a->ID) . '?register=true">Request Waitlist</a>'; $a->status = 'waitlist'; } else { if ($a->seats_available < 1) { $a->blurb_action = '<span class="btn btn-closed">Sold Out</span>'; $a->status = 'sold_out'; } else { $a->status = 'closed'; $a->blurb_action = '<span class="btn btn-closed">Registration closed</span>'; } } } else { $a->blurb_action = '<a class="btn btn-register" href="' . get_permalink($a->ID) . '?register=true">Register</a>'; $a->status = 'reservation'; } } /** * Return the $a object or save to global post */ if (is_null($id)) { $post = $a; return true; } else { return $a; } }