protected function _parser($shortcode) { EE_Registry::instance()->load_helper('Template'); $this->_ticket = $this->_data instanceof EE_Ticket ? $this->_data : null; $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; $aee = !$aee instanceof EE_Messages_Addressee && is_array($this->_extra_data) && isset($this->_extra_data['data']) && $this->_extra_data['data'] instanceof EE_Messages_Addressee ? $this->_extra_data['data'] : $aee; //possible EE_Line_Item may be incoming data $this->_ticket = empty($this->_ticket) && $this->_data instanceof EE_Line_Item && $aee instanceof EE_Messages_Addressee && !empty($aee->line_items_with_children[$this->_data->ID()]['EE_Ticket']) && $aee->line_items_with_children[$this->_data->ID()]['EE_Ticket'] instanceof EE_Ticket ? $aee->line_items_with_children[$this->_data->ID()]['EE_Ticket'] : $this->_ticket; //if still no ticket, then let's see if there is a reg_obj. If there IS, then we'll try and grab the ticket from the reg_obj instead. if (empty($this->_ticket)) { $this->_ticket = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration ? $aee->reg_obj->ticket() : NULL; } //If there is no event object by now then get out. if (!$this->_ticket instanceof EE_Ticket) { return ''; } switch ($shortcode) { case '[TICKET_ID]': return $this->_ticket->ID(); break; case '[TICKET_NAME]': return $this->_ticket->get('TKT_name'); break; case '[TICKET_DESCRIPTION]': return $this->_ticket->get('TKT_description'); break; case '[TICKET_PRICE]': return EEH_Template::format_currency($this->_ticket->get('TKT_price')); break; case '[TICKET_PRICE_WITH_TAXES]': return EEH_Template::format_currency($this->_ticket->get_ticket_total_with_taxes()); break; case '[TKT_QTY_PURCHASED]': return $aee instanceof EE_Messages_Addressee ? $aee->tickets[$this->_ticket->ID()]['count'] : ''; break; } if (strpos($shortcode, '[TKT_USES_*') !== FALSE) { $attrs = $this->_get_shortcode_attrs($shortcode); $schema = empty($attrs['schema']) ? null : $attrs['schema']; return $this->_ticket->get_pretty('TKT_uses', $schema); } return ''; }
/** * @param \EE_Transaction $transaction * @param \EE_Ticket $ticket * @param \EE_Event $event * @param float $REG_final_price * @return \EE_Registration * @throws \EE_Error */ public function get_registration_mock(EE_Transaction $transaction, EE_Ticket $ticket, EE_Event $event, $REG_final_price = 10.0) { return $this->new_model_obj_with_dependencies('Registration', array('TXN_ID' => $transaction->ID(), 'TKT_ID' => $ticket->ID(), 'EVT_ID' => $event->ID(), 'REG_final_price' => $REG_final_price, 'REG_count' => EEM_Registration::PRIMARY_REGISTRANT_COUNT)); }
/** * _recalculate_ticket_datetime_availability * * @access private * @param EE_Ticket $ticket * @param int $qty * @return int */ private static function _recalculate_ticket_datetime_availability(EE_Ticket $ticket, $qty = 0) { if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) { // loop thru tickets, which will ALSO include individual ticket records AND a total foreach (self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) { // subtract the qty of selected tickets from each datetime's available spaces this ticket has access to, self::$_available_spaces['datetimes'][$DTD_ID] = self::$_available_spaces['datetimes'][$DTD_ID] - $qty; } } }
/** * This attaches a list of given prices to a ticket. * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old price info and prices are automatically "archived" via the ticket. * * @access private * @param array $prices Array of prices from the form. * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. * @param bool $new_prices Whether attach existing incoming prices or create new ones. * @param int|bool $base_price if FALSE then NOT doing a base price add. * @param int|bool $base_price_id if present then this is the base_price_id being updated. * @return EE_Ticket */ protected function _add_prices_to_ticket($prices = array(), EE_Ticket $ticket, $new_prices = FALSE, $base_price = FALSE, $base_price_id = FALSE) { //let's just get any current prices that may exist on the given ticket so we can remove any prices that got trashed in this session. $current_prices_on_ticket = $base_price !== FALSE ? $ticket->base_price(TRUE) : $ticket->price_modifiers(); $updated_prices = array(); // if $base_price ! FALSE then updating a base price. if ($base_price !== FALSE) { $prices[1] = array('PRC_ID' => $new_prices || $base_price_id === 1 ? NULL : $base_price_id, 'PRT_ID' => 1, 'PRC_amount' => $base_price, 'PRC_name' => $ticket->get('TKT_name'), 'PRC_desc' => $ticket->get('TKT_description')); } //possibly need to save tkt if (!$ticket->ID()) { $ticket->save(); } foreach ($prices as $row => $prc) { $prt_id = !empty($prc['PRT_ID']) ? $prc['PRT_ID'] : NULL; if (empty($prt_id)) { continue; } //prices MUST have a price type id. $PRC_values = array('PRC_ID' => !empty($prc['PRC_ID']) ? $prc['PRC_ID'] : NULL, 'PRT_ID' => $prt_id, 'PRC_amount' => !empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, 'PRC_name' => !empty($prc['PRC_name']) ? $prc['PRC_name'] : '', 'PRC_desc' => !empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', 'PRC_is_default' => false, 'PRC_order' => $row); if ($new_prices || empty($PRC_values['PRC_ID'])) { $PRC_values['PRC_ID'] = 0; $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), FALSE, FALSE); } else { $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); //update this price with new values foreach ($PRC_values as $field => $newprc) { $PRC->set($field, $newprc); } } $PRC->save(); $prcid = $PRC->ID(); $updated_prices[$prcid] = $PRC; $ticket->_add_relation_to($PRC, 'Price'); } //now let's remove any prices that got removed from the ticket if (!empty($current_prices_on_ticket)) { $current = array_keys($current_prices_on_ticket); $updated = array_keys($updated_prices); $prices_to_remove = array_diff($current, $updated); if (!empty($prices_to_remove)) { foreach ($prices_to_remove as $prc_id) { $p = $current_prices_on_ticket[$prc_id]; $ticket->_remove_relation_to($p, 'Price'); //delete permanently the price $p->delete_permanently(); } } } return $ticket; }
/** * Setup an individual ticket form for the decaf event editor page * * @access private * @param EE_Ticket $ticket the ticket object * @param boolean $skeleton whether we're generating a skeleton for js manipulation * @param int $row * @return string generated html for the ticket row. */ private function _get_ticket_row($ticket, $skeleton = FALSE, $row = 0) { $template_args = array('tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && !$skeleton ? ' tkt-archived' : '', 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, 'TKT_ID' => $ticket->get('TKT_ID'), 'TKT_name' => $ticket->get('TKT_name'), 'TKT_start_date' => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'), 'TKT_end_date' => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'), 'TKT_is_default' => $ticket->get('TKT_is_default'), 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), 'trash_icon' => ($skeleton || !empty($ticket) && !$ticket->get('TKT_deleted')) && (!empty($ticket) && $ticket->get('TKT_sold') === 0) ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon', 'disabled' => $skeleton || !empty($ticket) && !$ticket->get('TKT_deleted') ? '' : ' disabled=disabled'); $price = $ticket->ID() !== 0 ? $ticket->get_first_related('Price', array('default_where_conditions' => 'none')) : EE_Registry::instance()->load_model('Price')->create_default_object(); $price_args = array('price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, 'PRC_amount' => $price->get('PRC_amount'), 'PRT_ID' => $price->get('PRT_ID'), 'PRC_ID' => $price->get('PRC_ID'), 'PRC_is_default' => $price->get('PRC_is_default')); //make sure we have default start and end dates if skeleton //handle rows that should NOT be empty if (empty($template_args['TKT_start_date'])) { //if empty then the start date will be now. $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp')); } if (empty($template_args['TKT_end_date'])) { //get the earliest datetime (if present); $earliest_dtt = $this->_cpt_model_obj->ID() > 0 ? $this->_cpt_model_obj->get_first_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC'))) : NULL; if (!empty($earliest_dtt)) { $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a'); } else { $template_args['TKT_end_date'] = date('Y-m-d h:i a', mktime(0, 0, 0, date("m"), date("d") + 7, date("Y"))); } } $template_args = array_merge($template_args, $price_args); $template = apply_filters('FHEE__Events_Admin_Page__get_ticket_row__template', EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', $ticket); return EEH_Template::display_template($template, $template_args, TRUE); }
private function _get_datetimes_from_ticket(EE_Ticket $ticket, $att = NULL) { return isset($this->_extra_data['data']->tickets) ? $this->_extra_data['data']->tickets[$ticket->ID()]['dtt_objs'] : array(); }
/** * simulate six sales for an event's ticket, which will also increase sold qty for D1 & D2 * * @param \EE_Ticket $ticket * @param int $qty * @throws \EE_Error */ protected function _sell_tickets(EE_Ticket $ticket, $qty = 1) { if ($ticket instanceof EE_Ticket) { $transaction = EE_Transaction::new_instance(array('STS_ID' => EEM_Transaction::complete_status_code, 'TXN_timestamp' => time() - DAY_IN_SECONDS, 'TXN_total' => 0, 'TXN_paid' => 0)); $transaction->save(); for ($x = 1; $x <= $qty; $x++) { $registration = EE_Registration::new_instance(array('STS_ID' => EEM_Registration::status_id_approved, 'REG_date' => time() - DAY_IN_SECONDS, 'REG_code' => $transaction->ID() . "-" . $ticket->ID() . "-{$x}-test", 'TXN_ID' => $transaction->ID(), 'EVT_ID' => $ticket->get_event_ID(), 'TKT_ID' => $ticket->ID())); $registration->save(); } } }
/** * _total_ticket_quantity_within_event_additional_limit * * returns true if the requested ticket quantity * does not exceed the event's additional limit * when combined with the tickets for the same event * that have already been added to the cart * * @access protected * @param EE_Ticket $ticket * @param int $quantity * @param bool $cart_update * @return bool */ protected function _total_ticket_quantity_within_event_additional_limit(EE_Ticket $ticket, $quantity = 1, $cart_update = false) { $event = $ticket->first_datetime()->event(); // we want to exclude this ticket from the count if this is a cart update, // because we are not simply incrementing the cart count // but replacing the quantity in the cart with a totally new value $TKT_ID = $cart_update ? $ticket->ID() : 0; $event_tickets = $this->_event_tickets($TKT_ID); if (isset($event_tickets[$event->ID()])) { // add tickets that are already in cart $quantity += count($event_tickets[$event->ID()]); } return $quantity <= $event->additional_limit() ? true : false; }
/** * simply take an incoming ticket and calculate the subtotal for the ticket * @param EE_Ticket $ticket * @return float subtotal calculated from all EE_Price[] on Ticket. */ private static function _get_subtotal_for_admin(EE_Ticket $ticket) { $subtotal = 0; //get all prices $prices = $ticket->get_many_related('Price', array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))); //let's loop through them (base price is always the first item) foreach ($prices as $price) { if ($price instanceof EE_Price) { $price_type = $price->type_obj(); if ($price_type instanceof EE_Price_Type) { switch ($price->type_obj()->base_type()) { case 1: // base price // base price case 3: // surcharges $subtotal += $price->is_percent() ? $subtotal * $price->get('PRC_amount') / 100 : $price->get('PRC_amount'); break; case 2: // discounts $subtotal -= $price->is_percent() ? $subtotal * $price->get('PRC_amount') / 100 : $price->get('PRC_amount'); break; } } } } $TKT_ID = $ticket->ID(); self::$_subtotal = array($TKT_ID => $subtotal); return $subtotal; }
/** * _ticket_qty_input * * @param EE_Line_Item $line_item * @param \EE_Ticket $ticket * @return mixed */ private function _ticket_qty_input(EE_Line_Item $line_item, EE_Ticket $ticket) { if ($ticket->remaining() - $line_item->quantity()) { $disabled = ''; $disabled_class = ''; $disabled_style = ''; $disabled_title = __('add one item', 'event_espresso'); $query_args = array('event_cart' => 'add_ticket', 'ticket' => $ticket->ID(), 'line_item' => $line_item->code()); } else { $disabled = ' disabled="disabled"'; $disabled_class = ' disabled'; $disabled_style = ' style="background-color:#e8e8e8;"'; $disabled_title = __('there are no more items available', 'event_espresso'); $query_args = array('event_cart' => 'view'); } return ' <div class="event-cart-ticket-qty-dv"> <input type="text" id="event-cart-update-txt-qty-' . $line_item->code() . '" class="event-cart-update-txt-qty ' . $disabled_class . '" name="event_cart_update_txt_qty[' . $ticket->ID() . '][' . $line_item->code() . ']" rel="' . $line_item->code() . '" value="' . $line_item->quantity() . '" ' . $disabled . ' size="3" /> <span class="event-cart-update-buttons" > <a title = "' . $disabled_title . '" class="event-cart-add-ticket-button event-cart-button event-cart-icon-button button' . $disabled_class . '" rel = "' . $line_item->code() . '" href = "' . add_query_arg($query_args, EE_EVENT_QUEUE_BASE_URL) . '" ' . $disabled_style . ' > <span class="dashicons dashicons-plus" ></span > </a > <a title = "' . __('remove one item', 'event_espresso') . '" class="event-cart-remove-ticket-button event-cart-button event-cart-icon-button button" rel = "' . $line_item->code() . '" href = "' . add_query_arg(array('event_cart' => 'remove_ticket', 'ticket' => $ticket->ID(), 'line_item' => $line_item->code()), EE_EVENT_QUEUE_BASE_URL) . '" > <span class="dashicons dashicons-minus" ></span > </a > <a title="' . __('delete item from event cart', 'event_espresso') . '" class="event-cart-delete-ticket-button event-cart-button event-cart-icon-button button" rel="' . $line_item->code() . '" href="' . add_query_arg(array('event_cart' => 'delete_ticket', 'ticket' => $ticket->ID(), 'line_item' => $line_item->code()), EE_EVENT_QUEUE_BASE_URL) . '" > <span class="dashicons dashicons-trash"></span> </a> </span > </div> '; }
/** * Given the grand total line item and a ticket, finds the event sub-total * line item the ticket's purchase should be added onto * * @access public * @param EE_Line_Item $grand_total the grand total line item * @param EE_Ticket $ticket * @throws \EE_Error * @return EE_Line_Item */ public static function get_event_line_item_for_ticket(EE_Line_Item $grand_total, EE_Ticket $ticket) { $first_datetime = $ticket->first_datetime(); if (!$first_datetime instanceof EE_Datetime) { throw new EE_Error(sprintf(__('The supplied ticket (ID %d) has no datetimes', 'event_espresso'), $ticket->ID())); } $event = $first_datetime->event(); if (!$event instanceof EE_Event) { throw new EE_Error(sprintf(__('The supplied ticket (ID %d) has no event data associated with it.', 'event_espresso'), $ticket->ID())); } $event_line_item = NULL; $found = false; foreach (EEH_Line_Item::get_event_subtotals($grand_total) as $event_line_item) { // default event subtotal, we should only ever find this the first time this method is called if (!$event_line_item->OBJ_ID()) { // let's use this! but first... set the event details EEH_Line_Item::set_event_subtotal_details($event_line_item, $event); $found = true; break; } else { if ($event_line_item->OBJ_ID() === $event->ID()) { // found existing line item for this event in the cart, so break out of loop and use this one $found = true; break; } } } if (!$found) { //there is no event sub-total yet, so add it $pre_tax_subtotal = EEH_Line_Item::get_pre_tax_subtotal($grand_total); // create a new "event" subtotal below that $event_line_item = EEH_Line_Item::create_event_subtotal($pre_tax_subtotal, null, $event); // and set the event details EEH_Line_Item::set_event_subtotal_details($event_line_item, $event); } return $event_line_item; }
/** * Given the grand total line item and a ticket, finds the event sub-total * line item the ticket's purchase should be added onto * * @access public * @param EE_Line_Item $grand_total the grand total line item * @param EE_Ticket $ticket * @throws \EE_Error * @return EE_Line_Item */ public static function get_event_line_item_for_ticket(EE_Line_Item $grand_total, EE_Ticket $ticket) { $first_datetime = $ticket->first_datetime(); if (!$first_datetime instanceof EE_Datetime) { throw new EE_Error(sprintf(__('The supplied ticket (ID %d) has no datetimes', 'event_espresso'), $ticket->ID())); } $event = $first_datetime->event(); if (!$event instanceof EE_Event) { throw new EE_Error(sprintf(__('The supplied ticket (ID %d) has no event data associated with it.', 'event_espresso'), $ticket->ID())); } return EEH_Line_Item::get_event_line_item($grand_total, $event); }
/** * @process items for adding to cart * @access public * @param EE_Ticket $ticket * @param int $qty * @return TRUE on success, FALSE on fail */ public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1) { $datetimes = $ticket->datetimes(); $event_names = array(); foreach ($datetimes as $datetime) { $event = $datetime->event(); $event_names[$event->ID()] = $event->name(); } $description_addition = " (For " . implode(", ", $event_names) . ")"; $full_description = $ticket->description() . $description_addition; // add $ticket to cart $line_item = EE_Line_Item::new_instance(array('LIN_name' => $ticket->name(), 'LIN_desc' => $full_description, 'LIN_unit_price' => $ticket->price(), 'LIN_quantity' => $qty, 'LIN_is_taxable' => $ticket->taxable(), 'LIN_order' => count($this->_grand_total->children()), 'LIN_total' => $ticket->price() * $qty, 'LIN_type' => EEM_Line_Item::type_line_item, 'OBJ_ID' => $ticket->ID(), 'OBJ_type' => 'Ticket')); //now add the sub-line items $running_total_for_ticket = 0; foreach ($ticket->prices(array('order_by' => array('PRC_order' => 'ASC'))) as $price) { $sign = $price->is_discount() ? -1 : 1; $price_total = $price->is_percent() ? $running_total_for_ticket * $price->amount() / 100 : $price->amount() * $qty; $sub_line_item = EE_Line_Item::new_instance(array('LIN_name' => $price->name(), 'LIN_desc' => $price->desc(), 'LIN_quantity' => $price->is_percent() ? null : $qty, 'LIN_is_taxable' => false, 'LIN_order' => $price->order(), 'LIN_total' => $sign * $price_total, 'LIN_type' => EEM_Line_Item::type_sub_line_item, 'OBJ_ID' => $price->ID(), 'OBJ_type' => 'Price')); if ($price->is_percent()) { $sub_line_item->set_percent($sign * $price->amount()); } else { $sub_line_item->set_unit_price($sign * $price->amount()); } $running_total_for_ticket += $price_total; $line_item->add_child_line_item($sub_line_item); } $this->_add_item($line_item); return $this->save_cart() ? TRUE : FALSE; }
/** * Returns the new line item created by adding a purchase of the ticket * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total * @param EE_Ticket $ticket * @param int $qty * @return EE_Line_Item */ public static function create_ticket_line_item(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) { $datetimes = $ticket->datetimes(); $event_names = array(); foreach ($datetimes as $datetime) { $event = $datetime->event(); $event_names[$event->ID()] = $event->name(); } $description_addition = sprintf(__(' (For %1$s)', 'event_espresso'), implode(", ", $event_names)); $full_description = $ticket->description() . $description_addition; $items_subtotal = self::get_items_subtotal($total_line_item); // add $ticket to cart $line_item = EE_Line_Item::new_instance(array('LIN_name' => $ticket->name(), 'LIN_desc' => $full_description, 'LIN_unit_price' => $ticket->price(), 'LIN_quantity' => $qty, 'LIN_is_taxable' => $ticket->taxable(), 'LIN_order' => $items_subtotal instanceof EE_Line_Item ? count($items_subtotal->children()) : 0, 'LIN_total' => $ticket->price() * $qty, 'LIN_type' => EEM_Line_Item::type_line_item, 'OBJ_ID' => $ticket->ID(), 'OBJ_type' => 'Ticket')); //now add the sub-line items $running_total_for_ticket = 0; foreach ($ticket->prices(array('order_by' => array('PRC_order' => 'ASC'))) as $price) { $sign = $price->is_discount() ? -1 : 1; $price_total = $price->is_percent() ? $running_total_for_ticket * $price->amount() / 100 : $price->amount() * $qty; $sub_line_item = EE_Line_Item::new_instance(array('LIN_name' => $price->name(), 'LIN_desc' => $price->desc(), 'LIN_quantity' => $price->is_percent() ? null : $qty, 'LIN_is_taxable' => false, 'LIN_order' => $price->order(), 'LIN_total' => $sign * $price_total, 'LIN_type' => EEM_Line_Item::type_sub_line_item, 'OBJ_ID' => $price->ID(), 'OBJ_type' => 'Price')); if ($price->is_percent()) { $sub_line_item->set_percent($sign * $price->amount()); } else { $sub_line_item->set_unit_price($sign * $price->amount()); } $running_total_for_ticket += $price_total; $line_item->add_child_line_item($sub_line_item); } return $line_item; }