Commit | Line | Data |
---|---|---|
97d8187a DG |
1 | <?php |
2 | ||
3 | /* | |
4 | +--------------------------------------------------------------------+ | |
fee14197 | 5 | | CiviCRM version 5 | |
97d8187a | 6 | +--------------------------------------------------------------------+ |
6b83d5bd | 7 | | Copyright CiviCRM LLC (c) 2004-2019 | |
97d8187a DG |
8 | +--------------------------------------------------------------------+ |
9 | | This file is a part of CiviCRM. | | |
10 | | | | |
11 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
12 | | under the terms of the GNU Affero General Public License | | |
13 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
14 | | | | |
15 | | CiviCRM is distributed in the hope that it will be useful, but | | |
16 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
17 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
18 | | See the GNU Affero General Public License for more details. | | |
19 | | | | |
20 | | You should have received a copy of the GNU Affero General Public | | |
21 | | License and the CiviCRM Licensing Exception along | | |
22 | | with this program; if not, contact CiviCRM LLC | | |
23 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
24 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
25 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
26 | +--------------------------------------------------------------------+ | |
27 | */ | |
28 | ||
29 | /** | |
30 | * | |
31 | * @package CRM | |
6b83d5bd | 32 | * @copyright CiviCRM LLC (c) 2004-2019 |
97d8187a DG |
33 | * $Id$ |
34 | * | |
35 | */ | |
36 | ||
37 | /** | |
38 | * This class generates form components to transfer an Event to another participant | |
39 | * | |
40 | */ | |
41 | class CRM_Event_Form_SelfSvcTransfer extends CRM_Core_Form { | |
42 | /** | |
43 | * from particpant id | |
44 | * | |
45 | * @var string | |
46 | * | |
47 | */ | |
48 | protected $_from_participant_id; | |
49 | /** | |
50 | * from contact id | |
51 | * | |
52 | * @var string | |
53 | * | |
54 | */ | |
55 | protected $_from_contact_id; | |
56 | /** | |
57 | * last name of the particpant to transfer to | |
58 | * | |
59 | * @var string | |
60 | * | |
61 | */ | |
62 | protected $_to_contact_last_name; | |
63 | /** | |
64 | * first name of the particpant to transfer to | |
65 | * | |
66 | * @var string | |
67 | * | |
68 | */ | |
69 | protected $_to_contact_first_name; | |
70 | /** | |
71 | * email of participant | |
72 | * | |
73 | * | |
74 | * @var string | |
75 | */ | |
76 | protected $_to_contact_email; | |
77 | /** | |
78 | * _to_contact_id | |
79 | * | |
80 | * @var string | |
81 | */ | |
82 | protected $_to_contact_id; | |
83 | /** | |
84 | * event to be cancelled/transferred | |
85 | * | |
86 | * @var string | |
87 | */ | |
88 | protected $_event_id; | |
89 | /** | |
90 | * event title | |
91 | * | |
92 | * @var string | |
93 | */ | |
94 | protected $_event_title; | |
95 | /** | |
96 | * event title | |
97 | * | |
98 | * @var string | |
99 | */ | |
100 | protected $_event_start_date; | |
101 | /** | |
102 | * action | |
103 | * | |
104 | * @var string | |
105 | */ | |
3a936dab | 106 | public $_action; |
97d8187a DG |
107 | /** |
108 | * participant object | |
109 | * | |
110 | * @var string | |
111 | */ | |
be2fb01f | 112 | protected $_participant = []; |
97d8187a DG |
113 | /** |
114 | * particpant values | |
115 | * | |
90b461f1 | 116 | * @var string |
97d8187a DG |
117 | */ |
118 | protected $_part_values; | |
119 | /** | |
120 | * details | |
121 | * | |
90b461f1 | 122 | * @var array |
97d8187a | 123 | */ |
be2fb01f | 124 | protected $_details = []; |
97d8187a DG |
125 | /** |
126 | * line items | |
127 | * | |
90b461f1 | 128 | * @var array |
97d8187a | 129 | */ |
be2fb01f | 130 | protected $_line_items = []; |
97d8187a DG |
131 | /** |
132 | * contact_id | |
133 | * | |
90b461f1 | 134 | * @var int |
97d8187a DG |
135 | */ |
136 | protected $contact_id; | |
974bdb44 | 137 | |
e219d53b | 138 | /** |
139 | * Is backoffice form? | |
140 | * | |
90b461f1 | 141 | * @var bool |
e219d53b | 142 | */ |
143 | protected $isBackoffice = FALSE; | |
144 | ||
97d8187a DG |
145 | /** |
146 | * Get source values for transfer based on participant id in URL. Line items will | |
147 | * be transferred to this participant - at this point no transaction changes processed | |
148 | * | |
149 | * return @void | |
150 | */ | |
151 | public function preProcess() { | |
152 | $config = CRM_Core_Config::singleton(); | |
153 | $session = CRM_Core_Session::singleton(); | |
154 | $this->_userContext = $session->readUserContext(); | |
155 | $this->_from_participant_id = CRM_Utils_Request::retrieve('pid', 'Positive', $this, FALSE, NULL, 'REQUEST'); | |
af29aaac | 156 | $this->_userChecksum = CRM_Utils_Request::retrieve('cs', 'String', $this, FALSE, NULL, 'REQUEST'); |
e219d53b | 157 | $this->isBackoffice = CRM_Utils_Request::retrieve('is_backoffice', 'String', $this, FALSE, NULL, 'REQUEST'); |
be2fb01f CW |
158 | $params = ['id' => $this->_from_participant_id]; |
159 | $participant = $values = []; | |
97d8187a DG |
160 | $this->_participant = CRM_Event_BAO_Participant::getValues($params, $values, $participant); |
161 | $this->_part_values = $values[$this->_from_participant_id]; | |
162 | $this->set('values', $this->_part_values); | |
163 | $this->_event_id = $this->_part_values['event_id']; | |
af29aaac | 164 | $url = CRM_Utils_System::url('civicrm/event/info', "reset=1&id={$this->_event_id}"); |
97d8187a | 165 | $this->_from_contact_id = $this->_part_values['participant_contact_id']; |
af29aaac | 166 | $validUser = CRM_Contact_BAO_Contact_Utils::validChecksum($this->_from_contact_id, $this->_userChecksum); |
167 | if (!$validUser && !CRM_Core_Permission::check('edit all events')) { | |
168 | CRM_Core_Error::statusBounce(ts('You do not have sufficient permission to transfer/cancel this participant.'), $url); | |
169 | } | |
97d8187a DG |
170 | $this->assign('action', $this->_action); |
171 | if ($this->_from_participant_id) { | |
172 | $this->assign('participantId', $this->_from_participant_id); | |
173 | } | |
be2fb01f | 174 | $event = []; |
97d8187a DG |
175 | $daoName = 'title'; |
176 | $this->_event_title = CRM_Event_BAO_Event::getFieldValue('CRM_Event_DAO_Event', $this->_event_id, $daoName); | |
177 | $daoName = 'start_date'; | |
178 | $this->_event_start_date = CRM_Event_BAO_Event::getFieldValue('CRM_Event_DAO_Event', $this->_event_id, $daoName); | |
179 | list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_from_contact_id); | |
180 | $this->_contact_name = $displayName; | |
181 | $this->_contact_email = $email; | |
be2fb01f | 182 | $details = []; |
97d8187a | 183 | $details = CRM_Event_BAO_Participant::participantDetails($this->_from_participant_id); |
4abc4ee1 | 184 | $optionGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'participant_role', 'id', 'name'); |
97d8187a | 185 | $query = " |
974bdb44 | 186 | SELECT cpst.name as status, cov.name as role, cp.fee_level, cp.fee_amount, cp.register_date, civicrm_event.start_date |
97d8187a DG |
187 | FROM civicrm_participant cp |
188 | LEFT JOIN civicrm_participant_status_type cpst ON cpst.id = cp.status_id | |
4abc4ee1 | 189 | LEFT JOIN civicrm_option_value cov ON cov.value = cp.role_id and cov.option_group_id = {$optionGroupId} |
974bdb44 | 190 | LEFT JOIN civicrm_event ON civicrm_event.id = cp.event_id |
97d8187a | 191 | WHERE cp.id = {$this->_from_participant_id}"; |
33621c4f | 192 | $dao = CRM_Core_DAO::executeQuery($query); |
97d8187a DG |
193 | while ($dao->fetch()) { |
194 | $details['status'] = $dao->status; | |
195 | $details['role'] = $dao->role; | |
196 | $details['fee_level'] = $dao->fee_level; | |
197 | $details['fee_amount'] = $dao->fee_amount; | |
198 | $details['register_date'] = $dao->register_date; | |
0d21c8b1 | 199 | $details['event_start_date'] = $dao->start_date; |
97d8187a DG |
200 | } |
201 | $this->assign('details', $details); | |
202 | //This participant row will be cancelled. Get line item(s) to cancel | |
203 | $this->selfsvctransferUrl = CRM_Utils_System::url('civicrm/event/selfsvcupdate', | |
204 | "reset=1&id={$this->_from_participant_id}&id=0"); | |
205 | $this->selfsvctransferText = ts('Update'); | |
206 | $this->selfsvctransferButtonText = ts('Update'); | |
207 | } | |
974bdb44 | 208 | |
97d8187a DG |
209 | /** |
210 | * Build form for input of transferree email, name | |
211 | * | |
212 | * return @void | |
213 | */ | |
214 | public function buildQuickForm() { | |
e219d53b | 215 | // use entityRef select field for contact when this form is used by staff/admin user |
216 | if ($this->isBackoffice) { | |
be2fb01f | 217 | $this->addEntityRef("contact_id", ts('Select Contact'), ['create' => TRUE], TRUE); |
e219d53b | 218 | } |
219 | // for front-end user show and use the basic three fields used to create a contact | |
220 | else { | |
6dabf459 ML |
221 | $this->add('text', 'email', ts('To Email'), $this->_contact_email, TRUE); |
222 | $this->add('text', 'last_name', ts('To Last Name'), $this->_to_contact_last_name, TRUE); | |
223 | $this->add('text', 'first_name', ts('To First Name'), $this->_to_contact_first_name, TRUE); | |
e219d53b | 224 | } |
225 | ||
be2fb01f CW |
226 | $this->addButtons([ |
227 | [ | |
97d8187a | 228 | 'type' => 'submit', |
be2fb01f CW |
229 | 'name' => ts('Transfer Registration'), |
230 | ], | |
231 | ]); | |
232 | $this->addFormRule(['CRM_Event_Form_SelfSvcTransfer', 'formRule'], $this); | |
97d8187a DG |
233 | parent::buildQuickForm(); |
234 | } | |
974bdb44 | 235 | |
97d8187a DG |
236 | /** |
237 | * Set defaults | |
238 | * | |
239 | * return @array _defaults | |
240 | */ | |
241 | public function setDefaultValues() { | |
be2fb01f | 242 | $this->_defaults = []; |
97d8187a DG |
243 | return $this->_defaults; |
244 | } | |
974bdb44 | 245 | |
97d8187a DG |
246 | /** |
247 | * Validate email and name input | |
248 | * | |
249 | * return array $errors | |
250 | */ | |
251 | public static function formRule($fields, $files, $self) { | |
be2fb01f | 252 | $errors = []; |
e219d53b | 253 | if (!empty($fields['contact_id'])) { |
254 | $to_contact_id = $fields['contact_id']; | |
255 | } | |
256 | else { | |
257 | //check that either an email or firstname+lastname is included in the form(CRM-9587) | |
258 | $to_contact_id = self::checkProfileComplete($fields, $errors, $self); | |
259 | } | |
97d8187a | 260 | //To check if the user is already registered for the event(CRM-2426) |
e219d53b | 261 | if (!empty($to_contact_id)) { |
e3b510fe | 262 | self::checkRegistration($fields, $self, $to_contact_id, $errors); |
263 | } | |
97d8187a DG |
264 | //return parent::formrule($fields, $files, $self); |
265 | return empty($errors) ? TRUE : $errors; | |
266 | } | |
974bdb44 | 267 | |
97d8187a DG |
268 | /** |
269 | * Check whether profile (name, email) is complete | |
270 | * | |
271 | * return $contact_id | |
272 | */ | |
273 | public static function checkProfileComplete($fields, &$errors, $self) { | |
274 | $email = ''; | |
275 | foreach ($fields as $fieldname => $fieldvalue) { | |
276 | if (substr($fieldname, 0, 5) == 'email' && $fieldvalue) { | |
277 | $email = $fieldvalue; | |
278 | } | |
279 | } | |
280 | if (!$email && !(CRM_Utils_Array::value('first_name', $fields) && | |
281 | CRM_Utils_Array::value('last_name', $fields))) { | |
be2fb01f | 282 | $defaults = $params = ['id' => $eventId]; |
97d8187a DG |
283 | CRM_Event_BAO_Event::retrieve($params, $defaults); |
284 | $message = ts("Mandatory fields (first name and last name, OR email address) are missing from this form."); | |
285 | $errors['_qf_default'] = $message; | |
286 | } | |
287 | $contact = CRM_Contact_BAO_Contact::matchContactOnEmail($email, ""); | |
288 | $contact_id = empty($contact->contact_id) ? NULL : $contact->contact_id; | |
e3b510fe | 289 | if (!CRM_Utils_Rule::email($fields['email'])) { |
290 | $errors['email'] = ts('Enter valid email address.'); | |
291 | } | |
292 | if (empty($errors) && empty($contact_id)) { | |
be2fb01f | 293 | $params = [ |
97d8187a DG |
294 | 'email-Primary' => CRM_Utils_Array::value('email', $fields, NULL), |
295 | 'first_name' => CRM_Utils_Array::value('first_name', $fields, NULL), | |
296 | 'last_name' => CRM_Utils_Array::value('last_name', $fields, NULL), | |
be2fb01f CW |
297 | 'is_deleted' => CRM_Utils_Array::value('is_deleted', $fields, FALSE), |
298 | ]; | |
97d8187a DG |
299 | //create new contact for this name/email pair |
300 | //if new contact, no need to check for contact already registered | |
301 | $contact_id = CRM_Contact_BAO_Contact::createProfileContact($params, $fields, $contact_id); | |
302 | } | |
303 | return $contact_id; | |
304 | } | |
974bdb44 | 305 | |
97d8187a DG |
306 | /** |
307 | * Check contact details | |
308 | * | |
309 | * return @void | |
310 | */ | |
4abc4ee1 | 311 | public static function checkRegistration($fields, $self, $contact_id, &$errors) { |
97d8187a | 312 | // verify whether this contact already registered for this event |
97d8187a DG |
313 | $contact_details = CRM_Contact_BAO_Contact::getContactDetails($contact_id); |
314 | $display_name = $contact_details[0]; | |
315 | $query = "select event_id from civicrm_participant where contact_id = " . $contact_id; | |
33621c4f | 316 | $dao = CRM_Core_DAO::executeQuery($query); |
97d8187a | 317 | while ($dao->fetch()) { |
90b461f1 | 318 | $to_event_id[] = $dao->event_id; |
97d8187a DG |
319 | } |
320 | if (!empty($to_event_id)) { | |
321 | foreach ($to_event_id as $id) { | |
322 | if ($id == $self->_event_id) { | |
4abc4ee1 | 323 | $errors['email'] = $display_name . ts(" is already registered for this event"); |
97d8187a DG |
324 | } |
325 | } | |
326 | } | |
327 | } | |
974bdb44 | 328 | |
97d8187a DG |
329 | /** |
330 | * Process transfer - first add the new participant to the event, then cancel | |
331 | * source participant - send confirmation email to transferee | |
332 | */ | |
333 | public function postProcess() { | |
334 | //For transfer, process form to allow selection of transferree | |
335 | $params = $this->controller->exportValues($this->_name); | |
e219d53b | 336 | if (!empty($params['contact_id'])) { |
337 | $contact_id = $params['contact_id']; | |
338 | } | |
339 | else { | |
340 | //cancel 'from' participant row | |
be2fb01f | 341 | $contact_id_result = civicrm_api3('Contact', 'get', [ |
d4a64d9a | 342 | 'sequential' => 1, |
be2fb01f | 343 | 'return' => ["id"], |
d4a64d9a | 344 | 'email' => $params['email'], |
be2fb01f CW |
345 | 'options' => ['limit' => 1], |
346 | ]); | |
d4a64d9a AS |
347 | $contact_id_result = $contact_id_result['values'][0]; |
348 | $contact_id = $contact_id_result['contact_id']; | |
349 | $contact_is_deleted = $contact_id_result['contact_is_deleted']; | |
350 | if ($contact_is_deleted || !is_numeric($contact_id)) { | |
2ddf0fcd | 351 | CRM_Core_Error::statusBounce(ts('Contact does not exist.')); |
e219d53b | 352 | } |
97d8187a | 353 | } |
be2fb01f | 354 | $from_participant = $params = []; |
97d8187a | 355 | $query = "select role_id, source, fee_level, is_test, is_pay_later, fee_amount, discount_id, fee_currency,campaign_id, discount_amount from civicrm_participant where id = " . $this->_from_participant_id; |
33621c4f | 356 | $dao = CRM_Core_DAO::executeQuery($query); |
be2fb01f | 357 | $value_to = []; |
97d8187a DG |
358 | while ($dao->fetch()) { |
359 | $value_to['role_id'] = $dao->role_id; | |
360 | $value_to['source'] = $dao->source; | |
361 | $value_to['fee_level'] = $dao->fee_level; | |
362 | $value_to['is_test'] = $dao->is_test; | |
363 | $value_to['is_pay_later'] = $dao->is_pay_later; | |
364 | $value_to['fee_amount'] = $dao->fee_amount; | |
365 | } | |
366 | $value_to['contact_id'] = $contact_id; | |
367 | $value_to['event_id'] = $this->_event_id; | |
35538401 PN |
368 | $value_to['status_id'] = CRM_Core_PseudoConstant::getKey( |
369 | 'CRM_Event_BAO_Participant', | |
370 | 'status_id', | |
371 | 'Registered' | |
372 | ); | |
97d8187a DG |
373 | $value_to['register_date'] = date("Y-m-d"); |
374 | //first create the new participant row -don't set registered_by yet or email won't be sent | |
375 | $participant = CRM_Event_BAO_Participant::create($value_to); | |
376 | //send a confirmation email to the new participant | |
e3b510fe | 377 | $this->participantTransfer($participant); |
97d8187a DG |
378 | //now update registered_by_id |
379 | $query = "UPDATE civicrm_participant cp SET cp.registered_by_id = %1 WHERE cp.id = ({$participant->id})"; | |
be2fb01f | 380 | $params = [1 => [$this->_from_participant_id, 'Integer']]; |
97d8187a DG |
381 | $dao = CRM_Core_DAO::executeQuery($query, $params); |
382 | //copy line items to new participant | |
383 | $line_items = CRM_Price_BAO_LineItem::getLineItems($this->_from_participant_id); | |
384 | foreach ($line_items as $item) { | |
385 | $item['entity_id'] = $participant->id; | |
386 | $item['id'] = NULL; | |
387 | $item['entity_table'] = "civicrm_participant"; | |
388 | $new_item = CRM_Price_BAO_LineItem::create($item); | |
389 | } | |
390 | //now cancel the from participant record, leaving the original line-item(s) | |
be2fb01f | 391 | $value_from = []; |
97d8187a DG |
392 | $value_from['id'] = $this->_from_participant_id; |
393 | $tansferId = array_search('Transferred', CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Negative'")); | |
394 | $value_from['status_id'] = $tansferId; | |
395 | $value_from['transferred_to_contact_id'] = $contact_id; | |
396 | $contact_details = CRM_Contact_BAO_Contact::getContactDetails($contact_id); | |
397 | $display_name = current($contact_details); | |
398 | $this->assign('to_participant', $display_name); | |
399 | CRM_Event_BAO_Participant::create($value_from); | |
400 | $this->sendCancellation(); | |
401 | list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contact_id); | |
be2fb01f CW |
402 | $statusMsg = ts('Event registration information for %1 has been updated.', [1 => $displayName]); |
403 | $statusMsg .= ' ' . ts('A confirmation email has been sent to %1.', [1 => $email]); | |
974bdb44 | 404 | CRM_Core_Session::setStatus($statusMsg, ts('Registration Transferred'), 'success'); |
e219d53b | 405 | if ($this->isBackoffice) { |
406 | return; | |
407 | } | |
e3b510fe | 408 | $url = CRM_Utils_System::url('civicrm/event/info', "reset=1&id={$this->_event_id}"); |
409 | CRM_Utils_System::redirect($url); | |
97d8187a | 410 | } |
974bdb44 | 411 | |
97d8187a DG |
412 | /** |
413 | * Based on input, create participant row for transferee and send email | |
414 | * | |
415 | * return @ void | |
416 | */ | |
417 | public function participantTransfer($participant) { | |
be2fb01f | 418 | $contactDetails = []; |
97d8187a DG |
419 | $contactIds[] = $participant->contact_id; |
420 | list($currentContactDetails) = CRM_Utils_Token::getTokenDetails($contactIds, NULL, | |
be2fb01f | 421 | FALSE, FALSE, NULL, [], 'CRM_Event_BAO_Participant'); |
97d8187a DG |
422 | foreach ($currentContactDetails as $contactId => $contactValues) { |
423 | $contactDetails[$contactId] = $contactValues; | |
424 | } | |
425 | $participantRoles = CRM_Event_PseudoConstant::participantRole(); | |
be2fb01f | 426 | $participantDetails = []; |
97d8187a DG |
427 | $query = "SELECT * FROM civicrm_participant WHERE id = " . $participant->id; |
428 | $dao = CRM_Core_DAO::executeQuery($query); | |
429 | while ($dao->fetch()) { | |
be2fb01f | 430 | $participantDetails[$dao->id] = [ |
97d8187a DG |
431 | 'id' => $dao->id, |
432 | 'role' => $participantRoles[$dao->role_id], | |
433 | 'is_test' => $dao->is_test, | |
434 | 'event_id' => $dao->event_id, | |
435 | 'status_id' => $dao->status_id, | |
436 | 'fee_amount' => $dao->fee_amount, | |
437 | 'contact_id' => $dao->contact_id, | |
438 | 'register_date' => $dao->register_date, | |
439 | 'registered_by_id' => $dao->registered_by_id, | |
be2fb01f | 440 | ]; |
97d8187a | 441 | } |
be2fb01f | 442 | $domainValues = []; |
97d8187a DG |
443 | if (empty($domainValues)) { |
444 | $domain = CRM_Core_BAO_Domain::getDomain(); | |
be2fb01f | 445 | $tokens = [ |
97d8187a | 446 | 'domain' => |
be2fb01f | 447 | [ |
97d8187a DG |
448 | 'name', |
449 | 'phone', | |
450 | 'address', | |
451 | 'email', | |
be2fb01f | 452 | ], |
97d8187a | 453 | 'contact' => CRM_Core_SelectValues::contactTokens(), |
be2fb01f | 454 | ]; |
97d8187a DG |
455 | foreach ($tokens['domain'] as $token) { |
456 | $domainValues[$token] = CRM_Utils_Token::getDomainTokenReplacement($token, $domain); | |
457 | } | |
458 | } | |
be2fb01f CW |
459 | $eventDetails = []; |
460 | $eventParams = ['id' => $participant->event_id]; | |
e3b510fe | 461 | CRM_Event_BAO_Event::retrieve($eventParams, $eventDetails); |
97d8187a | 462 | //get default participant role. |
e3b510fe | 463 | $eventDetails['participant_role'] = CRM_Utils_Array::value($eventDetails['default_role_id'], $participantRoles); |
97d8187a | 464 | //get the location info |
be2fb01f | 465 | $locParams = [ |
97d8187a DG |
466 | 'entity_id' => $participant->event_id, |
467 | 'entity_table' => 'civicrm_event', | |
be2fb01f | 468 | ]; |
e3b510fe | 469 | $eventDetails['location'] = CRM_Core_BAO_Location::getValues($locParams, TRUE); |
470 | $toEmail = CRM_Utils_Array::value('email', $contactDetails[$participant->contact_id]); | |
471 | if ($toEmail) { | |
472 | //take a receipt from as event else domain. | |
473 | $receiptFrom = $domainValues['name'] . ' <' . $domainValues['email'] . '>'; | |
474 | if (!empty($eventDetails['confirm_from_name']) && !empty($eventDetails['confirm_from_email'])) { | |
475 | $receiptFrom = $eventDetails['confirm_from_name'] . ' <' . $eventDetails['confirm_from_email'] . '>'; | |
476 | } | |
477 | $participantName = $contactDetails[$participant->contact_id]['display_name']; | |
be2fb01f | 478 | $tplParams = [ |
e3b510fe | 479 | 'event' => $eventDetails, |
480 | 'participant' => $participantDetails[$participant->id], | |
481 | 'participantID' => $participant->id, | |
482 | 'participant_status' => 'Registered', | |
be2fb01f | 483 | ]; |
e3b510fe | 484 | |
be2fb01f | 485 | $sendTemplateParams = [ |
e3b510fe | 486 | 'groupName' => 'msg_tpl_workflow_event', |
487 | 'valueName' => 'event_online_receipt', | |
488 | 'contactId' => $participantDetails[$participant->id]['contact_id'], | |
489 | 'tplParams' => $tplParams, | |
490 | 'from' => $receiptFrom, | |
491 | 'toName' => $participantName, | |
492 | 'toEmail' => $toEmail, | |
493 | 'cc' => CRM_Utils_Array::value('cc_confirm', $eventDetails), | |
494 | 'bcc' => CRM_Utils_Array::value('bcc_confirm', $eventDetails), | |
be2fb01f | 495 | ]; |
e3b510fe | 496 | CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams); |
497 | } | |
97d8187a | 498 | } |
974bdb44 | 499 | |
97d8187a DG |
500 | /** |
501 | * Send confirmation of cancellation to source participant | |
502 | * | |
503 | * return @ void | |
504 | */ | |
505 | public function sendCancellation() { | |
be2fb01f | 506 | $domainValues = []; |
97d8187a | 507 | $domain = CRM_Core_BAO_Domain::getDomain(); |
be2fb01f | 508 | $tokens = [ |
97d8187a | 509 | 'domain' => |
be2fb01f | 510 | [ |
97d8187a DG |
511 | 'name', |
512 | 'phone', | |
513 | 'address', | |
514 | 'email', | |
be2fb01f | 515 | ], |
97d8187a | 516 | 'contact' => CRM_Core_SelectValues::contactTokens(), |
be2fb01f | 517 | ]; |
97d8187a DG |
518 | foreach ($tokens['domain'] as $token) { |
519 | $domainValues[$token] = CRM_Utils_Token::getDomainTokenReplacement($token, $domain); | |
520 | } | |
be2fb01f | 521 | $participantRoles = []; |
97d8187a | 522 | $participantRoles = CRM_Event_PseudoConstant::participantRole(); |
be2fb01f | 523 | $participantDetails = []; |
97d8187a DG |
524 | $query = "SELECT * FROM civicrm_participant WHERE id = {$this->_from_participant_id}"; |
525 | $dao = CRM_Core_DAO::executeQuery($query); | |
526 | while ($dao->fetch()) { | |
be2fb01f | 527 | $participantDetails[$dao->id] = [ |
97d8187a DG |
528 | 'id' => $dao->id, |
529 | 'role' => $participantRoles[$dao->role_id], | |
530 | 'is_test' => $dao->is_test, | |
531 | 'event_id' => $dao->event_id, | |
532 | 'status_id' => $dao->status_id, | |
533 | 'fee_amount' => $dao->fee_amount, | |
534 | 'contact_id' => $dao->contact_id, | |
535 | 'register_date' => $dao->register_date, | |
536 | 'registered_by_id' => $dao->registered_by_id, | |
be2fb01f | 537 | ]; |
97d8187a | 538 | } |
be2fb01f CW |
539 | $eventDetails = []; |
540 | $eventParams = ['id' => $this->_event_id]; | |
97d8187a DG |
541 | CRM_Event_BAO_Event::retrieve($eventParams, $eventDetails[$this->_event_id]); |
542 | //get default participant role. | |
543 | $eventDetails[$this->_event_id]['participant_role'] = CRM_Utils_Array::value($eventDetails[$this->_event_id]['default_role_id'], $participantRoles); | |
544 | //get the location info | |
be2fb01f | 545 | $locParams = ['entity_id' => $this->_event_id, 'entity_table' => 'civicrm_event']; |
97d8187a DG |
546 | $eventDetails[$this->_event_id]['location'] = CRM_Core_BAO_Location::getValues($locParams, TRUE); |
547 | //get contact details | |
548 | $contactIds[$this->_from_contact_id] = $this->_from_contact_id; | |
549 | list($currentContactDetails) = CRM_Utils_Token::getTokenDetails($contactIds, NULL, | |
be2fb01f | 550 | FALSE, FALSE, NULL, [], |
97d8187a DG |
551 | 'CRM_Event_BAO_Participant' |
552 | ); | |
553 | foreach ($currentContactDetails as $contactId => $contactValues) { | |
554 | $contactDetails[$this->_from_contact_id] = $contactValues; | |
555 | } | |
556 | //send a 'cancelled' email to user, and cc the event's cc_confirm email | |
557 | $mail = CRM_Event_BAO_Participant::sendTransitionParticipantMail($this->_from_participant_id, | |
558 | $participantDetails[$this->_from_participant_id], | |
559 | $eventDetails[$this->_event_id], | |
560 | $contactDetails[$this->_from_contact_id], | |
561 | $domainValues, | |
562 | "Transferred", | |
563 | "" | |
564 | ); | |
be2fb01f CW |
565 | $statusMsg = ts('Event registration information for %1 has been updated.', [1 => $this->_contact_name]); |
566 | $statusMsg .= ' ' . ts('A cancellation email has been sent to %1.', [1 => $this->_contact_email]); | |
8b9023b8 | 567 | CRM_Core_Session::setStatus($statusMsg, ts('Thanks'), 'success'); |
97d8187a DG |
568 | } |
569 | ||
570 | } |