INFRA-132 - CRM/Event - phpcbf
[civicrm-core.git] / CRM / Event / Form / ParticipantView.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
6a488035 5 +--------------------------------------------------------------------+
06b69b18 6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 +--------------------------------------------------------------------+
26*/
27
28/**
29 *
30 * @package CRM
06b69b18 31 * @copyright CiviCRM LLC (c) 2004-2014
6a488035
TO
32 * $Id$
33 *
34 */
35
36/**
37 * This class generates form components for Participant
38 *
39 */
40class CRM_Event_Form_ParticipantView extends CRM_Core_Form {
41
96f50de2
CW
42 public $useLivePageJS = TRUE;
43
6a488035 44 /**
100fef9d 45 * Set variables up before form is built
6a488035
TO
46 *
47 * @return void
6a488035
TO
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
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);
77
28e4e707
PJ
78 if ($parentParticipantId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant',
79 $participantID, 'registered_by_id'
80 )) {
81 $parentHasPayment = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment',
82 $parentParticipantId, 'id', 'participant_id'
83 );
84 $this->assign('parentHasPayment', $parentHasPayment);
85 }
86
fbc54416
PJ
87 $statusId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_Participant', $participantID, 'status_id', 'id');
88 $participantStatuses = CRM_Event_PseudoConstant::participantStatus();
fbc54416 89
6a488035
TO
90 if ($values[$participantID]['is_test']) {
91 $values[$participantID]['status'] .= ' (test) ';
92 }
93
94 // Get Note
95 $noteValue = CRM_Core_BAO_Note::getNote($participantID, 'civicrm_participant');
96
97 $values[$participantID]['note'] = array_values($noteValue);
98
6a488035
TO
99 // Get Line Items
100 $lineItem = CRM_Price_BAO_LineItem::getLineItems($participantID);
101
102 if (!CRM_Utils_System::isNull($lineItem)) {
103 $values[$participantID]['lineItem'][] = $lineItem;
104 }
105
106 $values[$participantID]['totalAmount'] = CRM_Utils_Array::value('fee_amount', $values[$participantID]);
107
108 // Get registered_by contact ID and display_name if participant was registered by someone else (CRM-4859)
a7488080 109 if (!empty($values[$participantID]['participant_registered_by_id'])) {
6a488035
TO
110 $values[$participantID]['registered_by_contact_id'] = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Participant",
111 $values[$participantID]['participant_registered_by_id'],
112 'contact_id', 'id'
113 );
114 $values[$participantID]['registered_by_display_name'] = CRM_Contact_BAO_Contact::displayName($values[$participantID]['registered_by_contact_id']);
115 }
116
117 // Check if this is a primaryParticipant (registered for others) and retrieve additional participants if true (CRM-4859)
118 if (CRM_Event_BAO_Participant::isPrimaryParticipant($participantID)) {
119 $values[$participantID]['additionalParticipants'] = CRM_Event_BAO_Participant::getAdditionalParticipants($participantID);
120 }
121
122 // get the option value for custom data type
123 $roleCustomDataTypeID = CRM_Core_OptionGroup::getValue('custom_data_type', 'ParticipantRole', 'name');
124 $eventNameCustomDataTypeID = CRM_Core_OptionGroup::getValue('custom_data_type', 'ParticipantEventName', 'name');
125 $eventTypeCustomDataTypeID = CRM_Core_OptionGroup::getValue('custom_data_type', 'ParticipantEventType', 'name');
126 $allRoleIDs = explode(CRM_Core_DAO::VALUE_SEPARATOR, $values[$participantID]['role_id']);
127 $groupTree = array();
128 $finalTree = array();
129
130 foreach ($allRoleIDs as $k => $v) {
131 $roleGroupTree = CRM_Core_BAO_CustomGroup::getTree('Participant', $this, $participantID, NULL, $v, $roleCustomDataTypeID);
132 $eventGroupTree = &CRM_Core_BAO_CustomGroup::getTree('Participant', $this, $participantID, NULL,
133 $values[$participantID]['event_id'], $eventNameCustomDataTypeID
134 );
135 $eventTypeID = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Event", $values[$participantID]['event_id'], 'event_type_id', 'id');
136 $eventTypeGroupTree = CRM_Core_BAO_CustomGroup::getTree('Participant', $this, $participantID, NULL, $eventTypeID, $eventTypeCustomDataTypeID);
137 $groupTree = CRM_Utils_Array::crmArrayMerge($roleGroupTree, $eventGroupTree);
138 $groupTree = CRM_Utils_Array::crmArrayMerge($groupTree, $eventTypeGroupTree);
139 $groupTree = CRM_Utils_Array::crmArrayMerge($groupTree, CRM_Core_BAO_CustomGroup::getTree('Participant', $this, $participantID));
140 foreach ($groupTree as $treeId => $trees) {
141 $finalTree[$treeId] = $trees;
142 }
143 }
144 CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $finalTree);
145 $eventTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $values[$participantID]['event_id'], 'title');
146 //CRM-7150, show event name on participant view even if the event is disabled
a7488080 147 if (empty($values[$participantID]['event'])) {
6a488035
TO
148 $values[$participantID]['event'] = $eventTitle;
149 }
150
151 //do check for campaigns
152 if ($campaignId = CRM_Utils_Array::value('campaign_id', $values[$participantID])) {
153 $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId);
154 $values[$participantID]['campaign'] = $campaigns[$campaignId];
155 }
156
157 $this->assign($values[$participantID]);
158
159 // add viewed participant to recent items list
160 $url = CRM_Utils_System::url('civicrm/contact/view/participant',
161 "action=view&reset=1&id={$values[$participantID]['id']}&cid={$values[$participantID]['contact_id']}&context=home"
162 );
163
164 $recentOther = array();
165 if (CRM_Core_Permission::check('edit event participants')) {
166 $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/participant',
167 "action=update&reset=1&id={$values[$participantID]['id']}&cid={$values[$participantID]['contact_id']}&context=home"
168 );
169 }
170 if (CRM_Core_Permission::check('delete in CiviEvent')) {
171 $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/participant',
172 "action=delete&reset=1&id={$values[$participantID]['id']}&cid={$values[$participantID]['contact_id']}&context=home"
173 );
174 }
175
176 $participantRoles = CRM_Event_PseudoConstant::participantRole();
177 $displayName = CRM_Contact_BAO_Contact::displayName($values[$participantID]['contact_id']);
178
179 $participantCount = array();
0479b4c8 180 $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
03b412ae 181 $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
a32709be 182 $totalTaxAmount = 0;
6a488035
TO
183 foreach ($lineItem as $k => $v) {
184 if (CRM_Utils_Array::value('participant_count', $lineItem[$k]) > 0) {
aa4bb8d2 185 $participantCount[] = $lineItem[$k]['participant_count'];
6a488035 186 }
a32709be 187 $totalTaxAmount = $v['tax_amount'] + $totalTaxAmount;
6a488035 188 }
03b412ae
PB
189 if ($invoicing) {
190 $this->assign('totalTaxAmount', $totalTaxAmount);
191 }
6a488035
TO
192 if ($participantCount) {
193 $this->assign('pricesetFieldsCount', $participantCount);
194 }
195 $this->assign('displayName', $displayName);
196 // omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container
197 CRM_Utils_System::setTitle(ts('View Event Registration for') . ' ' . $displayName);
198
199 $roleId = CRM_Utils_Array::value('role_id', $values[$participantID]);
200 $title = $displayName . ' (' . CRM_Utils_Array::value($roleId, $participantRoles) . ' - ' . $eventTitle . ')';
201
202 $sep = CRM_Core_DAO::VALUE_SEPARATOR;
203 $viewRoles = array();
204 foreach (explode($sep, $values[$participantID]['role_id']) as $k => $v) {
205 $viewRoles[] = $participantRoles[$v];
206 }
207 $values[$participantID]['role_id'] = implode(', ', $viewRoles);
208 $this->assign('role', $values[$participantID]['role_id']);
209 // add Participant to Recent Items
210 CRM_Utils_Recent::add($title,
211 $url,
212 $values[$participantID]['id'],
213 'Participant',
214 $values[$participantID]['contact_id'],
215 NULL,
216 $recentOther
217 );
218 }
219
220 /**
c490a46a 221 * Build the form object
6a488035 222 *
355ba699 223 * @return void
6a488035
TO
224 */
225 public function buildQuickForm() {
226 $this->addButtons(array(
227 array(
228 'type' => 'cancel',
229 'name' => ts('Done'),
230 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
231 'isDefault' => TRUE,
232 ),
233 )
234 );
235 }
236}