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