Merge pull request #23073 from colemanw/contactTypeIcon
[civicrm-core.git] / CRM / Event / Form / Registration / ThankYou.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 *
15 * @package CRM
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 */
18
19 /**
20 * This class generates form components for processing Event
21 *
22 */
23 class CRM_Event_Form_Registration_ThankYou extends CRM_Event_Form_Registration {
24
25 /**
26 * Set variables up before form is built.
27 *
28 * @return void
29 */
30 public function preProcess() {
31 parent::preProcess();
32 $this->_params = $this->get('params');
33 $this->_lineItem = $this->get('lineItem');
34 $this->_part = $this->get('part');
35 $this->_totalAmount = $this->get('totalAmount');
36 $this->_receiveDate = $this->get('receiveDate');
37 $this->_trxnId = $this->get('trxnId');
38 $finalAmount = $this->get('finalAmount');
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);
45 $this->assign('individual', $this->get('individual'));
46
47 CRM_Event_Form_Registration_Confirm::assignProfiles($this);
48
49 $this->setTitle(CRM_Utils_Array::value('thankyou_title', $this->_values['event']));
50 }
51
52 /**
53 * Overwrite action, since we are only showing elements in frozen mode
54 * no help display needed
55 *
56 * @return int
57 */
58 public function getAction() {
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 /**
68 * Build the form object.
69 *
70 * @return void
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) {
76 $email = CRM_Utils_Array::valueByRegexKey('/^email-/', current($this->_params));
77 if (!$email) {
78 $email = CRM_Contact_BAO_Contact::getPrimaryEmail($primaryContactId);
79 }
80 $this->assign('email', $email);
81 }
82 $this->assignToTemplate();
83
84 $invoicing = CRM_Invoicing_Utils::isInvoicingEnabled();
85 $taxAmount = 0;
86
87 $lineItemForTemplate = [];
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'];
96 }
97 }
98 }
99 }
100 }
101 }
102
103 if ($this->_priceSetId &&
104 !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config') &&
105 !empty($lineItemForTemplate)
106 ) {
107 $this->assignLineItemsToTemplate($lineItemForTemplate);
108 }
109
110 if ($invoicing) {
111 $this->assign('totalTaxAmount', $taxAmount);
112 }
113 $this->assign('totalAmount', $this->_totalAmount);
114
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.
124 $this->assign('isAmountzero', $this->_totalAmount <= 0);
125
126 $this->assign('defaultRole', FALSE);
127 if (CRM_Utils_Array::value('defaultRole', $this->_params[0]) == 1) {
128 $this->assign('defaultRole', TRUE);
129 }
130 $defaults = [];
131 $fields = [];
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
159 $params['entity_id'] = $this->_eventId;
160 $params['entity_table'] = 'civicrm_event';
161 $data = [];
162 CRM_Friend_BAO_Friend::retrieve($params, $data);
163 if (!empty($data['is_active'])) {
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
179 $this->assign('iCal', CRM_Event_BAO_Event::getICalLinks($this->_eventId));
180
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
195 $dao = new CRM_PCP_DAO_PCPBlock();
196 $dao->entity_table = 'civicrm_event';
197 $dao->entity_id = $this->_eventId;
198 $dao->is_active = 1;
199 $dao->find(TRUE);
200
201 if ($dao->id) {
202 $this->assign('pcpLink', CRM_Utils_System::url('civicrm/contribute/campaign', 'action=add&reset=1&pageId=' . $this->_eventId . '&component=event'));
203 $this->assign('pcpLinkText', $dao->link_text);
204 }
205
206 // Assign Participant Count to Lineitem Table
207 $this->assign('pricesetFieldsCount', CRM_Price_BAO_PriceSet::getPricesetCount($this->_priceSetId));
208
209 // can we blow away the session now to prevent hackery
210 $this->controller->reset();
211 }
212
213 /**
214 * Process the form submission.
215 *
216 *
217 * @return void
218 */
219 public function postProcess() {
220 }
221
222 /**
223 * Return a descriptive name for the page, used in wizard header
224 *
225 * @return string
226 */
227 public function getTitle() {
228 return ts('Thank You Page');
229 }
230
231 }