Merge pull request #13106 from seamuslee001/5.8
[civicrm-core.git] / CRM / Event / Form / Registration / ThankYou.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
fee14197 4 | CiviCRM version 5 |
6a488035 5 +--------------------------------------------------------------------+
8c9251b3 6 | Copyright CiviCRM LLC (c) 2004-2018 |
6a488035
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
27
28/**
29 *
30 *
31 * @package CRM
8c9251b3 32 * @copyright CiviCRM LLC (c) 2004-2018
6a488035
TO
33 * $Id$
34 *
35 */
36
37/**
38 * This class generates form components for processing Event
39 *
40 */
41class CRM_Event_Form_Registration_ThankYou extends CRM_Event_Form_Registration {
42
43 /**
66f9e52b 44 * Set variables up before form is built.
6a488035
TO
45 *
46 * @return void
6a488035 47 */
00be9182 48 public function preProcess() {
6a488035 49 parent::preProcess();
353ffa53
TO
50 $this->_params = $this->get('params');
51 $this->_lineItem = $this->get('lineItem');
52 $this->_part = $this->get('part');
6a488035
TO
53 $this->_totalAmount = $this->get('totalAmount');
54 $this->_receiveDate = $this->get('receiveDate');
353ffa53
TO
55 $this->_trxnId = $this->get('trxnId');
56 $finalAmount = $this->get('finalAmount');
6a488035
TO
57 $this->assign('finalAmount', $finalAmount);
58 $participantInfo = $this->get('participantInfo');
59 $this->assign('part', $this->_part);
60 $this->assign('participantInfo', $participantInfo);
61 $customGroup = $this->get('customProfile');
62 $this->assign('customProfile', $customGroup);
75b065ce 63 $this->assign('individual', $this->get('individual'));
6a488035 64
5bdcb00b 65 CRM_Event_Form_Registration_Confirm::assignProfiles($this);
6a488035
TO
66
67 CRM_Utils_System::setTitle(CRM_Utils_Array::value('thankyou_title', $this->_values['event']));
68 }
69
70 /**
100fef9d 71 * Overwrite action, since we are only showing elements in frozen mode
6a488035
TO
72 * no help display needed
73 *
74 * @return int
6a488035 75 */
00be9182 76 public function getAction() {
6a488035
TO
77 if ($this->_action & CRM_Core_Action::PREVIEW) {
78 return CRM_Core_Action::VIEW | CRM_Core_Action::PREVIEW;
79 }
80 else {
81 return CRM_Core_Action::VIEW;
82 }
83 }
84
85 /**
66f9e52b 86 * Build the form object.
6a488035 87 *
355ba699 88 * @return void
6a488035
TO
89 */
90 public function buildQuickForm() {
91 // Assign the email address from a contact id lookup as in CRM_Event_BAO_Event->sendMail()
92 $primaryContactId = $this->get('primaryContactId');
93 if ($primaryContactId) {
94 list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($primaryContactId);
95 $this->assign('email', $email);
96 }
97 $this->assignToTemplate();
03e04002 98
aaffa79f 99 $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
d9e4ebe7
PB
100 $taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings);
101 $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
102 $getTaxDetails = FALSE;
a32709be 103 $taxAmount = 0;
e189cf22 104
105 $lineItemForTemplate = array();
106 if (!empty($this->_lineItem) && is_array($this->_lineItem)) {
107 foreach ($this->_lineItem as $key => $value) {
108 if (!empty($value) && $value != 'skip') {
109 $lineItemForTemplate[$key] = $value;
110 if ($invoicing) {
111 foreach ($value as $v) {
112 if (isset($v['tax_amount']) || isset($v['tax_rate'])) {
113 $taxAmount += $v['tax_amount'];
114 $getTaxDetails = TRUE;
03b412ae 115 }
a32709be
PB
116 }
117 }
6a488035
TO
118 }
119 }
6a488035 120 }
e189cf22 121
122 if ($this->_priceSetId &&
123 !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config') &&
124 !empty($lineItemForTemplate)
125 ) {
126 $this->assign('lineItem', $lineItemForTemplate);
a32709be 127 }
6a488035 128
03b412ae
PB
129 if ($invoicing) {
130 $this->assign('getTaxDetails', $getTaxDetails);
131 $this->assign('totalTaxAmount', $taxAmount);
d9e4ebe7 132 $this->assign('taxTerm', $taxTerm);
03b412ae 133 }
6a488035 134 $this->assign('totalAmount', $this->_totalAmount);
d75f2f47 135
6a488035
TO
136 $hookDiscount = $this->get('hookDiscount');
137 if ($hookDiscount) {
138 $this->assign('hookDiscount', $hookDiscount);
139 }
140
141 $this->assign('receive_date', $this->_receiveDate);
142 $this->assign('trxn_id', $this->_trxnId);
143
144 //cosider total amount.
145 $this->assign('isAmountzero', ($this->_totalAmount <= 0) ? TRUE : FALSE);
146
147 $this->assign('defaultRole', FALSE);
148 if (CRM_Utils_Array::value('defaultRole', $this->_params[0]) == 1) {
149 $this->assign('defaultRole', TRUE);
150 }
151 $defaults = array();
152 $fields = array();
153 if (!empty($this->_fields)) {
154 foreach ($this->_fields as $name => $dontCare) {
155 $fields[$name] = 1;
156 }
157 }
158 $fields['state_province'] = $fields['country'] = $fields['email'] = 1;
159 foreach ($fields as $name => $dontCare) {
160 if (isset($this->_params[0][$name])) {
161 $defaults[$name] = $this->_params[0][$name];
162 if (substr($name, 0, 7) == 'custom_') {
163 $timeField = "{$name}_time";
164 if (isset($this->_params[0][$timeField])) {
165 $defaults[$timeField] = $this->_params[0][$timeField];
166 }
167 }
168 elseif (in_array($name, CRM_Contact_BAO_Contact::$_greetingTypes)
169 && !empty($this->_params[0][$name . '_custom'])
170 ) {
171 $defaults[$name . '_custom'] = $this->_params[0][$name . '_custom'];
172 }
173 }
174 }
175
176 $this->_submitValues = array_merge($this->_submitValues, $defaults);
177
178 $this->setDefaults($defaults);
179
6a488035
TO
180 $params['entity_id'] = $this->_eventId;
181 $params['entity_table'] = 'civicrm_event';
182 $data = array();
183 CRM_Friend_BAO_Friend::retrieve($params, $data);
a7488080 184 if (!empty($data['is_active'])) {
6a488035
TO
185 $friendText = $data['title'];
186 $this->assign('friendText', $friendText);
187 if ($this->_action & CRM_Core_Action::PREVIEW) {
188 $url = CRM_Utils_System::url('civicrm/friend',
189 "eid={$this->_eventId}&reset=1&action=preview&pcomponent=event"
190 );
191 }
192 else {
193 $url = CRM_Utils_System::url('civicrm/friend',
194 "eid={$this->_eventId}&reset=1&pcomponent=event"
195 );
196 }
197 $this->assign('friendURL', $url);
198 }
199
200 $this->freeze();
201
202 //lets give meaningful status message, CRM-4320.
203 $isOnWaitlist = $isRequireApproval = FALSE;
204 if ($this->_allowWaitlist && !$this->_allowConfirmation) {
205 $isOnWaitlist = TRUE;
206 }
207 if ($this->_requireApproval && !$this->_allowConfirmation) {
208 $isRequireApproval = TRUE;
209 }
210 $this->assign('isOnWaitlist', $isOnWaitlist);
211 $this->assign('isRequireApproval', $isRequireApproval);
212
213 // find pcp info
353ffa53 214 $dao = new CRM_PCP_DAO_PCPBlock();
6a488035 215 $dao->entity_table = 'civicrm_event';
353ffa53
TO
216 $dao->entity_id = $this->_eventId;
217 $dao->is_active = 1;
6a488035
TO
218 $dao->find(TRUE);
219
220 if ($dao->id) {
af72b8c7 221 $this->assign('pcpLink', CRM_Utils_System::url('civicrm/contribute/campaign', 'action=add&reset=1&pageId=' . $this->_eventId . '&component=event'));
6a488035
TO
222 $this->assign('pcpLinkText', $dao->link_text);
223 }
224
225 // Assign Participant Count to Lineitem Table
9da8dc8c 226 $this->assign('pricesetFieldsCount', CRM_Price_BAO_PriceSet::getPricesetCount($this->_priceSetId));
6a488035
TO
227
228 // can we blow away the session now to prevent hackery
229 $this->controller->reset();
230 }
231
232 /**
66f9e52b 233 * Process the form submission.
6a488035 234 *
6a488035 235 *
355ba699 236 * @return void
6a488035 237 */
6ea503d4
TO
238 public function postProcess() {
239 }
6a488035
TO
240
241 /**
242 * Return a descriptive name for the page, used in wizard header
243 *
244 * @return string
6a488035
TO
245 */
246 public function getTitle() {
247 return ts('Thank You Page');
248 }
96025800 249
6a488035 250}