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 '';
 }
Пример #2
0
 /**
  * This method simply calculates the total taxes for a given ticket (by pulling the prices attached to the ticket and applying default taxes to it).
  * Note: this is just an intermediary helper method added to facilitate quick calc of taxes for tickets listed in the event editor.
  * @param  EE_Ticket $ticket incoming EE_Ticket
  * @return float             total taxes to apply to ticket.
  */
 public static function get_total_taxes_for_admin(EE_Ticket $ticket)
 {
     $tax = 0;
     $total_tax = 0;
     //This first checks to see if the given ticket is taxable.
     if (!$ticket->get('TKT_taxable')) {
         return $tax;
     }
     //get subtotal (notice we're only retrieving a subtotal if there isn't one given)
     $subtotal = self::get_subtotal_for_admin($ticket);
     //get taxes
     $taxes = self::get_taxes_for_admin();
     //apply taxes to subtotal
     foreach ($taxes as $tax) {
         //assuming taxes are not cumulative
         $total_tax += $subtotal * $tax->get('PRC_amount') / 100;
     }
     return $total_tax;
 }
 /**
  * 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);
 }