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