Merge pull request #15475 from mecachisenros/externUrl
[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 * $Id$
18 *
19 */
20
21 /**
22 * This class generates form components for processing Event
23 *
24 */
25 class CRM_Event_Form_Registration_ThankYou extends CRM_Event_Form_Registration {
26
27 /**
28 * Set variables up before form is built.
29 *
30 * @return void
31 */
32 public function preProcess() {
33 parent::preProcess();
34 $this->_params = $this->get('params');
35 $this->_lineItem = $this->get('lineItem');
36 $this->_part = $this->get('part');
37 $this->_totalAmount = $this->get('totalAmount');
38 $this->_receiveDate = $this->get('receiveDate');
39 $this->_trxnId = $this->get('trxnId');
40 $finalAmount = $this->get('finalAmount');
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);
47 $this->assign('individual', $this->get('individual'));
48
49 CRM_Event_Form_Registration_Confirm::assignProfiles($this);
50
51 CRM_Utils_System::setTitle(CRM_Utils_Array::value('thankyou_title', $this->_values['event']));
52 }
53
54 /**
55 * Overwrite action, since we are only showing elements in frozen mode
56 * no help display needed
57 *
58 * @return int
59 */
60 public function getAction() {
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 /**
70 * Build the form object.
71 *
72 * @return void
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();
82
83 $invoicing = CRM_Invoicing_Utils::isInvoicingEnabled();
84 $taxAmount = 0;
85
86 $lineItemForTemplate = [];
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'];
95 }
96 }
97 }
98 }
99 }
100 }
101
102 if ($this->_priceSetId &&
103 !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config') &&
104 !empty($lineItemForTemplate)
105 ) {
106 $this->assignLineItemsToTemplate($lineItemForTemplate);
107 }
108
109 if ($invoicing) {
110 $this->assign('totalTaxAmount', $taxAmount);
111 }
112 $this->assign('totalAmount', $this->_totalAmount);
113
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 }
129 $defaults = [];
130 $fields = [];
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
158 $params['entity_id'] = $this->_eventId;
159 $params['entity_table'] = 'civicrm_event';
160 $data = [];
161 CRM_Friend_BAO_Friend::retrieve($params, $data);
162 if (!empty($data['is_active'])) {
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
192 $dao = new CRM_PCP_DAO_PCPBlock();
193 $dao->entity_table = 'civicrm_event';
194 $dao->entity_id = $this->_eventId;
195 $dao->is_active = 1;
196 $dao->find(TRUE);
197
198 if ($dao->id) {
199 $this->assign('pcpLink', CRM_Utils_System::url('civicrm/contribute/campaign', 'action=add&reset=1&pageId=' . $this->_eventId . '&component=event'));
200 $this->assign('pcpLinkText', $dao->link_text);
201 }
202
203 // Assign Participant Count to Lineitem Table
204 $this->assign('pricesetFieldsCount', CRM_Price_BAO_PriceSet::getPricesetCount($this->_priceSetId));
205
206 // can we blow away the session now to prevent hackery
207 $this->controller->reset();
208 }
209
210 /**
211 * Process the form submission.
212 *
213 *
214 * @return void
215 */
216 public function postProcess() {
217 }
218
219 /**
220 * Return a descriptive name for the page, used in wizard header
221 *
222 * @return string
223 */
224 public function getTitle() {
225 return ts('Thank You Page');
226 }
227
228 }