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