Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
0cf587a7 EM |
2 | |
3 | /** | |
4 | * Class CRM_Event_Cart_Page_CheckoutAJAX | |
5 | */ | |
6a488035 | 6 | class CRM_Event_Cart_Page_CheckoutAJAX { |
00be9182 | 7 | public function add_participant_to_cart() { |
6a488035 | 8 | $transaction = new CRM_Core_Transaction(); |
c31109f1 EM |
9 | $cart_id = CRM_Utils_Request::retrieve('cart_id', 'Integer'); |
10 | $event_id = CRM_Utils_Request::retrieve('event_id', 'Integer'); | |
6a488035 | 11 | |
c31109f1 | 12 | $cart = CRM_Event_Cart_BAO_Cart::find_by_id($cart_id); |
6a488035 | 13 | |
353ffa53 TO |
14 | $params_array = array( |
15 | 'cart_id' => $cart->id, | |
16 | 'contact_id' => CRM_Event_Cart_Form_Cart::find_or_create_contact(), | |
7c550ca0 | 17 | 'event_id' => $event_id, |
353ffa53 | 18 | ); |
37b5eb89 A |
19 | |
20 | //XXX security? | |
21 | $participant = CRM_Event_Cart_BAO_MerParticipant::create($params_array); | |
6a488035 TO |
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 | ||
00be9182 | 48 | public function remove_participant_from_cart() { |
c31109f1 EM |
49 | $id = CRM_Utils_Request::retrieve('id', 'Integer'); |
50 | $participant = CRM_Event_Cart_BAO_MerParticipant::get_by_id($id); | |
6a488035 TO |
51 | $participant->delete(); |
52 | ||
53 | CRM_Utils_System::civiExit(); | |
54 | } | |
96025800 | 55 | |
6a488035 | 56 | } |