CRM-20091 - Add customValue.gettree api
[civicrm-core.git] / CRM / Event / Form / ParticipantView.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
7e9e8871 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
0f03f337 6 | Copyright CiviCRM LLC (c) 2004-2017 |
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 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
27
28/**
29 *
30 * @package CRM
0f03f337 31 * @copyright CiviCRM LLC (c) 2004-2017
6a488035
TO
32 * $Id$
33 *
34 */
35
36/**
37 * This class generates form components for Participant
38 *
39 */
40class CRM_Event_Form_ParticipantView extends CRM_Core_Form {
41
96f50de2
CW
42 public $useLivePageJS = TRUE;
43
6a488035 44 /**
fe482240 45 * Set variables up before form is built.
6a488035
TO
46 *
47 * @return void
6a488035
TO
48 */
49 public function preProcess() {
353ffa53 50 $values = $ids = array();
6a488035 51 $participantID = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
353ffa53
TO
52 $contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
53 $params = array('id' => $participantID);
6a488035
TO
54
55 CRM_Event_BAO_Participant::getValues($params,
56 $values,
57 $ids
58 );
59
60 if (empty($values)) {
61 CRM_Core_Error::statusBounce(ts('The requested participant record does not exist (possibly the record was deleted).'));
62 }
63
64 CRM_Event_BAO_Participant::resolveDefaults($values[$participantID]);
65
a7488080 66 if (!empty($values[$participantID]['fee_level'])) {
6a488035
TO
67 CRM_Event_BAO_Participant::fixEventLevel($values[$participantID]['fee_level']);
68 }
69
fbc54416
PJ
70 $this->assign('contactId', $contactID);
71 $this->assign('participantId', $participantID);
0b2b58ea
PJ
72
73 $paymentId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment',
74 $participantID, 'id', 'participant_id'
75 );
76 $this->assign('hasPayment', $paymentId);
685dc433
PN
77 $this->assign('componentId', $participantID);
78 $this->assign('component', 'event');
0b2b58ea 79
28e4e707 80 if ($parentParticipantId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant',
353ffa53
TO
81 $participantID, 'registered_by_id'
82 )
83 ) {
28e4e707
PJ
84 $parentHasPayment = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment',
85 $parentParticipantId, 'id', 'participant_id'
86 );
87 $this->assign('parentHasPayment', $parentHasPayment);
88 }
89
fbc54416 90 $statusId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_Participant', $participantID, 'status_id', 'id');
97d8187a
DG
91 $status = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_ParticipantStatusType', $statusId, 'name', 'id');
92 $status = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_ParticipantStatusType', $statusId, 'name', 'id');
93 if ($status == 'Transferred') {
94 $transferId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_Participant', $participantID, 'transferred_to_contact_id', 'id');
95 $pid = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_Participant', $transferId, 'id', 'contact_id');
96 $transferName = current(CRM_Contact_BAO_Contact::getContactDetails($transferId));
97 $this->assign('pid', $pid);
98 $this->assign('transferId', $transferId);
99 $this->assign('transferName', $transferName);
100 }
fbc54416 101 $participantStatuses = CRM_Event_PseudoConstant::participantStatus();
fbc54416 102
6a488035
TO
103 if ($values[$participantID]['is_test']) {
104 $values[$participantID]['status'] .= ' (test) ';
105 }
106
107 // Get Note
108 $noteValue = CRM_Core_BAO_Note::getNote($participantID, 'civicrm_participant');
109
110 $values[$participantID]['note'] = array_values($noteValue);
111
6a488035
TO
112 // Get Line Items
113 $lineItem = CRM_Price_BAO_LineItem::getLineItems($participantID);
114
115 if (!CRM_Utils_System::isNull($lineItem)) {
116 $values[$participantID]['lineItem'][] = $lineItem;
117 }
118
119 $values[$participantID]['totalAmount'] = CRM_Utils_Array::value('fee_amount', $values[$participantID]);
120
121 // Get registered_by contact ID and display_name if participant was registered by someone else (CRM-4859)
a7488080 122 if (!empty($values[$participantID]['participant_registered_by_id'])) {
6a488035
TO
123 $values[$participantID]['registered_by_contact_id'] = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Participant",
124 $values[$participantID]['participant_registered_by_id'],
125 'contact_id', 'id'
126 );
127 $values[$participantID]['registered_by_display_name'] = CRM_Contact_BAO_Contact::displayName($values[$participantID]['registered_by_contact_id']);
128 }
129
130 // Check if this is a primaryParticipant (registered for others) and retrieve additional participants if true (CRM-4859)
131 if (CRM_Event_BAO_Participant::isPrimaryParticipant($participantID)) {
132 $values[$participantID]['additionalParticipants'] = CRM_Event_BAO_Participant::getAdditionalParticipants($participantID);
133 }
134
135 // get the option value for custom data type
c460c196
PN
136 $customDataType = CRM_Core_OptionGroup::values('custom_data_type', FALSE, FALSE, FALSE, NULL, 'name');
137 $roleCustomDataTypeID = array_search('ParticipantRole', $customDataType);
138 $eventNameCustomDataTypeID = array_search('ParticipantEventName', $customDataType);
139 $eventTypeCustomDataTypeID = array_search('ParticipantEventType', $customDataType);
6a488035
TO
140 $allRoleIDs = explode(CRM_Core_DAO::VALUE_SEPARATOR, $values[$participantID]['role_id']);
141 $groupTree = array();
142 $finalTree = array();
143
144 foreach ($allRoleIDs as $k => $v) {
145 $roleGroupTree = CRM_Core_BAO_CustomGroup::getTree('Participant', $this, $participantID, NULL, $v, $roleCustomDataTypeID);
517755e0 146 $eventGroupTree = CRM_Core_BAO_CustomGroup::getTree('Participant', $this, $participantID, NULL,
6a488035
TO
147 $values[$participantID]['event_id'], $eventNameCustomDataTypeID
148 );
353ffa53 149 $eventTypeID = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Event", $values[$participantID]['event_id'], 'event_type_id', 'id');
6a488035 150 $eventTypeGroupTree = CRM_Core_BAO_CustomGroup::getTree('Participant', $this, $participantID, NULL, $eventTypeID, $eventTypeCustomDataTypeID);
353ffa53
TO
151 $groupTree = CRM_Utils_Array::crmArrayMerge($roleGroupTree, $eventGroupTree);
152 $groupTree = CRM_Utils_Array::crmArrayMerge($groupTree, $eventTypeGroupTree);
153 $groupTree = CRM_Utils_Array::crmArrayMerge($groupTree, CRM_Core_BAO_CustomGroup::getTree('Participant', $this, $participantID));
6a488035
TO
154 foreach ($groupTree as $treeId => $trees) {
155 $finalTree[$treeId] = $trees;
156 }
157 }
e34e6979 158 CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $finalTree, FALSE, NULL, NULL, NULL, $participantID);
6a488035
TO
159 $eventTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $values[$participantID]['event_id'], 'title');
160 //CRM-7150, show event name on participant view even if the event is disabled
a7488080 161 if (empty($values[$participantID]['event'])) {
6a488035
TO
162 $values[$participantID]['event'] = $eventTitle;
163 }
164
165 //do check for campaigns
166 if ($campaignId = CRM_Utils_Array::value('campaign_id', $values[$participantID])) {
167 $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId);
168 $values[$participantID]['campaign'] = $campaigns[$campaignId];
169 }
170
171 $this->assign($values[$participantID]);
172
173 // add viewed participant to recent items list
174 $url = CRM_Utils_System::url('civicrm/contact/view/participant',
175 "action=view&reset=1&id={$values[$participantID]['id']}&cid={$values[$participantID]['contact_id']}&context=home"
176 );
177
178 $recentOther = array();
179 if (CRM_Core_Permission::check('edit event participants')) {
180 $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/participant',
181 "action=update&reset=1&id={$values[$participantID]['id']}&cid={$values[$participantID]['contact_id']}&context=home"
182 );
183 }
184 if (CRM_Core_Permission::check('delete in CiviEvent')) {
185 $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/participant',
186 "action=delete&reset=1&id={$values[$participantID]['id']}&cid={$values[$participantID]['contact_id']}&context=home"
187 );
188 }
189
190 $participantRoles = CRM_Event_PseudoConstant::participantRole();
191 $displayName = CRM_Contact_BAO_Contact::displayName($values[$participantID]['contact_id']);
192
193 $participantCount = array();
aaffa79f 194 $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
03b412ae 195 $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
a32709be 196 $totalTaxAmount = 0;
6a488035
TO
197 foreach ($lineItem as $k => $v) {
198 if (CRM_Utils_Array::value('participant_count', $lineItem[$k]) > 0) {
aa4bb8d2 199 $participantCount[] = $lineItem[$k]['participant_count'];
6a488035 200 }
a32709be 201 $totalTaxAmount = $v['tax_amount'] + $totalTaxAmount;
6a488035 202 }
03b412ae
PB
203 if ($invoicing) {
204 $this->assign('totalTaxAmount', $totalTaxAmount);
205 }
6a488035
TO
206 if ($participantCount) {
207 $this->assign('pricesetFieldsCount', $participantCount);
208 }
209 $this->assign('displayName', $displayName);
210 // omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container
86bfa4f6 211 CRM_Utils_System::setTitle(ts('View Event Registration for') . ' ' . $displayName);
6a488035
TO
212
213 $roleId = CRM_Utils_Array::value('role_id', $values[$participantID]);
214 $title = $displayName . ' (' . CRM_Utils_Array::value($roleId, $participantRoles) . ' - ' . $eventTitle . ')';
215
216 $sep = CRM_Core_DAO::VALUE_SEPARATOR;
217 $viewRoles = array();
218 foreach (explode($sep, $values[$participantID]['role_id']) as $k => $v) {
219 $viewRoles[] = $participantRoles[$v];
220 }
221 $values[$participantID]['role_id'] = implode(', ', $viewRoles);
222 $this->assign('role', $values[$participantID]['role_id']);
223 // add Participant to Recent Items
224 CRM_Utils_Recent::add($title,
225 $url,
226 $values[$participantID]['id'],
227 'Participant',
228 $values[$participantID]['contact_id'],
229 NULL,
230 $recentOther
231 );
232 }
233
234 /**
fe482240 235 * Build the form object.
6a488035 236 *
355ba699 237 * @return void
6a488035
TO
238 */
239 public function buildQuickForm() {
240 $this->addButtons(array(
241 array(
242 'type' => 'cancel',
243 'name' => ts('Done'),
244 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
245 'isDefault' => TRUE,
246 ),
247 )
248 );
249 }
96025800 250
6a488035 251}