function add_participant_to_cart() { require 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); $cart_id = $_GET['cart_id']; $event_id = $_GET['event_id']; $cart = CRM_Event_Cart_BAO_Cart::find_by_id($_GET['cart_id']); $params_array = array('cart_id' => $cart->id, 'contact_id' => CRM_Event_Cart_Form_Cart::find_or_create_contact(), 'event_id' => $event_id); //XXX security? $participant = CRM_Event_Cart_BAO_MerParticipant::create($params_array); $participant->save(); $form = new CRM_Core_Form(); $pform = new CRM_Event_Cart_Form_MerParticipant($participant); $pform->appendQuickForm($form); $renderer = $form->getRenderer(); $config = CRM_Core_Config::singleton(); $templateDir = $config->templateDir; if (is_array($templateDir)) { $templateDir = array_pop($templateDir); } $requiredTemplate = file_get_contents($templateDir . '/CRM/Form/label.tpl'); $renderer->setRequiredTemplate($requiredTemplate); $form->accept($renderer); $template = CRM_Core_Smarty::singleton(); $template->assign('form', $renderer->toArray()); $template->assign('participant', $participant); $output = $template->fetch("CRM/Event/Cart/Form/Checkout/Participant.tpl"); $transaction->commit(); echo $output; CRM_Utils_System::civiExit(); }
/** * @param array $params * @param $participant * @param $event * * @return mixed */ public function registerParticipant($params, &$participant, $event) { $transaction = new CRM_Core_Transaction(); // handle register date CRM-4320 $registerDate = date('YmdHis'); $participantParams = array('id' => $participant->id, 'event_id' => $event->id, 'register_date' => $registerDate, 'source' => CRM_Utils_Array::value('participant_source', $params, $this->description), 'is_pay_later' => $this->is_pay_later, 'fee_amount' => CRM_Utils_Array::value('amount', $params, 0), 'fee_currency' => CRM_Utils_Array::value('currencyID', $params)); if ($participant->must_wait) { $participant_status = 'On waitlist'; } elseif (CRM_Utils_Array::value('is_pay_later', $params, FALSE)) { $participant_status = 'Pending from pay later'; } else { $participant_status = 'Registered'; } $participant_statuses = CRM_Event_PseudoConstant::participantStatus(); $participantParams['status_id'] = array_search($participant_status, $participant_statuses); $participant_status_label = CRM_Utils_Array::value($participantParams['status_id'], CRM_Event_PseudoConstant::participantStatus(NULL, NULL, 'label')); $participantParams['participant_status'] = $participant_status_label; $this->assign('isOnWaitlist', $participant->must_wait); if ($this->_action & CRM_Core_Action::PREVIEW || CRM_Utils_Array::value('mode', $params) == 'test') { $participantParams['is_test'] = 1; } else { $participantParams['is_test'] = 0; } if (self::is_administrator()) { if (!empty($params['note'])) { $note_params = array('participant_id' => $participant->id, 'contact_id' => self::getContactID(), 'note' => $params['note']); CRM_Event_BAO_Participant::update_note($note_params); } } $participant->copyValues($participantParams); $participant->save(); if (!empty($params['contributionID'])) { $payment_params = array('participant_id' => $participant->id, 'contribution_id' => $params['contributionID']); $ids = array(); $paymentParticpant = CRM_Event_BAO_ParticipantPayment::create($payment_params, $ids); } $transaction->commit(); $event_values = array(); CRM_Core_DAO::storeValues($event, $event_values); $location = array(); if (CRM_Utils_Array::value('is_show_location', $event_values) == 1) { $locationParams = array('entity_id' => $participant->event_id, 'entity_table' => 'civicrm_event'); $location = CRM_Core_BAO_Location::getValues($locationParams, TRUE); CRM_Core_BAO_Address::fixAddress($location['address'][1]); } list($pre_id, $post_id) = CRM_Event_Cart_Form_MerParticipant::get_profile_groups($participant->event_id); $payer_values = array('email' => '', 'name' => ''); if ($this->payer_contact_id) { $payer_contact_details = CRM_Contact_BAO_Contact::getContactDetails($this->payer_contact_id); $payer_values = array('email' => $payer_contact_details[1], 'name' => $payer_contact_details[0]); } $values = array('params' => array($participant->id => $participantParams), 'event' => $event_values, 'location' => $location, 'custom_pre_id' => $pre_id, 'custom_post_id' => $post_id, 'payer' => $payer_values); CRM_Event_BAO_Event::sendMail($participant->contact_id, $values, $participant->id); return $participant; }
function buildQuickForm() { $this->price_fields_for_event = array(); foreach ($this->cart->get_main_event_participants() as $participant) { $form = new CRM_Event_Cart_Form_MerParticipant($participant); $form->appendQuickForm($this); } foreach ($this->cart->get_main_events_in_carts() as $event_in_cart) { $this->price_fields_for_event[$event_in_cart->event_id] = $this->build_price_options($event_in_cart->event); } // XXX $this->addElement('text', 'discountcode', ts('If you have a discount code, enter it here')); $this->assign('events_in_carts', $this->cart->get_main_events_in_carts()); $this->assign('price_fields_for_event', $this->price_fields_for_event); $this->addButtons(array(array('type' => 'upload', 'name' => ts('Continue >>'), 'spacing' => ' ', 'isDefault' => TRUE))); if ($this->cid) { $params = array('id' => $this->cid); $contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults); $contact_values = array(); CRM_Core_DAO::storeValues($contact, $contact_values); $this->assign('contact', $contact_values); } }
/** * Build quick form. */ public function buildQuickForm() { $this->price_fields_for_event = array(); foreach ($this->cart->get_main_event_participants() as $participant) { $form = new CRM_Event_Cart_Form_MerParticipant($participant); $form->appendQuickForm($this); } foreach ($this->cart->get_main_events_in_carts() as $event_in_cart) { $this->price_fields_for_event[$event_in_cart->event_id] = $this->build_price_options($event_in_cart->event); } //If events in cart have discounts the textbox for discount code will be displayed at the top, as long as this //form name is added to cividiscount $this->assign('events_in_carts', $this->cart->get_main_events_in_carts()); $this->assign('price_fields_for_event', $this->price_fields_for_event); $this->addButtons(array(array('type' => 'upload', 'name' => ts('Continue'), 'spacing' => ' ', 'isDefault' => TRUE))); if ($this->cid) { $params = array('id' => $this->cid); $contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults); $contact_values = array(); CRM_Core_DAO::storeValues($contact, $contact_values); $this->assign('contact', $contact_values); } }