3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * This class generates form components for Participant
22 class CRM_Event_Form_ParticipantView
extends CRM_Core_Form
{
24 public $useLivePageJS = TRUE;
27 * Set variables up before form is built.
31 public function preProcess() {
33 $participantID = CRM_Utils_Request
::retrieve('id', 'Positive', $this, TRUE);
34 $contactID = CRM_Utils_Request
::retrieve('cid', 'Positive', $this, TRUE);
35 $params = ['id' => $participantID];
37 CRM_Event_BAO_Participant
::getValues($params,
43 CRM_Core_Error
::statusBounce(ts('The requested participant record does not exist (possibly the record was deleted).'));
46 CRM_Event_BAO_Participant
::resolveDefaults($values[$participantID]);
48 if (!empty($values[$participantID]['fee_level'])) {
49 CRM_Event_BAO_Participant
::fixEventLevel($values[$participantID]['fee_level']);
52 $this->assign('contactId', $contactID);
53 $this->assign('participantId', $participantID);
55 $paymentId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
56 $participantID, 'id', 'participant_id'
58 $this->assign('hasPayment', $paymentId);
59 $this->assign('componentId', $participantID);
60 $this->assign('component', 'event');
62 if ($parentParticipantId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant',
63 $participantID, 'registered_by_id'
66 $parentHasPayment = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
67 $parentParticipantId, 'id', 'participant_id'
69 $this->assign('parentHasPayment', $parentHasPayment);
72 $statusId = CRM_Core_DAO
::getFieldValue('CRM_Event_BAO_Participant', $participantID, 'status_id', 'id');
73 $status = CRM_Core_DAO
::getFieldValue('CRM_Event_BAO_ParticipantStatusType', $statusId, 'name', 'id');
74 if ($status == 'Transferred') {
75 $transferId = CRM_Core_DAO
::getFieldValue('CRM_Event_BAO_Participant', $participantID, 'transferred_to_contact_id', 'id');
76 $pid = CRM_Core_DAO
::getFieldValue('CRM_Event_BAO_Participant', $transferId, 'id', 'contact_id');
77 $transferName = current(CRM_Contact_BAO_Contact
::getContactDetails($transferId));
78 $this->assign('pid', $pid);
79 $this->assign('transferId', $transferId);
80 $this->assign('transferName', $transferName);
83 // CRM-20879: Show 'Transfer or Cancel' option beside 'Change fee selection'
84 // only if logged in user have 'edit event participants' permission and
85 // participant status is not Cancelled or Transferred
86 if (CRM_Core_Permission
::check('edit event participants') && !in_array($status, ['Cancelled', 'Transferred'])) {
87 $this->assign('transferOrCancelLink',
88 CRM_Utils_System
::url(
89 'civicrm/event/selfsvcupdate',
93 'pid' => $participantID,
94 'cs' => CRM_Contact_BAO_Contact_Utils
::generateChecksum($contactID, NULL, 'inf'),
100 if ($values[$participantID]['is_test']) {
101 $values[$participantID]['status'] = CRM_Core_TestEntity
::appendTestText($values[$participantID]['status']);
105 $noteValue = CRM_Core_BAO_Note
::getNote($participantID, 'civicrm_participant');
107 $values[$participantID]['note'] = array_values($noteValue);
110 $lineItem = CRM_Price_BAO_LineItem
::getLineItems($participantID);
112 if (!CRM_Utils_System
::isNull($lineItem)) {
113 $values[$participantID]['lineItem'][] = $lineItem;
116 $values[$participantID]['totalAmount'] = $values[$participantID]['fee_amount'] ??
NULL;
118 // Get registered_by contact ID and display_name if participant was registered by someone else (CRM-4859)
119 if (!empty($values[$participantID]['participant_registered_by_id'])) {
120 $values[$participantID]['registered_by_contact_id'] = CRM_Core_DAO
::getFieldValue("CRM_Event_DAO_Participant",
121 $values[$participantID]['participant_registered_by_id'],
124 $values[$participantID]['registered_by_display_name'] = CRM_Contact_BAO_Contact
::displayName($values[$participantID]['registered_by_contact_id']);
127 // Check if this is a primaryParticipant (registered for others) and retrieve additional participants if true (CRM-4859)
128 if (CRM_Event_BAO_Participant
::isPrimaryParticipant($participantID)) {
129 $values[$participantID]['additionalParticipants'] = CRM_Event_BAO_Participant
::getAdditionalParticipants($participantID);
132 // get the option value for custom data type
133 $customDataType = CRM_Core_OptionGroup
::values('custom_data_type', FALSE, FALSE, FALSE, NULL, 'name');
134 $roleCustomDataTypeID = array_search('ParticipantRole', $customDataType);
135 $eventNameCustomDataTypeID = array_search('ParticipantEventName', $customDataType);
136 $eventTypeCustomDataTypeID = array_search('ParticipantEventType', $customDataType);
137 $allRoleIDs = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $values[$participantID]['role_id']);
140 foreach ($allRoleIDs as $k => $v) {
141 $roleGroupTree = CRM_Core_BAO_CustomGroup
::getTree('Participant', NULL, $participantID, NULL, $v, $roleCustomDataTypeID);
142 $eventGroupTree = CRM_Core_BAO_CustomGroup
::getTree('Participant', NULL, $participantID, NULL,
143 $values[$participantID]['event_id'], $eventNameCustomDataTypeID
145 $eventTypeID = CRM_Core_DAO
::getFieldValue("CRM_Event_DAO_Event", $values[$participantID]['event_id'], 'event_type_id', 'id');
146 $eventTypeGroupTree = CRM_Core_BAO_CustomGroup
::getTree('Participant', NULL, $participantID, NULL, $eventTypeID, $eventTypeCustomDataTypeID);
147 $groupTree = CRM_Utils_Array
::crmArrayMerge($roleGroupTree, $eventGroupTree);
148 $groupTree = CRM_Utils_Array
::crmArrayMerge($groupTree, $eventTypeGroupTree);
149 $groupTree = CRM_Utils_Array
::crmArrayMerge($groupTree, CRM_Core_BAO_CustomGroup
::getTree('Participant', NULL, $participantID));
150 foreach ($groupTree as $treeId => $trees) {
151 $finalTree[$treeId] = $trees;
154 CRM_Core_BAO_CustomGroup
::buildCustomDataView($this, $finalTree, FALSE, NULL, NULL, NULL, $participantID);
155 $eventTitle = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $values[$participantID]['event_id'], 'title');
156 //CRM-7150, show event name on participant view even if the event is disabled
157 if (empty($values[$participantID]['event'])) {
158 $values[$participantID]['event'] = $eventTitle;
161 //do check for campaigns
162 if ($campaignId = CRM_Utils_Array
::value('campaign_id', $values[$participantID])) {
163 $campaigns = CRM_Campaign_BAO_Campaign
::getCampaigns($campaignId);
164 $values[$participantID]['campaign'] = $campaigns[$campaignId];
167 $this->assign($values[$participantID]);
169 // add viewed participant to recent items list
170 $url = CRM_Utils_System
::url('civicrm/contact/view/participant',
171 "action=view&reset=1&id={$values[$participantID]['id']}&cid={$values[$participantID]['contact_id']}&context=home"
175 if (CRM_Core_Permission
::check('edit event participants')) {
176 $recentOther['editUrl'] = CRM_Utils_System
::url('civicrm/contact/view/participant',
177 "action=update&reset=1&id={$values[$participantID]['id']}&cid={$values[$participantID]['contact_id']}&context=home"
180 if (CRM_Core_Permission
::check('delete in CiviEvent')) {
181 $recentOther['deleteUrl'] = CRM_Utils_System
::url('civicrm/contact/view/participant',
182 "action=delete&reset=1&id={$values[$participantID]['id']}&cid={$values[$participantID]['contact_id']}&context=home"
186 $participantRoles = CRM_Event_PseudoConstant
::participantRole();
187 $displayName = CRM_Contact_BAO_Contact
::displayName($values[$participantID]['contact_id']);
189 $participantCount = [];
190 $invoiceSettings = Civi
::settings()->get('contribution_invoice_settings');
191 $invoicing = $invoiceSettings['invoicing'] ??
NULL;
193 foreach ($lineItem as $k => $v) {
194 if (CRM_Utils_Array
::value('participant_count', $lineItem[$k]) > 0) {
195 $participantCount[] = $lineItem[$k]['participant_count'];
197 $totalTaxAmount = $v['tax_amount'] +
$totalTaxAmount;
200 $this->assign('totalTaxAmount', $totalTaxAmount);
202 if ($participantCount) {
203 $this->assign('pricesetFieldsCount', $participantCount);
205 $this->assign('displayName', $displayName);
206 // omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container
207 CRM_Utils_System
::setTitle(ts('View Event Registration for') . ' ' . $displayName);
209 $roleId = $values[$participantID]['role_id'] ??
NULL;
210 $title = $displayName . ' (' . CRM_Utils_Array
::value($roleId, $participantRoles) . ' - ' . $eventTitle . ')';
212 $sep = CRM_Core_DAO
::VALUE_SEPARATOR
;
214 foreach (explode($sep, $values[$participantID]['role_id']) as $k => $v) {
215 $viewRoles[] = $participantRoles[$v];
217 $values[$participantID]['role_id'] = implode(', ', $viewRoles);
218 $this->assign('role', $values[$participantID]['role_id']);
219 // add Participant to Recent Items
220 CRM_Utils_Recent
::add($title,
222 $values[$participantID]['id'],
224 $values[$participantID]['contact_id'],
231 * Build the form object.
235 public function buildQuickForm() {
239 'name' => ts('Done'),
240 'spacing' => ' ',