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