/** * Spawns instance variations for Product, when recurring instance is created. */ function save_event_product_variations($instance_id) { $product_id = !empty($_POST['eab_e2mp_product_id']) ? $_POST['eab_e2mp_product_id'] : false; $event = new Eab_EventModel(get_post($instance_id)); $quick_price = $this->_get_quick_product_price($product_id); $meta = get_post_meta($product_id, 'mp_var_name', true); if (!$meta || !is_array($meta)) { /* add_post_meta($product_id, 'mp_var_name', array('')); add_post_meta($product_id, 'mp_sku', array(0)); add_post_meta($product_id, 'mp_price', array(0)); $meta = array(0); */ $meta = array(); } $max = count($meta); $meta[$max] = date_i18n(get_option("date_format"), $event->get_start_timestamp()); $sku = get_post_meta($product_id, 'mp_sku', true); $sku[$max] = $instance_id; $price = get_post_meta($product_id, 'mp_price', true); $price[$max] = $quick_price; $unset_first = false; if (empty($meta[0]) && empty($sku[0])) { unset($meta[0]); $meta = array_values($meta); unset($sku[0]); $sku = array_values($sku); unset($price[0]); $price = array_values($price); $unset_first = true; } update_post_meta($product_id, 'mp_var_name', $meta); update_post_meta($product_id, 'mp_sku', $sku); update_post_meta($product_id, 'mp_price', $price); do_action('eab-mp-variation-meta', $product_id, $max, $instance_id, $event->is_recurring_child(), $unset_first); // Let's get the variations going if (class_exists('MP_Installer')) { // Clean up all the variations first $query = new WP_Query(array('post_type' => apply_filters('mp_product_variation_post_type', 'mp_product_variation'), 'posts_per_page' => -1, 'post_parent' => $product_id)); if (!empty($query->posts)) { foreach ($query->posts as $variation) { wp_delete_post($variation->ID, true); } } // Import new ones $mpi = MP_Installer::get_instance(); $mpi->product_variations_transition($product_id, 'external'); } }
/** * Spawns instance variations for Product, when recurring instance is created. */ function save_event_product_variations($instance_id) { $product_id = !empty($_POST['eab_e2mp_product_id']) ? $_POST['eab_e2mp_product_id'] : false; $event = new Eab_EventModel(get_post($instance_id)); $quick_price = $this->_get_quick_product_price($product_id); $meta = get_post_meta($product_id, 'mp_var_name', true); if (!$meta || !is_array($meta)) { /* add_post_meta($product_id, 'mp_var_name', array('')); add_post_meta($product_id, 'mp_sku', array(0)); add_post_meta($product_id, 'mp_price', array(0)); $meta = array(0); */ $meta = array(); } $max = count($meta); $meta[$max] = date_i18n(get_option("date_format"), $event->get_start_timestamp()); $sku = get_post_meta($product_id, 'mp_sku', true); $sku[$max] = $instance_id; $price = get_post_meta($product_id, 'mp_price', true); $price[$max] = $quick_price; $unset_first = false; if (empty($meta[0]) && empty($sku[0])) { unset($meta[0]); $meta = array_values($meta); unset($sku[0]); $sku = array_values($sku); unset($price[0]); $price = array_values($price); $unset_first = true; } update_post_meta($product_id, 'mp_var_name', $meta); update_post_meta($product_id, 'mp_sku', $sku); update_post_meta($product_id, 'mp_price', $price); do_action('eab-mp-variation-meta', $product_id, $max, $instance_id, $event->is_recurring_child(), $unset_first); // Add a download link, so that app will be a digital product //$file = get_post_meta($product_id, 'mp_file', true); //if ( !$file ) add_post_meta( $product_id, 'mp_file', get_permalink( $instance_id ) ); }
function manage_posts_custom_column($column) { global $post; switch ($column) { case "attendees": global $wpdb; $event = $post instanceof Eab_EventModel ? $post : new Eab_EventModel($post); $yes = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM " . Eab_EventsHub::tablename(Eab_EventsHub::BOOKING_TABLE) . " WHERE event_id = %d AND status = %s;", $event->get_id(), Eab_EventModel::BOOKING_YES)); $no = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM " . Eab_EventsHub::tablename(Eab_EventsHub::BOOKING_TABLE) . " WHERE event_id = %d AND status = %s;", $event->get_id(), Eab_EventModel::BOOKING_NO)); $maybe = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM " . Eab_EventsHub::tablename(Eab_EventsHub::BOOKING_TABLE) . " WHERE event_id = %d AND status = %s;", $event->get_id(), Eab_EventModel::BOOKING_MAYBE)); printf('<b>' . __('Attending / Undecided', self::TEXT_DOMAIN) . ':</b> %d / %d<br />', $yes, $maybe); printf('<b>' . __('Not Attending', self::TEXT_DOMAIN) . ':</b> %d', $no); echo ' '; echo '<a class="button" href="' . admin_url('index.php?eab_export=attendees&event_id=' . $event->get_id()) . '" class="eab-export_attendees">' . __('Export', self::TEXT_DOMAIN) . '</a>'; break; case "start": $event = new Eab_EventModel($post); $df = get_option('date_format', 'Y-m-d'); if (!$event->is_recurring()) { echo date_i18n($df, $event->get_start_timestamp()) . ' - ' . date_i18n($df, $event->get_end_timestamp()); } else { $repeats = $event->get_supported_recurrence_intervals(); $title = @$repeats[$event->get_recurrence()]; $start = date_i18n($df, $event->get_recurrence_starts()); $end = date_i18n($df, $event->get_recurrence_ends()); printf(__("From %s, repeats every %s until %s", self::TEXT_DOMAIN), $start, $title, $end); } break; case "venue": $event = new Eab_EventModel($post); echo $event->get_venue_location(); break; case "event": $event = new Eab_EventModel($post); $post_type_object = get_post_type_object($post->post_type); $edit_link = get_edit_post_link($event->get_id()); $statuses = array(); if ('draft' == $post->post_status) { $statuses[] = __('Draft'); } if ('private' == $post->post_status) { $statuses[] = __('Private'); } if ('pending' == $post->post_status) { $statuses[] = __('Pending'); } $status = $statuses ? ' - <span class="post-state">' . join(', ', $statuses) . '</span>' : ''; $title = current_user_can($post_type_object->cap->edit_post, $event->get_id()) && 'trash' != $post->post_status ? '<strong>' . '<a class="row-title" href="' . $edit_link . '" title="' . esc_attr(sprintf(__('Edit “%s”'), $event->get_title())) . '">' . $event->get_title() . '</a> ' . $status . '</strong>' : '<strong>' . $event->get_title() . ' ' . $status . '</strong>'; if (current_user_can($post_type_object->cap->edit_post, $event->get_id()) && 'trash' != $post->post_status) { $actions['edit'] = '<a title="' . esc_attr(__('Edit Event', self::TEXT_DOMAIN)) . '" href="' . $edit_link . '">' . __('Edit') . '</a>'; if (!$event->is_recurring()) { $actions['inline hide-if-no-js'] = '<a href="#" class="editinline" title="' . esc_attr(__('Edit this Event inline', self::TEXT_DOMAIN)) . '">' . __('Quick Edit') . '</a>'; } } if (current_user_can($post_type_object->cap->delete_post, $event->get_id())) { if ('trash' == $post->post_status) { $actions['untrash'] = "<a title='" . esc_attr(__('Restore this Event from the Trash', self::TEXT_DOMAIN)) . "' href='" . wp_nonce_url(admin_url(sprintf($post_type_object->_edit_link . '&action=untrash', $event->get_id())), 'untrash-' . $post->post_type . '_' . $event->get_id()) . "'>" . __('Restore') . "</a>"; } else { if (EMPTY_TRASH_DAYS) { $actions['trash'] = '<a class="submitdelete" title="' . esc_attr(__('Move this Event to the Trash', self::TEXT_DOMAIN)) . '" href="' . get_delete_post_link($event->get_id()) . '">' . __('Trash') . '</a>'; } } if ('trash' == $post->post_status || !EMPTY_TRASH_DAYS) { $actions['delete'] = "<a class='submitdelete' title='" . esc_attr(__('Delete this Event permanently', self::TEXT_DOMAIN)) . "' href='" . get_delete_post_link($event->get_id(), '', true) . "'>" . __('Delete Permanently') . "</a>"; } } if ('trash' != $post->post_status) { $event_id = $event->get_id(); if ($event->is_recurring()) { $children = Eab_CollectionFactory::get_all_recurring_children_events($event); if (!$children || !$children[0] instanceof Eab_EventModel) { $event_id = false; } else { $event_id = $children[0]->get_id(); } } if ($event_id) { $actions['view'] = '<a href="' . get_permalink($event_id) . '" title="' . esc_attr(sprintf(__('View “%s”'), $event->get_title())) . '" rel="permalink">' . __('View') . '</a>'; } } echo $title; if (!empty($actions)) { foreach ($actions as $action => $link) { $actions[$action] = "<span class='{$action}'>{$link}</span>"; } } echo '<div class="row-actions">' . join(' | ', $actions) . '</div>'; get_inline_data($post); break; } }