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