public static function get_instance() { if (!self::$instance) { self::$instance = new EPL_report_model(); } return self::$instance; }
<?php global $wpdb; $rptm = EPL_report_model::get_instance(); ?> <div id="wpbody-content" style="min-height: 100%;"> <div class="wrap"> <h2><?php epl_e('Events Planner Dashboard'); ?> </h2> <div id="poststuff" style="min-height: 100%;position: relative;"> <form id="report_form" ction="<?php echo epl_get_url(); ?> " method="post"> <table class="table"> <tr> <td> <label>Date</label> <input type="text" name="daterange" class ="daterange" size="30" /> </td> <td> <?php $field = array('input_name' => 'location', 'input_type' => 'select', 'options' => array('all' => 'All') + get_list_of_available_locations());
function epl_get_att_count(array $args) { global $event_details, $current_att_count; $default = ''; extract($args); $event_id = $event_details['ID']; $refresh = true; if (epl_is_empty_array($current_att_count) || $refresh) { $current_att_count = EPL_report_model::get_instance()->get_attendee_counts($event_id); //EPL_common_model::get_instance()->get_current_att_count( $event_id ); } switch ($for) { case 'event': return epl_get_element('_total_att_' . $event_id, $current_att_count, $default); case 'date': return epl_get_element('_total_att_' . $event_id . "_date_{$date_id}", $current_att_count, $default); case 'time': return epl_get_element('_total_att_' . $event_id . "_time_{$date_id}_{$time_id}", $current_att_count, $default); case 'price': return epl_get_element('_total_att_' . $event_id . "_price_{$date_id}_{$time_id}_{$price_id}", $current_att_count, $default); } }
/** * This function will create a global variable called $event_snapshot, which holds all the following information about the event * -Availability for each date, each time inside each date, each price inside each date and time. * -Availability errors * * Uses global vars $event_details, $current_att_count * * @since 1.0.0 * @param event_id * @param refresh * @return Sets the global $event_snapshot variable */ function event_snapshot($event_id = null, $refresh = false) { global $event_details, $capacity, $current_att_count, $event_snapshot, $epl_error, $event_totals; $event_id = is_null($event_id) ? $this->get_current_event_id() : $event_id; setup_event_details($event_id); $meta = $this->current_data[$this->regis_id]; $cart_selected_dates = epl_get_element($event_id, epl_get_element('_epl_start_date', $this->get_cart_values('_dates'))); $cart_selected_times = (array) epl_get_element($event_id, epl_get_element('_epl_start_time', $this->get_cart_values('_dates'))); $cart_selected_quantities = (array) epl_get_element($event_id, epl_get_element('_att_quantity', $this->get_cart_values('_dates'))); static $_cache = array(); $_is_cached = epl_get_element($event_id, $_cache); if ($_is_cached) { return $_cache[$event_id]; } if (empty($cart_selected_dates) && epl_get_element('cart_action', $_REQUEST) != 'add') { $epl_error[] = array('', epl__('Please select at least one date.')); } $current_att_count = EPL_report_model::get_instance()->get_attendee_counts($event_id, true); $sold_out_text = apply_filters('merm__event_snapshot__sold_out_text', epl__('Sold Out.')); //get the attendee and money totals //$_totals = $this->calculate_cart_totals(); setup_event_details($event_id); $grand_total = epl_get_element_m('grand_total', 'money_totals', $event_totals); $grand_total_key = "_grand_total"; //this will hold the snapshot $event_snapshot = array(); $qty_meta_key = "_total_att_" . $event_id; //$total_att = array_sum( ( array ) $meta[$this->regis_id]['_dates']['_att_quantity'][$event_details['ID']] ); $total_att = epl_get_element_m($event_id, 'total', epl_get_element('_att_quantity', $event_totals)); //event dates, times and prices $dates = epl_get_element('_epl_start_date', $event_details); $times = epl_get_element('_epl_start_time', $event_details); $prices = epl_get_element('_epl_price_name', $event_details); $rolling_regis = epl_get_element('_epl_rolling_regis', $event_details) == 10; if (epl_is_empty_array($dates)) { return; } //foreach event date foreach ($dates as $_date_key => $date_timestamp) { $date_timestamp = epl_get_date_timestamp($date_timestamp); //number registered for the date $date_total_att = 0; $_date = epl_formatted_date($event_details['_epl_start_date'][$_date_key], 'Y-m-d', 'date'); //the date to display $_displ_date = epl_formatted_date($_date); $qty_meta_key = "_total_att_" . $event_details['ID'] . '_date_' . $_date_key; //find the capacity for this date. $cap = $event_details['_epl_date_capacity'][$_date_key]; //find the number of people regitered for this date $num_att = epl_get_element($qty_meta_key, $current_att_count, 0); //find the available spcaes. If there is no capacity, always available $date_avail = $this->avail_spaces($cap, $num_att); $_past = epl_compare_dates(EPL_TIME, $_date . ' 23:59:59', ">"); $_date_avail_display = epl_is_ok_to_register($event_details, $_date_key); $_date_avail_display = $_date_avail_display === true ? epl__('Available') : $_date_avail_display; //snapshot template $_t = array('timestamp' => $date_timestamp, 'disp' => $_displ_date, 'avail' => $date_avail, 'avail_display' => $_date_avail_display, 'regis' => $num_att, 'db_key' => $qty_meta_key, 'cart' => 0, 'past' => $_past, 'hide' => $date_avail != '' && $date_avail <= 0); //Set the snapshot for this date $event_snapshot[$event_id][$_date_key]['date'] = $_t; $rolling_regis_time_avail = 0; //foreach time available for the event foreach ($times as $_time_key => $_time_id) { $time_total_att = 0; $_time = $event_details['_epl_start_time'][$_time_key]; $qty_meta_key = "_total_att_" . $event_details['ID'] . '_time_' . $_date_key . '_' . $_time_key; //$cap = $capacity['time'][$_time_key]; $cap = epl_get_element($_time_key, epl_get_element('_epl_time_capacity', $event_details), ''); if ($rolling_regis && $cap == '') { $cap = epl_get_element_m($_date_key, '_epl_date_per_time_capacity', $event_details); } $num_att = epl_nz(epl_get_element($qty_meta_key, $current_att_count), 0); $time_avail = $this->avail_spaces($cap, $num_att); $rolling_regis_time_avail += $cap == '' ? 999 : epl_nz($time_avail, 0); $_comp_time = epl_get_element($_time_key, $event_details['_epl_regis_endtime']); $_comp_time = !$_comp_time ? $_time : $_comp_time; //Is this time for this date in the past and not available any more? $_past = epl_compare_dates(EPL_TIME, $_date . ' ' . $_comp_time, ">"); if ($rolling_regis && $_past) { $event_snapshot[$event_id][$_date_key]['date']['hide'] = true; } $_t = array('timestamp' => strtotime($times[$_time_key], $date_timestamp), 'disp' => $times[$_time_key], 'avail' => $time_avail, 'avail_display' => $_date_avail_display, 'regis' => $num_att, 'db_key' => $qty_meta_key, 'past' => $_past); //Set the snapsot for this time for this date $event_snapshot[$event_id][$_date_key]['time'][$_time_key] = $_t; foreach ($prices as $_price_key => $_price_id) { $_price = $event_details['_epl_price_name'][$_price_key]; $price_avail = 0; $do_count = true; $price_att = 0; $price_type = epl_get_element($_price_key, epl_get_element('_epl_price_type', $event_details), 'att'); if (isset($meta['_dates']['_att_quantity'][$event_details['ID']])) { if (is_array(epl_get_element($_price_key, $meta['_dates']['_att_quantity'][$event_details['ID']]))) { $price_att = array_sum((array) epl_get_element($_price_key, $meta['_dates']['_att_quantity'][$event_details['ID']])); } else { $price_att = epl_get_element($_price_key, $meta['_dates']['_att_quantity'][$event_details['ID']]); } } $qty_meta_key = "_total_att_" . $event_details['ID'] . '_price_' . $_date_key . '_' . $_time_key . '_' . $_price_key; if (epl_is_date_level_price()) { $price_att = epl_get_element_m($_date_key, $_price_key, $cart_selected_quantities); } $cap = epl_get_element($_price_key, epl_get_element('_epl_price_capacity', $event_details), ''); $num_att = epl_nz(epl_get_element($qty_meta_key, $current_att_count), 0); $price_avail = $this->avail_spaces($cap, $num_att); if (!epl_is_empty_array($offset = $this->is_offsetter_price($_price_key)) && $cap !== '' && $price_avail > 0) { //check to make sure users are not using the price as offset against itself if ($offset['offset_key'] != $_price_key) { // see if available count of the offseter is > capacity for this price $offset_avail = $event_snapshot[$event_id][$_date_key]['time'][$_time_key]['price'][$offset['offset_key']]['avail']; $offset_count = $offset['offset_count']; if ((int) $offset_count > (int) $offset_avail) { $price_avail = 0; } elseif ($offset_avail >= $offset_count) { $price_avail = intval($offset_avail / $offset_count); } } } //echo "<pre class='prettyprint'>" . __LINE__ . "> $event_id >>>> " . print_r($price_avail, true). "</pre>"; $time_total_att += $price_att; $_t = array('disp' => $prices[$_price_key], 'avail' => $price_avail, 'avail_display' => $_date_avail_display, 'regis' => $num_att, 'db_key' => $qty_meta_key, 'cart' => $price_att, 'past' => $_past); $event_snapshot[$event_id][$_date_key]['time'][$_time_key]['price'][$_price_key] = $_t; if (epl_is_date_level_time() && epl_get_element($_date_key, $cart_selected_times) != $_time_key) { $do_count = false; } if (epl_is_date_level_price() && !in_array($_date_key, (array) $cart_selected_dates)) { //if ( $_date_key != $_price_key ) { $do_count = false; //} } if (epl_is_time_specific_price($_price_key)) { if ($event_details['_epl_price_parent_time_id'][$_price_key] != $_time_key) { unset($event_snapshot[$event_id][$_date_key]['time'][$_time_key]['price'][$_price_key]); $do_count = false; } } if (!epl_is_time_optonal() && !in_array($_time_key, $cart_selected_times) || !in_array($_date_key, (array) $cart_selected_dates)) { $do_count = false; } if (!$do_count || $price_type != 'att') { $time_total_att -= $price_att; if (isset($event_snapshot[$event_id][$_date_key]['time'][$_time_key]['price'][$_price_key]['cart'])) { $event_snapshot[$event_id][$_date_key]['time'][$_time_key]['price'][$_price_key]['cart'] = 0; } } else { //check for a price availability for each date/time if ($price_att > 0 && $price_avail !== '') { $_error = array(); if ($price_avail === 0 || $price_avail < 0) { $_error = array($_displ_date . '<br />' . $_time . '<br />' . $_price, $sold_out_text); } elseif ($price_att > epl_nz($price_avail, 1000)) { $_error = array($_displ_date . '<br />' . $_time . '<br />' . $_price, sprintf(epl__(' Only %d spaces left.'), $price_avail)); } if (!empty($_error)) { $epl_error[] = $_error; $event_snapshot[$event_id]['error'][] = $_error; } $event_snapshot[$event_id][$_date_key]['time'][$_time_key]['price'][$_price_key]['avail_display'] = epl_get_element(1, $_error); } } /* if( $price_type != 'att' ) $time_total_att -= $price_att; */ } $date_total_att += $time_total_att; $event_snapshot[$event_id][$_date_key]['time'][$_time_key]['cart'] = $time_total_att; //echo "<pre class='prettyprint'>" . __LINE__ . "> $_date " . print_r($time_total_att, true). "</pre>"; //check for time availablility for each date if ($this->flow_mode == 'n' && !epl_is_time_optonal() && $time_total_att > 0 && ($time_avail !== '' || $event_snapshot[$event_id][$_date_key]['time'][$_time_key]['past'] === true)) { $_error = array(); if (!epl_is_ongoing_event() && $event_snapshot[$event_id][$_date_key]['time'][$_time_key]['past'] == 1) { $_error = array($_displ_date . '<br />' . $_time, epl__('This time has passed.')); } if ($time_avail === 0 || $time_avail < 0) { $_error = array($_displ_date . '<br />' . $_time, $sold_out_text); } elseif ($time_total_att > epl_nz($time_avail, 1000)) { $_error = array($_displ_date . '<br />' . $_time, sprintf(epl__('Only %d spaces left.'), $time_avail)); } if (!empty($_error)) { $epl_error[] = $_error; $event_snapshot[$event_id]['error'][] = $_error; } $event_snapshot[$event_id][$_date_key]['time'][$_time_key]['avail_display'] = epl_get_element(1, $_error); } } if ($rolling_regis && $rolling_regis_time_avail == 0 && $event_snapshot[$event_id][$_date_key]['date'] == '') { $event_snapshot[$event_id][$_date_key]['date']['hide'] = true; } //check for the date availability $event_snapshot[$event_id][$_date_key]['date']['cart'] = $date_total_att; if ($date_total_att > 0 && ($date_avail !== '' || $event_snapshot[$event_id][$_date_key]['date']['past'] === true) && (!epl_is_waitlist_approved() && !epl_is_waitlist_session_approved())) { $_error = array(); if ($this->flow_mode == 'n' && ($date_avail === 0 || $date_avail < 0)) { $_error = array($_displ_date, $sold_out_text); if (epl_is_ok_for_waitlist() && ($wl_spaces_left = epl_waitlist_spaces_open()) !== false) { $_error[1] .= '<br />' . epl__('If you would like to be added to the waiting list, please click on the button below. You will not be charged at this time.'); if ($wl_spaces_left !== true) { $_error[1] .= '<br />' . sprintf('Spaces available on the waiting list: %d', $wl_spaces_left); } if (epl_waitlist_enough_spaces($event_id) == false) { $_error[1] .= '<br />' . sprintf('To continue, please select only %d.', $wl_spaces_left); } else { $_error[1] .= '<br />' . epl_anchor('#', epl__('Click here to add your name to the waitlist'), null, " class='open_add_to_waitlist_form epl_button' data-event_id='{$event_id}'"); } $this->epl->epl_util->set_response_param('waitlist_form', ''); } } elseif ($this->flow_mode == 'n' && !epl_is_ongoing_event() && $event_snapshot[$event_id][$_date_key]['date']['past'] == 1) { $_error = array($_displ_date, epl__('This date has passed.')); } elseif ($this->flow_mode == 'n' && $date_total_att > epl_nz($date_avail, 1000)) { $_error = array($_displ_date, sprintf(epl__('Only %d spaces left.'), $date_avail)); } $event_snapshot[$event_id][$_date_key]['date']['avail_display'] = epl_get_element(1, $_error); if (!empty($_error)) { $event_snapshot[$event_id]['error'][] = $_error; $epl_error[] = $_error; } } //$this->epl_table->add_row( '', $event_details['_epl_start_date'][$_date_key], $avail ); } $_cache[$event_id] = $event_snapshot; return $event_snapshot; }
function get_current_att_count($event_id = null) { global $post, $event_details, $wpdb, $current_att_count; $event_id = $event_id ? $event_id : (int) $this->get_current_event_id(); $current_att_count = EPL_report_model::get_instance()->get_attendee_counts($event_id, true); return $current_att_count; static $_cache = array(); if (epl_is_empty_array($event_details)) { $this->setup_event_details($event_id); } if (isset($_cache[$event_id])) { $current_att_count = $_cache[$event_id]; return $_cache[$event_id]; } $current_att_count = array(); $_totals = $this->get_event_regis_snapshot($event_details['ID']); $completed_filter = ''; if (isset($_totals['status_complete']) && !epl_is_empty_array($_totals['status_complete'])) { $completed_ids = implode(',', array_keys($_totals['status_complete'])); $completed_filter = " AND post_id IN ({$completed_ids}) "; } else { return null; } //After the user clicks on the Overview, the info is in the db so //we don't want to count that as a record $excl_this_regis_post_id = ''; $this_regis_post_id = isset($_SESSION['__epl']['post_ID']) ? (int) $_SESSION['__epl']['post_ID'] : null; if (!is_null($this_regis_post_id) && is_int($this_regis_post_id)) { $excl_this_regis_post_id = " AND NOT post_id = " . $this_regis_post_id; } $q = $wpdb->get_results("SELECT meta_key, SUM(meta_value) as num_attendees\n FROM {$wpdb->postmeta} as pm\n INNER JOIN {$wpdb->posts} p ON p.ID = pm.post_id\n WHERE p.post_status = 'publish'\n AND meta_key LIKE '_total_att_{$event_details['ID']}%' {$excl_this_regis_post_id} {$completed_filter}\n GROUP BY meta_key", ARRAY_A); if ($wpdb->num_rows > 0) { foreach ($q as $k => $v) { $current_att_count[$v['meta_key']] = $v['num_attendees']; } } $_cache[$event_id] = $current_att_count; }
<?php global $event_details, $regis_details; $regis = current($registration); setup_event_details($regis->event_id); $form_data = EPL_report_model::get_form_data_array($regis->input_slug, $regis->value); $payment_due = epl_get_element('epl_invoice_due', $invoice_settings, false); $invoice_date = epl_get_element('inovice_date', $_POST, $regis->regis_date); ?> <div id="epl_invoice_wrapper"> <div class="invoice_section_full" > <table class="invoice_header"> <tr> <td class="logo"> <img src="<?php echo $invoice_settings['epl_invoice_logo']; ?> " alt="<?php echo get_bloginfo(); ?> " /></td> <td class="address" style="text-align:right"><?php echo $invoice_settings['epl_invoice_company_info']; ?> </td> </tr> </table>
function event_snapshot() { global $event_details, $regis_details, $event_snapshot; $erptm = EPL_report_model::get_instance(); $data['event_snapshot'] = $this->erm->event_snapshot($_GET['event_id']); $this->epl->load_view("admin/event-snapshot", $data); exit; }
function show_attendee_list($args = array()) { global $event_details, $wpdb; $this->erptm = EPL_report_model::get_instance(); $filters = array('event_id' => intval(epl_get_element('event_id', $args, $_REQUEST['event_id'])), 'date_id' => epl_get_element('date_id', $_REQUEST, null), 'time_id' => epl_get_element('time_id', $_REQUEST, null), 'names_only' => epl_get_element('names_only', $_REQUEST, 1)); setup_event_details($filters['event_id']); $show_second_to_last = apply_filters('epl_erpt__view_names__show_second_to_last', true); $data['pack_regis'] = epl_get_element('_epl_pack_regis', $event_details, 0) == 10; $data['pack_consecutive'] = epl_get_element('_epl_pack_regis_consecutive', $event_details, 0) == 10; $_filter = array(); $attendance_dates = array(); //if this is a pack class if ($data['pack_regis']) { //find all the registrations for this event //for each one, find out if package //for each one that is pack, find the pack * X days //contstruct array $event_date_keys = array_keys($event_details['_epl_start_date']); $pack_counts = epl_get_element('_epl_price_pack_size', $event_details, array()); $registrations = $wpdb->get_results("\n SELECT rd.* \n FROM {$wpdb->epl_regis_data} rd\n INNER JOIN {$wpdb->epl_registration} r\n ON r.regis_id=rd.regis_id\n WHERE 1=1 AND (r.status = 2 OR r.status = 5)\n AND event_id = " . intval($event_details['ID'])); if ($registrations) { foreach ($registrations as $regis) { $regis_weekday = date('N', $event_details['_epl_start_date'][$regis->date_id]); if (isset($pack_counts[$regis->price_id])) { $pack_counter = epl_get_element($regis->price_id, $pack_counts, 1); $start = false; foreach ($event_details['_epl_start_date'] as $date_id => $date) { if (!$start && $date_id != $regis->date_id) { continue; } $start = true; $_weekday = date('N', $date); if ($regis_weekday != $_weekday || $pack_counter == 0) { continue; } $pack_counter--; $attendance_dates[$regis->id][$date_id] = $date; $_filter[$regis->id] = $regis->id; } if ($filters['date_id'] && !isset($attendance_dates[$regis->id][$filters['date_id']]) || $filters['time_id'] && $filters['time_id'] != $regis->time_id) { unset($_filter[$regis->id]); unset($attendance_dates[$regis->id]); } //$offset = array_search( $regis->date_id, $event_date_keys ); //$attendance_dates[$regis->id] = array_slice( $event_details['_epl_start_date'], $offset, $pack_counts[$regis->price_id] ); } } } } if (!epl_is_empty_array($_filter)) { $_filter = implode(',', $_filter); $_filter = " AND rd.id IN ({$_filter})"; } if ($filters['names_only'] == 1) { $data['list'] = $this->erptm->attendee_form_data($_filter, $filters['event_id']); } else { $data['list'] = $this->erptm->get_all_data_2($_filter); } $data['fields'] = $this->erptm->get_form_fields(); $data['attendance_dates'] = $attendance_dates; $data['event_title'] = get_the_title($filters['event_id']); $data['event_date'] = isset($_REQUEST['date_id']) ? epl_formatted_date(epl_get_element_m($_REQUEST['date_id'], '_epl_start_date', $event_details), "D, M j") : ''; $data['event_time'] = isset($_REQUEST['time_id']) ? epl_get_element_m($_REQUEST['time_id'], '_epl_start_time', $event_details) : ''; $url = admin_url("edit.php?post_type=epl_event&epl_action=view_names&table_view=1&epl_controller=epl_report_manager&print=1"); $url = add_query_arg($filters, $url); $data['print_icon'] = !isset($_REQUEST['print']) ? '<div><a href="' . $url . '" target="_blank"><img src="' . EPL_FULL_URL . 'images/printer.png" /></a></div>' : ''; $data['filters'] = $filters; $display = epl_get_element('_epl_show_attendee_list_template', $event_details, 'attendee-list-1'); $r = $this->epl->load_view('front/attendee-list/' . $display, $data, true); // if ( $GLOBALS['epl_ajax'] ) // return $r; /* if ( isset( $_REQUEST['print'] ) ) { $data['content'] = $r; $this->epl->load_view( 'admin/template', $data ); return; } */ return $r; }