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 stub_out_and_inherit() { $transaction = new CRM_Core_Transaction(); foreach ($this->cart->get_main_events_in_carts() as $event_in_cart) { if (empty($event_in_cart->participants)) { $participant = CRM_Event_Cart_BAO_MerParticipant::create(array('cart_id' => $this->cart->id, 'event_id' => $event_in_cart->event_id, 'contact_id' => self::find_or_create_contact($this->getContactID()))); $participant->save(); $event_in_cart->add_participant($participant); } $event_in_cart->save(); } $transaction->commit(); }
function postProcess() { $params = $this->controller->exportValues($this->_name); $main_event_in_cart = $this->cart->get_event_in_cart_by_event_id($this->conference_event->id); foreach ($this->cart->events_in_carts as $event_in_cart) { if ($event_in_cart->event->parent_event_id == $this->conference_event->id) { $event_in_cart->remove_participant_by_contact_id($this->contact_id); if (empty($event_in_cart->participants)) { $this->cart->remove_event_in_cart($event_in_cart->id); } } } $slot_index = -1; foreach ($this->events_by_slot as $slot_name => $events) { $slot_index++; $field_name = "slot_{$slot_index}"; $session_event_id = CRM_Utils_Array::value($field_name, $params, NULL); if (!$session_event_id) { continue; } $event_in_cart = $this->cart->add_event($session_event_id); $values = array(); CRM_Core_DAO::storeValues($this->main_participant, $values); $values['id'] = NULL; $values['event_id'] = $event_in_cart->event_id; $participant = CRM_Event_Cart_BAO_MerParticipant::create($values); $participant->save(); $event_in_cart->add_participant($participant); } $this->cart->save(); }