Merge pull request #18400 from aydun/class_api_tweak_2
[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 CRM_Utils_System::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 list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($primaryContactId);
77 $this->assign('email', $email);
78 }
79 $this->assignToTemplate();
80
81 $invoicing = CRM_Invoicing_Utils::isInvoicingEnabled();
82 $taxAmount = 0;
83
84 $lineItemForTemplate = [];
85 if (!empty($this->_lineItem) && is_array($this->_lineItem)) {
86 foreach ($this->_lineItem as $key => $value) {
87 if (!empty($value) && $value != 'skip') {
88 $lineItemForTemplate[$key] = $value;
89 if ($invoicing) {
90 foreach ($value as $v) {
91 if (isset($v['tax_amount']) || isset($v['tax_rate'])) {
92 $taxAmount += $v['tax_amount'];
93 }
94 }
95 }
96 }
97 }
98 }
99
100 if ($this->_priceSetId &&
101 !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config') &&
102 !empty($lineItemForTemplate)
103 ) {
104 $this->assignLineItemsToTemplate($lineItemForTemplate);
105 }
106
107 if ($invoicing) {
108 $this->assign('totalTaxAmount', $taxAmount);
109 }
110 $this->assign('totalAmount', $this->_totalAmount);
111
112 $hookDiscount = $this->get('hookDiscount');
113 if ($hookDiscount) {
114 $this->assign('hookDiscount', $hookDiscount);
115 }
116
117 $this->assign('receive_date', $this->_receiveDate);
118 $this->assign('trxn_id', $this->_trxnId);
119
120 //cosider total amount.
121 $this->assign('isAmountzero', $this->_totalAmount <= 0);
122
123 $this->assign('defaultRole', FALSE);
124 if (CRM_Utils_Array::value('defaultRole', $this->_params[0]) == 1) {
125 $this->assign('defaultRole', TRUE);
126 }
127 $defaults = [];
128 $fields = [];
129 if (!empty($this->_fields)) {
130 foreach ($this->_fields as $name => $dontCare) {
131 $fields[$name] = 1;
132 }
133 }
134 $fields['state_province'] = $fields['country'] = $fields['email'] = 1;
135 foreach ($fields as $name => $dontCare) {
136 if (isset($this->_params[0][$name])) {
137 $defaults[$name] = $this->_params[0][$name];
138 if (substr($name, 0, 7) == 'custom_') {
139 $timeField = "{$name}_time";
140 if (isset($this->_params[0][$timeField])) {
141 $defaults[$timeField] = $this->_params[0][$timeField];
142 }
143 }
144 elseif (in_array($name, CRM_Contact_BAO_Contact::$_greetingTypes)
145 && !empty($this->_params[0][$name . '_custom'])
146 ) {
147 $defaults[$name . '_custom'] = $this->_params[0][$name . '_custom'];
148 }
149 }
150 }
151
152 $this->_submitValues = array_merge($this->_submitValues, $defaults);
153
154 $this->setDefaults($defaults);
155
156 $params['entity_id'] = $this->_eventId;
157 $params['entity_table'] = 'civicrm_event';
158 $data = [];
159 CRM_Friend_BAO_Friend::retrieve($params, $data);
160 if (!empty($data['is_active'])) {
161 $friendText = $data['title'];
162 $this->assign('friendText', $friendText);
163 if ($this->_action & CRM_Core_Action::PREVIEW) {
164 $url = CRM_Utils_System::url('civicrm/friend',
165 "eid={$this->_eventId}&reset=1&action=preview&pcomponent=event"
166 );
167 }
168 else {
169 $url = CRM_Utils_System::url('civicrm/friend',
170 "eid={$this->_eventId}&reset=1&pcomponent=event"
171 );
172 }
173 $this->assign('friendURL', $url);
174 }
175
176 $this->assign('iCal', CRM_Event_BAO_Event::getICalLinks($this->_eventId));
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 }