Merge pull request #23041 from christianwach/lab-core-2103
[civicrm-core.git] / CRM / Event / Form / Registration / ThankYou.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
bc77d7c0
TO
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12/**
13 *
14 *
15 * @package CRM
ca5cec67 16 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
17 */
18
19/**
20 * This class generates form components for processing Event
21 *
22 */
23class CRM_Event_Form_Registration_ThankYou extends CRM_Event_Form_Registration {
24
25 /**
66f9e52b 26 * Set variables up before form is built.
6a488035
TO
27 *
28 * @return void
6a488035 29 */
00be9182 30 public function preProcess() {
6a488035 31 parent::preProcess();
353ffa53
TO
32 $this->_params = $this->get('params');
33 $this->_lineItem = $this->get('lineItem');
34 $this->_part = $this->get('part');
6a488035
TO
35 $this->_totalAmount = $this->get('totalAmount');
36 $this->_receiveDate = $this->get('receiveDate');
353ffa53
TO
37 $this->_trxnId = $this->get('trxnId');
38 $finalAmount = $this->get('finalAmount');
6a488035
TO
39 $this->assign('finalAmount', $finalAmount);
40 $participantInfo = $this->get('participantInfo');
41 $this->assign('part', $this->_part);
42 $this->assign('participantInfo', $participantInfo);
43 $customGroup = $this->get('customProfile');
44 $this->assign('customProfile', $customGroup);
75b065ce 45 $this->assign('individual', $this->get('individual'));
6a488035 46
5bdcb00b 47 CRM_Event_Form_Registration_Confirm::assignProfiles($this);
6a488035 48
94fd9d17 49 $this->setTitle(CRM_Utils_Array::value('thankyou_title', $this->_values['event']));
6a488035
TO
50 }
51
52 /**
100fef9d 53 * Overwrite action, since we are only showing elements in frozen mode
6a488035
TO
54 * no help display needed
55 *
56 * @return int
6a488035 57 */
00be9182 58 public function getAction() {
6a488035
TO
59 if ($this->_action & CRM_Core_Action::PREVIEW) {
60 return CRM_Core_Action::VIEW | CRM_Core_Action::PREVIEW;
61 }
62 else {
63 return CRM_Core_Action::VIEW;
64 }
65 }
66
67 /**
66f9e52b 68 * Build the form object.
6a488035 69 *
355ba699 70 * @return void
6a488035
TO
71 */
72 public function buildQuickForm() {
73 // Assign the email address from a contact id lookup as in CRM_Event_BAO_Event->sendMail()
74 $primaryContactId = $this->get('primaryContactId');
75 if ($primaryContactId) {
2ba7b9e8
JG
76 $email = CRM_Utils_Array::valueByRegexKey('/^email-/', current($this->_params));
77 if (!$email) {
78 $email = CRM_Contact_BAO_Contact::getPrimaryEmail($primaryContactId);
79 }
6a488035
TO
80 $this->assign('email', $email);
81 }
82 $this->assignToTemplate();
03e04002 83
ec5e7bcf 84 $invoicing = CRM_Invoicing_Utils::isInvoicingEnabled();
a32709be 85 $taxAmount = 0;
e189cf22 86
be2fb01f 87 $lineItemForTemplate = [];
e189cf22 88 if (!empty($this->_lineItem) && is_array($this->_lineItem)) {
89 foreach ($this->_lineItem as $key => $value) {
90 if (!empty($value) && $value != 'skip') {
91 $lineItemForTemplate[$key] = $value;
92 if ($invoicing) {
93 foreach ($value as $v) {
94 if (isset($v['tax_amount']) || isset($v['tax_rate'])) {
95 $taxAmount += $v['tax_amount'];
03b412ae 96 }
a32709be
PB
97 }
98 }
6a488035
TO
99 }
100 }
6a488035 101 }
e189cf22 102
103 if ($this->_priceSetId &&
104 !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config') &&
105 !empty($lineItemForTemplate)
106 ) {
1dacd56e 107 $this->assignLineItemsToTemplate($lineItemForTemplate);
a32709be 108 }
6a488035 109
03b412ae 110 if ($invoicing) {
03b412ae
PB
111 $this->assign('totalTaxAmount', $taxAmount);
112 }
6a488035 113 $this->assign('totalAmount', $this->_totalAmount);
d75f2f47 114
6a488035
TO
115 $hookDiscount = $this->get('hookDiscount');
116 if ($hookDiscount) {
117 $this->assign('hookDiscount', $hookDiscount);
118 }
119
120 $this->assign('receive_date', $this->_receiveDate);
121 $this->assign('trxn_id', $this->_trxnId);
122
123 //cosider total amount.
f7dbf5d9 124 $this->assign('isAmountzero', $this->_totalAmount <= 0);
6a488035
TO
125
126 $this->assign('defaultRole', FALSE);
127 if (CRM_Utils_Array::value('defaultRole', $this->_params[0]) == 1) {
128 $this->assign('defaultRole', TRUE);
129 }
be2fb01f
CW
130 $defaults = [];
131 $fields = [];
6a488035
TO
132 if (!empty($this->_fields)) {
133 foreach ($this->_fields as $name => $dontCare) {
134 $fields[$name] = 1;
135 }
136 }
137 $fields['state_province'] = $fields['country'] = $fields['email'] = 1;
138 foreach ($fields as $name => $dontCare) {
139 if (isset($this->_params[0][$name])) {
140 $defaults[$name] = $this->_params[0][$name];
141 if (substr($name, 0, 7) == 'custom_') {
142 $timeField = "{$name}_time";
143 if (isset($this->_params[0][$timeField])) {
144 $defaults[$timeField] = $this->_params[0][$timeField];
145 }
146 }
147 elseif (in_array($name, CRM_Contact_BAO_Contact::$_greetingTypes)
148 && !empty($this->_params[0][$name . '_custom'])
149 ) {
150 $defaults[$name . '_custom'] = $this->_params[0][$name . '_custom'];
151 }
152 }
153 }
154
155 $this->_submitValues = array_merge($this->_submitValues, $defaults);
156
157 $this->setDefaults($defaults);
158
6a488035
TO
159 $params['entity_id'] = $this->_eventId;
160 $params['entity_table'] = 'civicrm_event';
be2fb01f 161 $data = [];
6a488035 162 CRM_Friend_BAO_Friend::retrieve($params, $data);
a7488080 163 if (!empty($data['is_active'])) {
6a488035
TO
164 $friendText = $data['title'];
165 $this->assign('friendText', $friendText);
166 if ($this->_action & CRM_Core_Action::PREVIEW) {
167 $url = CRM_Utils_System::url('civicrm/friend',
168 "eid={$this->_eventId}&reset=1&action=preview&pcomponent=event"
169 );
170 }
171 else {
172 $url = CRM_Utils_System::url('civicrm/friend',
173 "eid={$this->_eventId}&reset=1&pcomponent=event"
174 );
175 }
176 $this->assign('friendURL', $url);
177 }
178
679bd095
AH
179 $this->assign('iCal', CRM_Event_BAO_Event::getICalLinks($this->_eventId));
180
6a488035
TO
181 $this->freeze();
182
183 //lets give meaningful status message, CRM-4320.
184 $isOnWaitlist = $isRequireApproval = FALSE;
185 if ($this->_allowWaitlist && !$this->_allowConfirmation) {
186 $isOnWaitlist = TRUE;
187 }
188 if ($this->_requireApproval && !$this->_allowConfirmation) {
189 $isRequireApproval = TRUE;
190 }
191 $this->assign('isOnWaitlist', $isOnWaitlist);
192 $this->assign('isRequireApproval', $isRequireApproval);
193
194 // find pcp info
353ffa53 195 $dao = new CRM_PCP_DAO_PCPBlock();
6a488035 196 $dao->entity_table = 'civicrm_event';
353ffa53
TO
197 $dao->entity_id = $this->_eventId;
198 $dao->is_active = 1;
6a488035
TO
199 $dao->find(TRUE);
200
201 if ($dao->id) {
af72b8c7 202 $this->assign('pcpLink', CRM_Utils_System::url('civicrm/contribute/campaign', 'action=add&reset=1&pageId=' . $this->_eventId . '&component=event'));
6a488035
TO
203 $this->assign('pcpLinkText', $dao->link_text);
204 }
205
206 // Assign Participant Count to Lineitem Table
9da8dc8c 207 $this->assign('pricesetFieldsCount', CRM_Price_BAO_PriceSet::getPricesetCount($this->_priceSetId));
6a488035
TO
208
209 // can we blow away the session now to prevent hackery
210 $this->controller->reset();
211 }
212
213 /**
66f9e52b 214 * Process the form submission.
6a488035 215 *
6a488035 216 *
355ba699 217 * @return void
6a488035 218 */
6ea503d4
TO
219 public function postProcess() {
220 }
6a488035
TO
221
222 /**
223 * Return a descriptive name for the page, used in wizard header
224 *
225 * @return string
6a488035
TO
226 */
227 public function getTitle() {
228 return ts('Thank You Page');
229 }
96025800 230
6a488035 231}