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