| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Class CRM_Event_Cart_Page_CheckoutAJAX |
| 5 | */ |
| 6 | class CRM_Event_Cart_Page_CheckoutAJAX { |
| 7 | public function add_participant_to_cart() { |
| 8 | $transaction = new CRM_Core_Transaction(); |
| 9 | $cart_id = CRM_Utils_Request::retrieve('cart_id', 'Integer'); |
| 10 | $event_id = CRM_Utils_Request::retrieve('event_id', 'Integer'); |
| 11 | |
| 12 | $cart = CRM_Event_Cart_BAO_Cart::find_by_id($cart_id); |
| 13 | |
| 14 | $params_array = array( |
| 15 | 'cart_id' => $cart->id, |
| 16 | 'contact_id' => CRM_Event_Cart_Form_Cart::find_or_create_contact(), |
| 17 | 'event_id' => $event_id, |
| 18 | ); |
| 19 | |
| 20 | //XXX security? |
| 21 | $participant = CRM_Event_Cart_BAO_MerParticipant::create($params_array); |
| 22 | $participant->save(); |
| 23 | |
| 24 | $form = new CRM_Core_Form(); |
| 25 | $pform = new CRM_Event_Cart_Form_MerParticipant($participant); |
| 26 | $pform->appendQuickForm($form); |
| 27 | |
| 28 | $renderer = $form->getRenderer(); |
| 29 | |
| 30 | $config = CRM_Core_Config::singleton(); |
| 31 | $templateDir = $config->templateDir; |
| 32 | if (is_array($templateDir)) { |
| 33 | $templateDir = array_pop($templateDir); |
| 34 | } |
| 35 | $requiredTemplate = file_get_contents($templateDir . '/CRM/Form/label.tpl'); |
| 36 | $renderer->setRequiredTemplate($requiredTemplate); |
| 37 | |
| 38 | $form->accept($renderer); |
| 39 | $template = CRM_Core_Smarty::singleton(); |
| 40 | $template->assign('form', $renderer->toArray()); |
| 41 | $template->assign('participant', $participant); |
| 42 | $output = $template->fetch("CRM/Event/Cart/Form/Checkout/Participant.tpl"); |
| 43 | $transaction->commit(); |
| 44 | echo $output; |
| 45 | CRM_Utils_System::civiExit(); |
| 46 | } |
| 47 | |
| 48 | public function remove_participant_from_cart() { |
| 49 | $id = CRM_Utils_Request::retrieve('id', 'Integer'); |
| 50 | $participant = CRM_Event_Cart_BAO_MerParticipant::get_by_id($id); |
| 51 | $participant->delete(); |
| 52 | |
| 53 | CRM_Utils_System::civiExit(); |
| 54 | } |
| 55 | |
| 56 | } |