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(); }
function get_participant_index() { if (!$this->cart) { $this->cart = CRM_Event_Cart_BAO_Cart::find_by_id($this->cart_id); $this->cart->load_associations(); } $index = $this->cart->get_participant_index_from_id($this->id); return $index + 1; }
function loadCart() { if ($this->event_cart_id == NULL) { $this->cart = CRM_Event_Cart_BAO_Cart::find_or_create_for_current_session(); } else { $this->cart = CRM_Event_Cart_BAO_Cart::find_by_id($this->event_cart_id); } $this->cart->load_associations(); $this->stub_out_and_inherit(); }
/** * @param null $event_cart */ public function load_associations($event_cart = NULL) { if ($this->assocations_loaded) { return; } $this->assocations_loaded = TRUE; $params = array('id' => $this->event_id); $defaults = array(); $this->event = CRM_Event_BAO_Event::retrieve($params, $defaults); if ($event_cart != NULL) { $this->event_cart = $event_cart; $this->event_cart_id = $event_cart->id; } else { $this->event_cart = CRM_Event_Cart_BAO_Cart::find_by_id($this->event_cart_id); } $participants = CRM_Event_Cart_BAO_MerParticipant::find_all_by_event_and_cart_id($this->event_id, $this->event_cart->id); foreach ($participants as $participant) { $participant->load_associations(); $this->add_participant($participant); } }