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