Move BAO and template files into event cart
[civicrm-core.git] / ext / eventcart / CRM / Event / Cart / Form / Checkout / ThankYou.php
1 <?php
2
3 /**
4 * Class CRM_Event_Cart_Form_Checkout_ThankYou
5 */
6 class CRM_Event_Cart_Form_Checkout_ThankYou extends CRM_Event_Cart_Form_Cart {
7 public $line_items = NULL;
8 public $sub_total = 0;
9
10 public function buildLineItems() {
11 foreach ($this->cart->events_in_carts as $event_in_cart) {
12 $event_in_cart->load_location();
13 }
14 $line_items = $this->get('line_items');
15 foreach ($line_items as $line_item) {
16 $event_in_cart = $this->cart->get_event_in_cart_by_event_id($line_item['event_id']);
17
18 $not_waiting_participants = [];
19 foreach ($event_in_cart->not_waiting_participants() as $participant) {
20 $not_waiting_participants[] = [
21 'display_name' => CRM_Contact_BAO_Contact::displayName($participant->contact_id),
22 ];
23 }
24 $waiting_participants = [];
25 foreach ($event_in_cart->waiting_participants() as $participant) {
26 $waiting_participants[] = [
27 'display_name' => CRM_Contact_BAO_Contact::displayName($participant->contact_id),
28 ];
29 }
30
31 $line_item['event'] = $event_in_cart->event;
32 $line_item['num_participants'] = count($not_waiting_participants);
33 $line_item['participants'] = $not_waiting_participants;
34 $line_item['num_waiting_participants'] = count($waiting_participants);
35 $line_item['waiting_participants'] = $waiting_participants;
36 $line_item['location'] = $event_in_cart->location;
37 $line_item['class'] = $event_in_cart->event->parent_event_id ? 'subevent' : NULL;
38
39 $this->sub_total += $line_item['amount'];
40 $this->line_items[] = $line_item;
41 }
42 $this->assign('line_items', $this->line_items);
43 }
44
45 public function buildQuickForm() {
46 $defaults = [];
47 $ids = [];
48 $template_params_to_copy = [
49 'billing_name',
50 'billing_city',
51 'billing_country',
52 'billing_postal_code',
53 'billing_state',
54 'billing_street_address',
55 'credit_card_exp_date',
56 'credit_card_type',
57 'credit_card_number',
58 ];
59 foreach ($template_params_to_copy as $template_param_to_copy) {
60 $this->assign($template_param_to_copy, $this->get($template_param_to_copy));
61 }
62 $this->buildLineItems();
63 $this->assign('discounts', $this->get('discounts'));
64 $this->assign('events_in_carts', $this->cart->events_in_carts);
65 $this->assign('transaction_id', $this->get('trxn_id'));
66 $this->assign('transaction_date', $this->get('trxn_date'));
67 $this->assign('payment_required', $this->get('payment_required'));
68 $this->assign('is_pay_later', $this->get('is_pay_later'));
69 $this->assign('pay_later_receipt', $this->get('pay_later_receipt'));
70 $this->assign('sub_total', $this->sub_total);
71 $this->assign('total', $this->get('total'));
72 // XXX Configure yourself
73 //$this->assign( 'site_name', "" );
74 //$this->assign( 'site_contact', "" );
75 }
76
77 public function preProcess() {
78 $this->event_cart_id = $this->get('last_event_cart_id');
79 $this->loadCart();
80 //$this->loadParticipants( );
81 }
82
83 }