Merge pull request #15326 from totten/master-headfoot-2
[civicrm-core.git] / CRM / Event / Form / ParticipantView.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 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 * $Id$
17 *
18 */
19
20 /**
21 * This class generates form components for Participant
22 *
23 */
24 class CRM_Event_Form_ParticipantView extends CRM_Core_Form {
25
26 public $useLivePageJS = TRUE;
27
28 /**
29 * Set variables up before form is built.
30 *
31 * @return void
32 */
33 public function preProcess() {
34 $values = $ids = [];
35 $participantID = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
36 $contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
37 $params = ['id' => $participantID];
38
39 CRM_Event_BAO_Participant::getValues($params,
40 $values,
41 $ids
42 );
43
44 if (empty($values)) {
45 CRM_Core_Error::statusBounce(ts('The requested participant record does not exist (possibly the record was deleted).'));
46 }
47
48 CRM_Event_BAO_Participant::resolveDefaults($values[$participantID]);
49
50 if (!empty($values[$participantID]['fee_level'])) {
51 CRM_Event_BAO_Participant::fixEventLevel($values[$participantID]['fee_level']);
52 }
53
54 $this->assign('contactId', $contactID);
55 $this->assign('participantId', $participantID);
56
57 $paymentId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment',
58 $participantID, 'id', 'participant_id'
59 );
60 $this->assign('hasPayment', $paymentId);
61 $this->assign('componentId', $participantID);
62 $this->assign('component', 'event');
63
64 if ($parentParticipantId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant',
65 $participantID, 'registered_by_id'
66 )
67 ) {
68 $parentHasPayment = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment',
69 $parentParticipantId, 'id', 'participant_id'
70 );
71 $this->assign('parentHasPayment', $parentHasPayment);
72 }
73
74 $statusId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_Participant', $participantID, 'status_id', 'id');
75 $status = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_ParticipantStatusType', $statusId, 'name', 'id');
76 $status = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_ParticipantStatusType', $statusId, 'name', 'id');
77 if ($status == 'Transferred') {
78 $transferId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_Participant', $participantID, 'transferred_to_contact_id', 'id');
79 $pid = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_Participant', $transferId, 'id', 'contact_id');
80 $transferName = current(CRM_Contact_BAO_Contact::getContactDetails($transferId));
81 $this->assign('pid', $pid);
82 $this->assign('transferId', $transferId);
83 $this->assign('transferName', $transferName);
84 }
85 $participantStatuses = CRM_Event_PseudoConstant::participantStatus();
86
87 // CRM-20879: Show 'Transfer or Cancel' option beside 'Change fee selection'
88 // only if logged in user have 'edit event participants' permission and
89 // participant status is not Cancelled or Transferred
90 if (CRM_Core_Permission::check('edit event participants') && !in_array($status, ['Cancelled', 'Transferred'])) {
91 $this->assign('transferOrCancelLink',
92 CRM_Utils_System::url(
93 'civicrm/event/selfsvcupdate',
94 [
95 'reset' => 1,
96 'is_backoffice' => 1,
97 'pid' => $participantID,
98 'cs' => CRM_Contact_BAO_Contact_Utils::generateChecksum($contactID, NULL, 'inf'),
99 ]
100 )
101 );
102 }
103
104 if ($values[$participantID]['is_test']) {
105 $values[$participantID]['status'] = CRM_Core_TestEntity::appendTestText($values[$participantID]['status']);
106 }
107
108 // Get Note
109 $noteValue = CRM_Core_BAO_Note::getNote($participantID, 'civicrm_participant');
110
111 $values[$participantID]['note'] = array_values($noteValue);
112
113 // Get Line Items
114 $lineItem = CRM_Price_BAO_LineItem::getLineItems($participantID);
115
116 if (!CRM_Utils_System::isNull($lineItem)) {
117 $values[$participantID]['lineItem'][] = $lineItem;
118 }
119
120 $values[$participantID]['totalAmount'] = CRM_Utils_Array::value('fee_amount', $values[$participantID]);
121
122 // Get registered_by contact ID and display_name if participant was registered by someone else (CRM-4859)
123 if (!empty($values[$participantID]['participant_registered_by_id'])) {
124 $values[$participantID]['registered_by_contact_id'] = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Participant",
125 $values[$participantID]['participant_registered_by_id'],
126 'contact_id', 'id'
127 );
128 $values[$participantID]['registered_by_display_name'] = CRM_Contact_BAO_Contact::displayName($values[$participantID]['registered_by_contact_id']);
129 }
130
131 // Check if this is a primaryParticipant (registered for others) and retrieve additional participants if true (CRM-4859)
132 if (CRM_Event_BAO_Participant::isPrimaryParticipant($participantID)) {
133 $values[$participantID]['additionalParticipants'] = CRM_Event_BAO_Participant::getAdditionalParticipants($participantID);
134 }
135
136 // get the option value for custom data type
137 $customDataType = CRM_Core_OptionGroup::values('custom_data_type', FALSE, FALSE, FALSE, NULL, 'name');
138 $roleCustomDataTypeID = array_search('ParticipantRole', $customDataType);
139 $eventNameCustomDataTypeID = array_search('ParticipantEventName', $customDataType);
140 $eventTypeCustomDataTypeID = array_search('ParticipantEventType', $customDataType);
141 $allRoleIDs = explode(CRM_Core_DAO::VALUE_SEPARATOR, $values[$participantID]['role_id']);
142 $groupTree = [];
143 $finalTree = [];
144
145 foreach ($allRoleIDs as $k => $v) {
146 $roleGroupTree = CRM_Core_BAO_CustomGroup::getTree('Participant', NULL, $participantID, NULL, $v, $roleCustomDataTypeID);
147 $eventGroupTree = CRM_Core_BAO_CustomGroup::getTree('Participant', NULL, $participantID, NULL,
148 $values[$participantID]['event_id'], $eventNameCustomDataTypeID
149 );
150 $eventTypeID = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Event", $values[$participantID]['event_id'], 'event_type_id', 'id');
151 $eventTypeGroupTree = CRM_Core_BAO_CustomGroup::getTree('Participant', NULL, $participantID, NULL, $eventTypeID, $eventTypeCustomDataTypeID);
152 $groupTree = CRM_Utils_Array::crmArrayMerge($roleGroupTree, $eventGroupTree);
153 $groupTree = CRM_Utils_Array::crmArrayMerge($groupTree, $eventTypeGroupTree);
154 $groupTree = CRM_Utils_Array::crmArrayMerge($groupTree, CRM_Core_BAO_CustomGroup::getTree('Participant', NULL, $participantID));
155 foreach ($groupTree as $treeId => $trees) {
156 $finalTree[$treeId] = $trees;
157 }
158 }
159 CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $finalTree, FALSE, NULL, NULL, NULL, $participantID);
160 $eventTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $values[$participantID]['event_id'], 'title');
161 //CRM-7150, show event name on participant view even if the event is disabled
162 if (empty($values[$participantID]['event'])) {
163 $values[$participantID]['event'] = $eventTitle;
164 }
165
166 //do check for campaigns
167 if ($campaignId = CRM_Utils_Array::value('campaign_id', $values[$participantID])) {
168 $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId);
169 $values[$participantID]['campaign'] = $campaigns[$campaignId];
170 }
171
172 $this->assign($values[$participantID]);
173
174 // add viewed participant to recent items list
175 $url = CRM_Utils_System::url('civicrm/contact/view/participant',
176 "action=view&reset=1&id={$values[$participantID]['id']}&cid={$values[$participantID]['contact_id']}&context=home"
177 );
178
179 $recentOther = [];
180 if (CRM_Core_Permission::check('edit event participants')) {
181 $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/participant',
182 "action=update&reset=1&id={$values[$participantID]['id']}&cid={$values[$participantID]['contact_id']}&context=home"
183 );
184 }
185 if (CRM_Core_Permission::check('delete in CiviEvent')) {
186 $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/participant',
187 "action=delete&reset=1&id={$values[$participantID]['id']}&cid={$values[$participantID]['contact_id']}&context=home"
188 );
189 }
190
191 $participantRoles = CRM_Event_PseudoConstant::participantRole();
192 $displayName = CRM_Contact_BAO_Contact::displayName($values[$participantID]['contact_id']);
193
194 $participantCount = [];
195 $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
196 $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
197 $totalTaxAmount = 0;
198 foreach ($lineItem as $k => $v) {
199 if (CRM_Utils_Array::value('participant_count', $lineItem[$k]) > 0) {
200 $participantCount[] = $lineItem[$k]['participant_count'];
201 }
202 $totalTaxAmount = $v['tax_amount'] + $totalTaxAmount;
203 }
204 if ($invoicing) {
205 $this->assign('totalTaxAmount', $totalTaxAmount);
206 }
207 if ($participantCount) {
208 $this->assign('pricesetFieldsCount', $participantCount);
209 }
210 $this->assign('displayName', $displayName);
211 // omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container
212 CRM_Utils_System::setTitle(ts('View Event Registration for') . ' ' . $displayName);
213
214 $roleId = CRM_Utils_Array::value('role_id', $values[$participantID]);
215 $title = $displayName . ' (' . CRM_Utils_Array::value($roleId, $participantRoles) . ' - ' . $eventTitle . ')';
216
217 $sep = CRM_Core_DAO::VALUE_SEPARATOR;
218 $viewRoles = [];
219 foreach (explode($sep, $values[$participantID]['role_id']) as $k => $v) {
220 $viewRoles[] = $participantRoles[$v];
221 }
222 $values[$participantID]['role_id'] = implode(', ', $viewRoles);
223 $this->assign('role', $values[$participantID]['role_id']);
224 // add Participant to Recent Items
225 CRM_Utils_Recent::add($title,
226 $url,
227 $values[$participantID]['id'],
228 'Participant',
229 $values[$participantID]['contact_id'],
230 NULL,
231 $recentOther
232 );
233 }
234
235 /**
236 * Build the form object.
237 *
238 * @return void
239 */
240 public function buildQuickForm() {
241 $this->addButtons([
242 [
243 'type' => 'cancel',
244 'name' => ts('Done'),
245 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
246 'isDefault' => TRUE,
247 ],
248 ]);
249 }
250
251 }