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