(NFC) Update CRM/Event folder for the new coder style
[civicrm-core.git] / CRM / Event / Cart / Page / CheckoutAJAX.php
CommitLineData
6a488035 1<?php
0cf587a7
EM
2
3/**
4 * Class CRM_Event_Cart_Page_CheckoutAJAX
5 */
6a488035 6class CRM_Event_Cart_Page_CheckoutAJAX {
90b461f1 7
00be9182 8 public function add_participant_to_cart() {
6a488035 9 $transaction = new CRM_Core_Transaction();
c31109f1
EM
10 $cart_id = CRM_Utils_Request::retrieve('cart_id', 'Integer');
11 $event_id = CRM_Utils_Request::retrieve('event_id', 'Integer');
6a488035 12
c31109f1 13 $cart = CRM_Event_Cart_BAO_Cart::find_by_id($cart_id);
6a488035 14
be2fb01f 15 $params_array = [
353ffa53
TO
16 'cart_id' => $cart->id,
17 'contact_id' => CRM_Event_Cart_Form_Cart::find_or_create_contact(),
7c550ca0 18 'event_id' => $event_id,
be2fb01f 19 ];
37b5eb89
A
20
21 //XXX security?
22 $participant = CRM_Event_Cart_BAO_MerParticipant::create($params_array);
6a488035
TO
23 $participant->save();
24
25 $form = new CRM_Core_Form();
26 $pform = new CRM_Event_Cart_Form_MerParticipant($participant);
27 $pform->appendQuickForm($form);
28
29 $renderer = $form->getRenderer();
30
31 $config = CRM_Core_Config::singleton();
32 $templateDir = $config->templateDir;
33 if (is_array($templateDir)) {
34 $templateDir = array_pop($templateDir);
35 }
36 $requiredTemplate = file_get_contents($templateDir . '/CRM/Form/label.tpl');
37 $renderer->setRequiredTemplate($requiredTemplate);
38
6a488035 39 $template = CRM_Core_Smarty::singleton();
ded1aa6e 40 $template->assign('form', $form->toSmarty());
6a488035
TO
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}