3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * Back office participant form.
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
20 * Back office participant form.
22 class CRM_Event_Form_Participant
extends CRM_Contribute_Form_AbstractEditPayment
{
25 * Participant ID - use getParticipantID.
32 * ID of discount record.
38 public $useLivePageJS = TRUE;
41 * The values for the contribution db object.
48 * The values for the quickconfig for priceset.
52 public $_quickConfig = NULL;
55 * Price Set ID, if the new price set method is used
62 * Array of fields for the price set.
69 * The id of the participation that we are processing.
80 protected $_noteId = NULL;
84 * Use parent $this->contactID
86 * The id of the contact associated with this participation.
94 * Array of event values.
101 * Are we operating in "single mode", i.e. adding / editing only
102 * one participant record, or is this a batch add operation
106 public $_single = FALSE;
109 * If event is paid or unpaid.
113 public $_isPaidEvent;
127 protected $_eventTypeId = NULL;
130 * Participant status Id.
134 protected $_statusId = NULL;
137 * Cache all the participant statuses.
141 protected $_participantStatuses;
148 public $_mode = NULL;
151 * Event ID preselect.
158 * Line Item for Price Set.
162 public $_lineItem = NULL;
165 * Contribution mode for event registration for offline mode.
170 public $_contributeMode = 'direct';
175 * Store id of role custom data type ( option value )
179 protected $_roleCustomDataTypeID;
182 * Store id of event Name custom data type ( option value)
186 protected $_eventNameCustomDataTypeID;
189 * Selected discount id.
193 public $_originalDiscountId = NULL;
200 public $_eventId = NULL;
203 * Id of payment, if any
207 public $_paymentId = NULL;
211 * @todo add explanatory note about this
213 public $_onlinePendingContributionId = NULL;
216 * Stored participant record.
220 protected $participantRecord;
223 * Params for creating a payment to add to the contribution.
227 protected $createPaymentParams = [];
230 * Get params to create payments.
234 public function getCreatePaymentParams(): array {
235 return $this->createPaymentParams
;
239 * Set params to create payments.
241 * @param array $createPaymentParams
243 public function setCreatePaymentParams(array $createPaymentParams) {
244 $this->createPaymentParams
= $createPaymentParams;
248 * Explicitly declare the entity api name.
250 public function getDefaultEntity() {
251 return 'Participant';
255 * Default form context used as part of addField()
257 public function getDefaultContext() {
262 * Set variables up before form is built.
264 * @throws \CRM_Core_Exception
265 * @throws \CiviCRM_API3_Exception
267 public function preProcess() {
268 parent
::preProcess();
269 $this->_showFeeBlock
= $_GET['eventId'] ??
NULL;
270 $this->assign('showFeeBlock', FALSE);
271 $this->assign('feeBlockPaid', FALSE);
273 // @todo eliminate this duplication.
274 $this->_contactId
= $this->_contactID
;
275 $this->_eID
= CRM_Utils_Request
::retrieve('eid', 'Positive', $this);
276 $this->_context
= CRM_Utils_Request
::retrieve('context', 'Alphanumeric', $this);
277 $this->assign('context', $this->_context
);
279 if ($this->_contactID
) {
280 $this->setPageTitle(ts('Event Registration for %1', [1 => $this->userDisplayName
]));
283 $this->setPageTitle(ts('Event Registration'));
286 // check the current path, if search based, then dont get participantID
288 $path = CRM_Utils_System
::currentPath();
290 strpos($path, 'civicrm/contact/search') === 0 ||
291 strpos($path, 'civicrm/group/search') === 0
296 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
300 $this->assign('participantId', $this->_id
);
302 $this->_paymentId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
303 $this->_id
, 'id', 'participant_id'
306 $this->assign('hasPayment', $this->_paymentId
);
307 $this->assign('componentId', $this->_id
);
308 $this->assign('component', 'event');
310 // CRM-12615 - Get payment information from the primary registration
311 if ((!$this->_paymentId
) && ($this->_action
== CRM_Core_Action
::UPDATE
)) {
312 $registered_by_id = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant',
313 $this->_id
, 'registered_by_id', 'id'
315 if ($registered_by_id) {
316 $this->_paymentId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
317 $registered_by_id, 'id', 'participant_id'
319 $this->assign('registeredByParticipantId', $registered_by_id);
323 $this->setCustomDataTypes();
326 $this->assign('participantMode', $this->_mode
);
329 if ($this->_showFeeBlock
) {
330 $this->assign('showFeeBlock', TRUE);
331 $isMonetary = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $this->_showFeeBlock
, 'is_monetary');
333 $this->assign('feeBlockPaid', TRUE);
335 return CRM_Event_Form_EventFees
::preProcess($this);
338 //check the mode when this form is called either single or as
340 if ($this->_id ||
$this->_contactId ||
$this->_context
== 'standalone') {
341 $this->_single
= TRUE;
342 $this->assign('urlPath', 'civicrm/contact/view/participant');
343 if (!$this->_id
&& !$this->_contactId
) {
346 'title' => ts('CiviEvent Dashboard'),
347 'url' => CRM_Utils_System
::url('civicrm/event', 'reset=1'),
351 CRM_Utils_System
::appendBreadCrumb($breadCrumbs);
355 //set the appropriate action
356 $context = $this->get('context');
357 $urlString = 'civicrm/contact/search';
358 $this->_action
= CRM_Core_Action
::BASIC
;
361 $urlString = 'civicrm/contact/search/advanced';
362 $this->_action
= CRM_Core_Action
::ADVANCED
;
366 $urlString = 'civicrm/contact/search/builder';
367 $this->_action
= CRM_Core_Action
::PROFILE
;
371 $urlString = 'civicrm/contact/search/basic';
372 $this->_action
= CRM_Core_Action
::BASIC
;
376 $urlString = 'civicrm/contact/search/custom';
377 $this->_action
= CRM_Core_Action
::COPY
;
380 CRM_Contact_Form_Task
::preProcessCommon($this);
382 $this->_single
= FALSE;
383 $this->_contactId
= NULL;
385 //set ajax path, this used for custom data building
386 $this->assign('urlPath', $urlString);
387 $this->assign('urlPathVar', "_qf_Participant_display=true&qfKey={$this->controller->_key}");
390 $this->assign('single', $this->_single
);
393 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'add');
395 $this->assign('action', $this->_action
);
397 // check for edit permission
398 if (!CRM_Core_Permission
::checkActionPermission('CiviEvent', $this->_action
)) {
399 CRM_Core_Error
::statusBounce(ts('You do not have permission to access this page.'));
402 if ($this->_action
& CRM_Core_Action
::DELETE
) {
403 // check delete permission for contribution
404 if ($this->_id
&& $this->_paymentId
&& !CRM_Core_Permission
::checkActionPermission('CiviContribute', $this->_action
)) {
405 CRM_Core_Error
::statusBounce(ts("This Participant is linked to a contribution. You must have 'delete in CiviContribute' permission in order to delete this record."));
411 // assign participant id to the template
412 $this->assign('participantId', $this->_id
);
415 // when fee amount is included in form
416 if (!empty($_POST['hidden_feeblock']) ||
!empty($_POST['send_receipt'])) {
417 CRM_Event_Form_EventFees
::preProcess($this);
418 $this->buildEventFeeForm($this);
419 CRM_Event_Form_EventFees
::setDefaultValues($this);
422 // when custom data is included in this page
423 if (!empty($_POST['hidden_custom'])) {
424 $eventId = (int) ($_POST['event_id'] ??
0);
425 // Custom data of type participant role
426 // Note: Some earlier commits imply $_POST['role_id'] could be a comma separated string,
427 // not sure if that ever really happens
428 if (!empty($_POST['role_id'])) {
429 foreach ($_POST['role_id'] as $roleID) {
430 CRM_Custom_Form_CustomData
::preProcess($this, $this->_roleCustomDataTypeID
, $roleID, 1, 'Participant', $this->_id
);
431 CRM_Custom_Form_CustomData
::buildQuickForm($this);
432 CRM_Custom_Form_CustomData
::setDefaultValues($this);
436 //custom data of type participant event
437 CRM_Custom_Form_CustomData
::preProcess($this, $this->_eventNameCustomDataTypeID
, $eventId, 1, 'Participant', $this->_id
);
438 CRM_Custom_Form_CustomData
::buildQuickForm($this);
439 CRM_Custom_Form_CustomData
::setDefaultValues($this);
441 // custom data of type participant event type
444 $eventTypeId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventId, 'event_type_id', 'id');
446 CRM_Custom_Form_CustomData
::preProcess($this, $this->_eventTypeCustomDataTypeID
, $eventTypeId,
447 1, 'Participant', $this->_id
449 CRM_Custom_Form_CustomData
::buildQuickForm($this);
450 CRM_Custom_Form_CustomData
::setDefaultValues($this);
452 //custom data of type participant, ( we 'null' to reset subType and subName)
453 CRM_Custom_Form_CustomData
::preProcess($this, 'null', 'null', 1, 'Participant', $this->_id
);
454 CRM_Custom_Form_CustomData
::buildQuickForm($this);
455 CRM_Custom_Form_CustomData
::setDefaultValues($this);
458 // CRM-4395, get the online pending contribution id.
459 $this->_onlinePendingContributionId
= NULL;
460 if (!$this->_mode
&& $this->_id
&& ($this->_action
& CRM_Core_Action
::UPDATE
)) {
461 $this->_onlinePendingContributionId
= CRM_Contribute_BAO_Contribution
::checkOnlinePendingContribution($this->_id
,
465 $this->set('onlinePendingContributionId', $this->_onlinePendingContributionId
);
469 * This function sets the default values for the form in edit/view mode
470 * the default values are retrieved from the database
473 * @throws \CRM_Core_Exception
475 public function setDefaultValues() {
476 if ($this->_showFeeBlock
) {
477 return CRM_Event_Form_EventFees
::setDefaultValues($this);
482 if ($this->_action
& CRM_Core_Action
::DELETE
) {
488 $params = ['id' => $this->_id
];
490 CRM_Event_BAO_Participant
::getValues($params, $defaults, $ids);
491 $sep = CRM_Core_DAO
::VALUE_SEPARATOR
;
492 if ($defaults[$this->_id
]['role_id']) {
493 $roleIDs = explode($sep, $defaults[$this->_id
]['role_id']);
495 $this->_contactId
= $defaults[$this->_id
]['contact_id'];
496 $this->_statusId
= $defaults[$this->_id
]['participant_status_id'];
498 //set defaults for note
499 $noteDetails = CRM_Core_BAO_Note
::getNote($this->_id
, 'civicrm_participant');
500 $defaults[$this->_id
]['note'] = array_pop($noteDetails);
502 // Check if this is a primaryParticipant (registered for others) and retrieve additional participants if true (CRM-4859)
503 if (CRM_Event_BAO_Participant
::isPrimaryParticipant($this->_id
)) {
504 $this->assign('additionalParticipants', CRM_Event_BAO_Participant
::getAdditionalParticipants($this->_id
));
507 // Get registered_by contact ID and display_name if participant was registered by someone else (CRM-4859)
508 if (!empty($defaults[$this->_id
]['participant_registered_by_id'])) {
509 $registered_by_contact_id = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant',
510 $defaults[$this->_id
]['participant_registered_by_id'],
513 $this->assign('participant_registered_by_id', $defaults[$this->_id
]['participant_registered_by_id']);
514 $this->assign('registered_by_contact_id', $registered_by_contact_id);
515 $this->assign('registered_by_display_name', CRM_Contact_BAO_Contact
::displayName($registered_by_contact_id));
518 elseif ($this->_contactID
) {
519 $defaults[$this->_id
]['contact_id'] = $this->_contactID
;
522 //setting default register date
523 if ($this->_action
== CRM_Core_Action
::ADD
) {
524 $statuses = array_flip(CRM_Event_PseudoConstant
::participantStatus());
525 $defaults[$this->_id
]['status_id'] = $statuses['Registered'] ??
NULL;
526 if (!empty($defaults[$this->_id
]['event_id'])) {
527 $contributionTypeId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event',
528 $defaults[$this->_id
]['event_id'],
531 if ($contributionTypeId) {
532 $defaults[$this->_id
]['financial_type_id'] = $contributionTypeId;
537 $fields["email-{$this->_bltID}"] = 1;
538 $fields['email-Primary'] = 1;
540 if ($this->_contactId
) {
541 CRM_Core_BAO_UFGroup
::setProfileDefaults($this->_contactId
, $fields, $defaults);
544 if (empty($defaults["email-{$this->_bltID}"]) &&
545 !empty($defaults['email-Primary'])
547 $defaults[$this->_id
]["email-{$this->_bltID}"] = $defaults['email-Primary'];
551 $submittedRole = $this->getElementValue('role_id');
552 if (!empty($submittedRole[0])) {
553 $roleID = $submittedRole[0];
555 $submittedEvent = $this->getElementValue('event_id');
556 if (!empty($submittedEvent[0])) {
557 $eventID = $submittedEvent[0];
559 $defaults[$this->_id
]['register_date'] = date('Y-m-d H:i:s');
562 $defaults[$this->_id
]['record_contribution'] = 0;
564 if ($defaults[$this->_id
]['participant_is_pay_later']) {
565 $this->assign('participant_is_pay_later', TRUE);
568 $this->assign('participant_status_id', $defaults[$this->_id
]['participant_status_id']);
569 $eventID = $defaults[$this->_id
]['event_id'];
571 $this->_eventTypeId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventID, 'event_type_id', 'id');
573 $this->_discountId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'discount_id');
574 if ($this->_discountId
) {
575 $this->set('discountId', $this->_discountId
);
579 //assign event and role id, this is needed for Custom data building
580 $sep = CRM_Core_DAO
::VALUE_SEPARATOR
;
581 if (!empty($defaults[$this->_id
]['participant_role_id'])) {
582 $roleIDs = explode($sep, $defaults[$this->_id
]['participant_role_id']);
584 if (isset($_POST['event_id'])) {
585 $eventID = $_POST['event_id'];
589 $eventID = $this->_eID
;
590 //@todo - rationalise the $this->_eID with $POST['event_id'], $this->_eid is set when eid=x is in the url
591 $roleID = CRM_Core_DAO
::getFieldValue(
592 'CRM_Event_DAO_Event',
596 if (empty($roleIDs)) {
597 $roleIDs = (array) $defaults[$this->_id
]['participant_role_id'] = $roleID;
599 $defaults[$this->_id
]['event_id'] = $eventID;
601 if (!empty($eventID)) {
602 $this->_eventTypeId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventID, 'event_type_id', 'id');
604 //these should take precedence so we state them last
605 $urlRoleIDS = CRM_Utils_Request
::retrieve('roles', 'String');
607 $roleIDs = explode(',', $urlRoleIDS);
609 if (isset($roleIDs)) {
610 $defaults[$this->_id
]['role_id'] = implode(',', $roleIDs);
613 if (isset($eventID)) {
614 $this->assign('eventID', $eventID);
615 $this->set('eventId', $eventID);
618 if (isset($this->_eventTypeId
)) {
619 $this->assign('eventTypeID', $this->_eventTypeId
);
622 $this->assign('event_is_test', CRM_Utils_Array
::value('event_is_test', $defaults[$this->_id
]));
623 return $defaults[$this->_id
];
627 * Build the form object.
630 * @throws \CRM_Core_Exception
631 * @throws \CiviCRM_API3_Exception
633 public function buildQuickForm() {
635 $participantStatuses = CRM_Event_PseudoConstant
::participantStatus();
636 $partiallyPaidStatusId = array_search('Partially paid', $participantStatuses);
637 $this->assign('partiallyPaidStatusId', $partiallyPaidStatusId);
639 if ($this->_showFeeBlock
) {
640 return $this->buildEventFeeForm($this);
643 //need to assign custom data type to the template
644 $this->assign('customDataType', 'Participant');
646 $this->applyFilter('__ALL__', 'trim');
648 if ($this->_action
& CRM_Core_Action
::DELETE
) {
649 if ($this->_single
) {
650 $additionalParticipant = count(CRM_Event_BAO_Event
::buildCustomProfile($this->_id
,
656 if ($additionalParticipant) {
657 $deleteParticipants = [
658 1 => ts('Delete this participant record along with associated participant record(s).'),
659 2 => ts('Delete only this participant record.'),
661 $this->addRadio('delete_participant', NULL, $deleteParticipants, NULL, '<br />');
662 $this->setDefaults(['delete_participant' => 1]);
663 $this->assign('additionalParticipant', $additionalParticipant);
669 'name' => ts('Delete'),
670 'spacing' => ' ',
675 'name' => ts('Cancel'),
681 if ($this->_single
) {
682 $contactField = $this->addEntityRef('contact_id', ts('Participant'), ['create' => TRUE, 'api' => ['extra' => ['email']]], TRUE);
683 if ($this->_context
!= 'standalone') {
684 $contactField->freeze();
688 $eventFieldParams = [
690 'select' => ['minimumInputLength' => 0],
692 'extra' => ['campaign_id', 'default_role_id', 'event_type_id'],
697 // exclude events which are not monetary when credit card registration is used
698 $eventFieldParams['api']['params']['is_monetary'] = 1;
700 $this->addPaymentProcessorSelect(TRUE, FALSE, FALSE);
702 $element = $this->addEntityRef('event_id', ts('Event'), $eventFieldParams, TRUE);
704 //frozen the field fix for CRM-4171
705 if ($this->_action
& CRM_Core_Action
::UPDATE
&& $this->_id
) {
706 if (CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
707 $this->_id
, 'contribution_id', 'participant_id'
714 //CRM-7362 --add campaigns.
717 $campaignId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'campaign_id');
720 $eventId = CRM_Utils_Request
::retrieve('eid', 'Positive', $this);
722 $campaignId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventId, 'campaign_id');
725 CRM_Campaign_BAO_Campaign
::addCampaign($this, $campaignId);
726 $this->add('datepicker', 'register_date', ts('Registration Date'), [], TRUE, ['time' => TRUE]);
729 $this->assign('entityID', $this->_id
);
732 $this->addSelect('role_id', ['multiple' => TRUE, 'class' => 'huge'], TRUE);
735 $checkCancelledJs = ['onchange' => "return sendNotification( );"];
737 if ($this->_onlinePendingContributionId
) {
738 $cancelledparticipantStatusId = array_search('Cancelled', CRM_Event_PseudoConstant
::participantStatus());
739 $cancelledContributionStatusId = array_search('Cancelled',
740 CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name')
742 $checkCancelledJs = [
743 'onchange' => "checkCancelled( this.value, {$cancelledparticipantStatusId},{$cancelledContributionStatusId});",
746 $participantStatusId = array_search('Pending from pay later',
747 CRM_Event_PseudoConstant
::participantStatus()
749 $contributionStatusId = array_search('Completed',
750 CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name')
752 $confirmJS = ['onclick' => "return confirmStatus( {$participantStatusId}, {$contributionStatusId} );"];
755 // get the participant status names to build special status array which is used to show notification
756 // checkbox below participant status select
757 $participantStatusName = CRM_Event_PseudoConstant
::participantStatus();
758 $notificationStatuses = [
760 'Pending from waitlist',
761 'Pending from approval',
765 // get the required status and then implode only ids
766 $notificationStatusIds = implode(',', array_keys(array_intersect($participantStatusName, $notificationStatuses)));
767 $this->assign('notificationStatusIds', $notificationStatusIds);
769 $this->_participantStatuses
= $statusOptions = CRM_Event_BAO_Participant
::buildOptions('status_id', 'create');
771 // Only show refund status when editing
772 if ($this->_action
& CRM_Core_Action
::ADD
) {
773 $pendingRefundStatusId = array_search('Pending refund', $participantStatusName);
774 if ($pendingRefundStatusId) {
775 unset($statusOptions[$pendingRefundStatusId]);
779 $this->addSelect('status_id', $checkCancelledJs +
[
780 'options' => $statusOptions,
781 'option_url' => 'civicrm/admin/participant_status',
784 $this->addElement('checkbox', 'is_notify', ts('Send Notification'), NULL);
786 $this->addField('source', ['entity' => 'Participant', 'name' => 'source']);
787 $noteAttributes = CRM_Core_DAO
::getAttribute('CRM_Core_DAO_Note');
788 $this->add('textarea', 'note', ts('Notes'), $noteAttributes['note']);
792 'name' => ts('Save'),
797 $path = CRM_Utils_System
::currentPath();
799 'civicrm/contact/search',
800 'civicrm/group/search',
802 if (!in_array($path, $excludeForPaths)) {
805 'name' => ts('Save and New'),
813 'name' => ts('Cancel'),
816 $this->addButtons($buttons);
817 if ($this->_action
== CRM_Core_Action
::VIEW
) {
823 * Add local and global form rules.
827 public function addRules() {
828 $this->addFormRule(['CRM_Event_Form_Participant', 'formRule'], $this);
832 * Global validation rules for the form.
834 * @param array $values
835 * Posted values of the form.
840 * list of errors to be posted back to the form
842 public static function formRule($values, $files, $self) {
843 // If $values['_qf_Participant_next'] is Delete or
844 // $values['event_id'] is empty, then return
845 // instead of proceeding further.
847 if ((CRM_Utils_Array
::value('_qf_Participant_next', $values) == 'Delete') ||
848 (!$values['event_id'])
855 if (!empty($values['payment_processor_id'])) {
856 // make sure that payment instrument values (e.g. credit card number and cvv) are valid
857 CRM_Core_Payment_Form
::validatePaymentInstrument($values['payment_processor_id'], $values, $errorMsg, NULL);
860 if (!empty($values['record_contribution'])) {
861 if (empty($values['financial_type_id'])) {
862 $errorMsg['financial_type_id'] = ts('Please enter the associated Financial Type');
864 if (empty($values['payment_instrument_id'])) {
865 $errorMsg['payment_instrument_id'] = ts('Payment Method is a required field.');
867 if (!empty($values['priceSetId'])) {
868 CRM_Price_BAO_PriceField
::priceSetValidation($values['priceSetId'], $values, $errorMsg);
872 // validate contribution status for 'Failed'.
873 if ($self->_onlinePendingContributionId
&& !empty($values['record_contribution']) &&
874 (CRM_Utils_Array
::value('contribution_status_id', $values) ==
875 array_search('Failed', CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name'))
878 $errorMsg['contribution_status_id'] = ts('Please select a valid payment status before updating.');
881 // do the amount validations.
882 //skip for update mode since amount is freeze, CRM-6052
883 if ((!$self->_id
&& empty($values['total_amount']) &&
884 empty($self->_values
['line_items'])
886 ($self->_id
&& !$self->_paymentId
&& isset($self->_values
['line_items']) && is_array($self->_values
['line_items']))
888 if ($priceSetId = CRM_Utils_Array
::value('priceSetId', $values)) {
889 CRM_Price_BAO_PriceField
::priceSetValidation($priceSetId, $values, $errorMsg, TRUE);
892 // For single additions - show validation error if the contact has already been registered
894 if ($self->_single
&& ($self->_action
& CRM_Core_Action
::ADD
)) {
895 if ($self->_context
== 'standalone') {
896 $contactId = $values['contact_id'] ??
NULL;
899 $contactId = $self->_contactId
;
902 $eventId = $values['event_id'] ??
NULL;
904 $event = new CRM_Event_DAO_Event();
905 $event->id
= $eventId;
908 if (!$event->allow_same_participant_emails
&& !empty($contactId) && !empty($eventId)) {
909 $cancelledStatusID = CRM_Core_PseudoConstant
::getKey('CRM_Event_BAO_Participant', 'status_id', 'Cancelled');
910 $dupeCheck = new CRM_Event_BAO_Participant();
911 $dupeCheck->contact_id
= $contactId;
912 $dupeCheck->event_id
= $eventId;
913 $dupeCheck->whereAdd("status_id != {$cancelledStatusID} ");
914 $dupeCheck->find(TRUE);
915 if (!empty($dupeCheck->id
)) {
916 $errorMsg['event_id'] = ts("This contact has already been assigned to this event.");
920 return CRM_Utils_Array
::crmIsEmptyArray($errorMsg) ?
TRUE : $errorMsg;
924 * Process the form submission.
926 public function postProcess() {
927 // get the submitted form values.
928 $params = $this->controller
->exportValues($this->_name
);
930 if ($this->_action
& CRM_Core_Action
::DELETE
) {
931 if (CRM_Utils_Array
::value('delete_participant', $params) == 2) {
932 $additionalId = (CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_id
));
933 $participantLinks = (CRM_Event_BAO_Participant
::getAdditionalParticipantUrl($additionalId));
935 if (CRM_Utils_Array
::value('delete_participant', $params) == 1) {
936 $additionalIds = CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_id
);
937 foreach ($additionalIds as $value) {
938 CRM_Event_BAO_Participant
::deleteParticipant($value);
941 CRM_Event_BAO_Participant
::deleteParticipant($this->_id
);
942 CRM_Core_Session
::setStatus(ts('Selected participant was deleted successfully.'), ts('Record Deleted'), 'success');
943 if (!empty($participantLinks)) {
944 $status = ts('The following participants no longer have an event fee recorded. You can edit their registration and record a replacement contribution by clicking the links below:') . '<br/>' . $participantLinks;
945 CRM_Core_Session
::setStatus($status, ts('Group Payment Deleted'));
949 // When adding a single contact, the formRule prevents you from adding duplicates
950 // (See above in formRule()). When adding more than one contact, the duplicates are
951 // removed automatically and the user receives one notification.
952 if ($this->_action
& CRM_Core_Action
::ADD
) {
953 $event_id = $this->_eventId
;
954 if (empty($event_id) && !empty($params['event_id'])) {
955 $event_id = $params['event_id'];
957 if (!$this->_single
&& !empty($event_id)) {
958 $duplicateContacts = 0;
959 foreach ($this->_contactIds
as $k => $dupeCheckContactId) {
960 // Eliminate contacts that have already been assigned to this event.
961 $dupeCheck = new CRM_Event_BAO_Participant();
962 $dupeCheck->contact_id
= $dupeCheckContactId;
963 $dupeCheck->event_id
= $event_id;
964 $dupeCheck->find(TRUE);
965 if (!empty($dupeCheck->id
)) {
966 $duplicateContacts++
;
967 unset($this->_contactIds
[$k]);
970 if ($duplicateContacts > 0) {
972 "%1 contacts have already been assigned to this event. They were not added a second time.",
973 [1 => $duplicateContacts]
975 CRM_Core_Session
::setStatus($msg);
977 if (count($this->_contactIds
) == 0) {
978 CRM_Core_Session
::setStatus(ts("No participants were added."));
981 // We have to re-key $this->_contactIds so each contact has the same
982 // key as their corresponding record in the $participants array that
983 // will be created below.
984 $this->_contactIds
= array_values($this->_contactIds
);
988 $statusMsg = $this->submit($params);
989 CRM_Core_Session
::setStatus($statusMsg, ts('Saved'), 'success');
990 $session = CRM_Core_Session
::singleton();
991 $buttonName = $this->controller
->getButtonName();
992 if ($this->_context
== 'standalone') {
993 if ($buttonName == $this->getButtonName('upload', 'new')) {
994 $urlParams = 'reset=1&action=add&context=standalone';
996 $urlParams .= '&mode=' . $this->_mode
;
999 $urlParams .= '&eid=' . $this->_eID
;
1001 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/participant/add', $urlParams));
1004 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/contact/view',
1005 "reset=1&cid={$this->_contactId}&selectedChild=participant"
1009 elseif ($buttonName == $this->getButtonName('upload', 'new')) {
1010 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/contact/view/participant',
1011 "reset=1&action=add&context={$this->_context}&cid={$this->_contactId}"
1019 * @param array $params
1022 * @throws \CRM_Core_Exception
1023 * @throws \CiviCRM_API3_Exception
1025 public function submit($params) {
1026 if ($this->_mode
&& !$this->_isPaidEvent
) {
1027 CRM_Core_Error
::statusBounce(ts('Selected Event is not Paid Event '));
1029 $participantStatus = CRM_Event_PseudoConstant
::participantStatus();
1030 // set the contact, when contact is selected
1031 if (!empty($params['contact_id'])) {
1032 $this->_contactID
= $this->_contactId
= $params['contact_id'];
1034 if (!$this->_priceSetId
&& $this->_isPaidEvent
) {
1035 CRM_Core_Error
::deprecatedFunctionWarning('this should never be true, handling to be removed');
1037 if ($this->_priceSetId
&& $isQuickConfig = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId
, 'is_quick_config')) {
1038 $this->_quickConfig
= $isQuickConfig;
1042 $params['id'] = $this->_id
;
1045 $config = CRM_Core_Config
::singleton();
1046 if (isset($params['total_amount'])) {
1047 $params['total_amount'] = CRM_Utils_Rule
::cleanMoney($params['total_amount']);
1049 if ($this->_isPaidEvent
) {
1050 list($contributionParams, $lineItem, $additionalParticipantDetails, $params) = $this->preparePaidEventProcessing($params);
1053 $this->_params
= $params;
1054 parent
::beginPostProcess();
1056 if (isset($params['amount'])) {
1057 $amountOwed = $params['amount'];
1058 unset($params['amount']);
1060 $params['contact_id'] = $this->_contactId
;
1062 // overwrite actual payment amount if entered
1063 if (!empty($params['total_amount'])) {
1064 $contributionParams['total_amount'] = $params['total_amount'] ??
NULL;
1067 // Retrieve the name and email of the current user - this will be the FROM for the receipt email
1068 $userName = CRM_Core_Session
::singleton()->getLoggedInContactDisplayName();
1070 if ($this->_contactId
) {
1071 list($this->_contributorDisplayName
, $this->_contributorEmail
, $this->_toDoNotEmail
) = CRM_Contact_BAO_Contact
::getContactDetails($this->_contactId
);
1074 //modify params according to parameter used in create
1075 //participant method (addParticipant)
1076 $this->_params
['participant_status_id'] = $params['status_id'];
1077 $this->_params
['participant_role_id'] = is_array($params['role_id']) ?
$params['role_id'] : explode(',', $params['role_id']);
1078 $roleIdWithSeparator = implode(CRM_Core_DAO
::VALUE_SEPARATOR
, $this->_params
['participant_role_id']);
1080 $now = date('YmdHis');
1083 // set source if not set
1084 if (empty($params['source'])) {
1085 $this->_params
['participant_source'] = ts('Offline Registration for Event: %2 by: %1', [
1087 2 => $this->getEventValue('title'),
1091 $this->_params
['participant_source'] = $params['source'];
1093 $this->_params
['description'] = $this->_params
['participant_source'];
1095 $this->_paymentProcessor
= CRM_Financial_BAO_PaymentProcessor
::getPayment($this->_params
['payment_processor_id'],
1100 // set email for primary location.
1101 $fields['email-Primary'] = 1;
1102 $params['email-Primary'] = $params["email-{$this->_bltID}"] = $this->_contributorEmail
;
1104 // now set the values for the billing location.
1105 foreach ($this->_fields
as $name => $dontCare) {
1109 // also add location name to the array
1110 $params["address_name-{$this->_bltID}"]
1111 = CRM_Utils_Array
::value('billing_first_name', $params) . ' ' .
1112 CRM_Utils_Array
::value('billing_middle_name', $params) . ' ' .
1113 CRM_Utils_Array
::value('billing_last_name', $params);
1115 $params["address_name-{$this->_bltID}"] = trim($params["address_name-{$this->_bltID}"]);
1116 $fields["address_name-{$this->_bltID}"] = 1;
1117 $fields["email-{$this->_bltID}"] = 1;
1118 $ctype = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId
, 'contact_type');
1120 $nameFields = ['first_name', 'middle_name', 'last_name'];
1122 foreach ($nameFields as $name) {
1124 if (array_key_exists("billing_$name", $params)) {
1125 $params[$name] = $params["billing_{$name}"];
1126 $params['preserveDBName'] = TRUE;
1129 $contactID = CRM_Contact_BAO_Contact
::createProfileContact($params, $fields, $this->_contactId
, NULL, NULL, $ctype);
1132 if (!empty($this->_params
['participant_role_id'])) {
1133 $customFieldsRole = [];
1134 foreach ($this->_params
['participant_role_id'] as $roleKey) {
1135 $customFieldsRole = CRM_Utils_Array
::crmArrayMerge(CRM_Core_BAO_CustomField
::getFields('Participant',
1136 FALSE, FALSE, $roleKey, $this->_roleCustomDataTypeID
), $customFieldsRole);
1138 $customFieldsEvent = CRM_Core_BAO_CustomField
::getFields('Participant',
1141 CRM_Utils_Array
::value('event_id', $params),
1142 $this->_eventNameCustomDataTypeID
1144 $customFieldsEventType = CRM_Core_BAO_CustomField
::getFields('Participant',
1147 $this->_eventTypeId
,
1148 $this->_eventTypeCustomDataTypeID
1150 $customFields = CRM_Utils_Array
::crmArrayMerge($customFieldsRole,
1151 CRM_Core_BAO_CustomField
::getFields('Participant', FALSE, FALSE, NULL, NULL, TRUE)
1153 $customFields = CRM_Utils_Array
::crmArrayMerge($customFieldsEvent, $customFields);
1154 $customFields = CRM_Utils_Array
::crmArrayMerge($customFieldsEventType, $customFields);
1156 $params['custom'] = CRM_Core_BAO_CustomField
::postProcess($params, $this->_id
, $this->getDefaultEntity());
1159 //do cleanup line items if participant edit the Event Fee.
1160 if (($this->_lineItem ||
!isset($params['proceSetId'])) && !$this->_paymentId
&& $this->_id
) {
1161 CRM_Price_BAO_LineItem
::deleteLineItems($this->_id
, 'civicrm_participant');
1165 // add all the additional payment params we need
1166 $this->_params
= $this->prepareParamsForPaymentProcessor($this->_params
);
1167 $this->_params
['amount'] = $params['fee_amount'];
1168 $this->_params
['amount_level'] = $params['amount_level'];
1169 $this->_params
['currencyID'] = $config->defaultCurrency
;
1170 $this->_params
['invoiceID'] = md5(uniqid(rand(), TRUE));
1172 // at this point we've created a contact and stored its address etc
1173 // all the payment processors expect the name and address to be in the
1174 // so we copy stuff over to first_name etc.
1175 $paymentParams = $this->_params
;
1176 if (!empty($this->_params
['send_receipt'])) {
1177 $paymentParams['email'] = $this->_contributorEmail
;
1180 // The only reason for merging in the 'contact_id' rather than ensuring it is set
1181 // is that this patch is being done around the time of the stable release
1182 // so more conservative approach is called for.
1183 // In fact the use of $params and $this->_params & $this->_contactId vs $contactID
1184 // needs rationalising.
1185 $mapParams = array_merge(['contact_id' => $contactID], $this->_params
);
1186 CRM_Core_Payment_Form
::mapParams($this->_bltID
, $mapParams, $paymentParams, TRUE);
1188 $payment = $this->_paymentProcessor
['object'];
1190 // CRM-15622: fix for incorrect contribution.fee_amount
1191 $paymentParams['fee_amount'] = NULL;
1193 $result = $payment->doPayment($paymentParams);
1195 catch (\Civi\Payment\Exception\PaymentProcessorException
$e) {
1196 // @todo un comment the following line out when we are creating a contribution before we get to this point
1197 // see dev/financial#53 about ensuring we create a pending contribution before we try processing payment
1198 // CRM_Contribute_BAO_Contribution::failPayment($contributionID);
1199 CRM_Core_Session
::singleton()->setStatus($e->getMessage());
1200 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/contact/view/participant',
1201 "reset=1&action=add&cid={$this->_contactId}&context=participant&mode={$this->_mode}"
1206 $this->_params
= array_merge($this->_params
, $result);
1209 $this->_params
['receive_date'] = $now;
1211 if (!empty($this->_params
['send_receipt'])) {
1212 $this->_params
['receipt_date'] = $now;
1215 $this->_params
['receipt_date'] = NULL;
1218 $this->set('params', $this->_params
);
1219 $this->assign('trxn_id', $result['trxn_id']);
1220 $this->assign('receive_date', $this->_params
['receive_date']);
1222 //add contribution record
1223 $this->_params
['financial_type_id']
1224 = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'financial_type_id');
1225 $this->_params
['mode'] = $this->_mode
;
1227 //add contribution record
1228 $contributions[] = $contribution = $this->processContribution(
1229 $this, $this->_params
,
1230 $result, $contactID,
1232 $this->_paymentProcessor
1235 // add participant record
1237 if (!empty($this->_params
['role_id']) && is_array($this->_params
['role_id'])) {
1238 $this->_params
['role_id'] = implode(CRM_Core_DAO
::VALUE_SEPARATOR
,
1239 $this->_params
['role_id']
1243 //CRM-15372 patch to fix fee amount replacing amount
1244 $this->_params
['fee_amount'] = $this->_params
['amount'];
1246 $participants[] = $this->addParticipant($this, $this->_params
, $contactID);
1248 //add custom data for participant
1249 CRM_Core_BAO_CustomValueTable
::postProcess($this->_params
,
1250 'civicrm_participant',
1251 $participants[0]->id
,
1255 // Add participant payment
1256 $participantPaymentParams = [
1257 'participant_id' => $participants[0]->id
,
1258 'contribution_id' => $contribution->id
,
1260 civicrm_api3('ParticipantPayment', 'create', $participantPaymentParams);
1262 $this->_contactIds
[] = $this->_contactId
;
1266 if ($this->_single
) {
1267 if ($params['role_id']) {
1268 $params['role_id'] = $roleIdWithSeparator;
1271 $params['role_id'] = 'NULL';
1273 $participants[] = CRM_Event_BAO_Participant
::create($params);
1276 foreach ($this->_contactIds
as $contactID) {
1277 $commonParams = $params;
1278 $commonParams['contact_id'] = $contactID;
1279 if ($commonParams['role_id']) {
1280 $commonParams['role_id'] = $commonParams['role_id'] = str_replace(',', CRM_Core_DAO
::VALUE_SEPARATOR
, $params['role_id']);
1283 $commonParams['role_id'] = 'NULL';
1285 $participants[] = CRM_Event_BAO_Participant
::create($commonParams);
1289 if ($this->_single
) {
1290 $this->_contactIds
[] = $this->_contactId
;
1293 $contributions = [];
1294 if (!empty($params['record_contribution'])) {
1295 if (!empty($params['id'])) {
1296 if ($this->_onlinePendingContributionId
) {
1297 $contributionParams['id'] = $this->_onlinePendingContributionId
;
1300 $contributionParams['id'] = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
1307 unset($params['note']);
1309 //build contribution params
1310 if (!$this->_onlinePendingContributionId
) {
1311 if (empty($params['source'])) {
1312 $contributionParams['source'] = ts('%1 : Offline registration (by %2)', [
1313 1 => $this->getEventValue('title'),
1318 $contributionParams['source'] = $params['source'];
1322 $contributionParams['currency'] = $config->defaultCurrency
;
1323 $contributionParams['non_deductible_amount'] = 'null';
1324 $contributionParams['receipt_date'] = !empty($params['send_receipt']) ? CRM_Utils_Array
::value('receive_date', $params) : 'null';
1325 $contributionParams['contact_id'] = $this->_contactID
;
1326 $contributionParams['receive_date'] = CRM_Utils_Array
::value('receive_date', $params, 'null');
1328 $recordContribution = [
1329 'financial_type_id',
1330 'payment_instrument_id',
1332 'contribution_status_id',
1339 foreach ($recordContribution as $f) {
1340 $contributionParams[$f] = $this->_params
[$f] ??
NULL;
1341 if ($f == 'trxn_id') {
1342 $this->assign('trxn_id', $contributionParams[$f]);
1346 //insert financial type name in receipt.
1347 $this->assign('financialTypeName', CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_FinancialType',
1348 $contributionParams['financial_type_id']));
1350 $this->assign('contributionTypeName', CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_FinancialType', $contributionParams['financial_type_id']));
1351 $contributionParams['skipLineItem'] = 1;
1353 $contributionParams['contribution_mode'] = 'participant';
1354 $contributionParams['participant_id'] = $this->_id
;
1356 // Set is_pay_later flag for back-office offline Pending status contributions
1357 if ($contributionParams['contribution_status_id'] == CRM_Core_PseudoConstant
::getKey('CRM_Contribute_DAO_Contribution', 'contribution_status_id', 'Pending')) {
1358 $contributionParams['is_pay_later'] = 1;
1360 elseif ($contributionParams['contribution_status_id'] == CRM_Core_PseudoConstant
::getKey('CRM_Contribute_DAO_Contribution', 'contribution_status_id', 'Completed')) {
1361 $contributionParams['is_pay_later'] = 0;
1364 if ($params['status_id'] == array_search('Partially paid', $participantStatus)) {
1365 if (!$amountOwed && $this->_action
& CRM_Core_Action
::UPDATE
) {
1366 $amountOwed = $params['fee_amount'];
1369 // if multiple participants are link, consider contribution total amount as the amount Owed
1370 if ($this->_id
&& CRM_Event_BAO_Participant
::isPrimaryParticipant($this->_id
)) {
1371 $amountOwed = CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_Contribution',
1372 $contributionParams['id'],
1377 // CRM-13964 partial_payment_total
1378 if ($amountOwed > $params['total_amount']) {
1380 $contributionParams['total_amount'] = $amountOwed;
1381 $contributionParams['contribution_status_id'] = CRM_Core_PseudoConstant
::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending');
1382 $this->assign('balanceAmount', $amountOwed - $params['total_amount']);
1383 $this->storePaymentCreateParams($params);
1387 if (!empty($this->_params
['tax_amount'])) {
1388 $contributionParams['tax_amount'] = $this->_params
['tax_amount'];
1391 if ($this->_single
) {
1392 $contributions[] = CRM_Contribute_BAO_Contribution
::create($contributionParams);
1395 foreach ($this->_contactIds
as $contactID) {
1396 $contributionParams['contact_id'] = $contactID;
1397 $contributions[] = CRM_Contribute_BAO_Contribution
::create($contributionParams);
1401 // Insert payment record for this participant
1402 if (empty($contributionParams['id'])) {
1403 foreach ($this->_contactIds
as $num => $contactID) {
1404 $participantPaymentParams = [
1405 'participant_id' => $participants[$num]->id
,
1406 'contribution_id' => $contributions[$num]->id
,
1408 civicrm_api3('ParticipantPayment', 'create', $participantPaymentParams);
1413 if ($this->_params
['discount_id']) {
1414 CRM_Event_BAO_Participant
::createDiscountTrxn(
1416 $contributionParams,
1418 CRM_Price_BAO_PriceSet
::parseFirstPriceSetValueIDFromParams($this->_params
)
1424 // also store lineitem stuff here
1425 if ((($this->_lineItem
& $this->_action
& CRM_Core_Action
::ADD
) ||
1426 ($this->_lineItem
&& CRM_Core_Action
::UPDATE
&& !$this->_paymentId
))
1428 foreach ($this->_contactIds
as $num => $contactID) {
1429 foreach ($this->_lineItem
as $key => $value) {
1430 if (is_array($value) && $value != 'skip') {
1431 foreach ($value as $lineKey => $line) {
1432 //10117 update the line items for participants if contribution amount is recorded
1433 if ($this->_quickConfig
&& !empty($params['total_amount']) &&
1434 ($params['status_id'] != array_search('Partially paid', $participantStatus))
1436 $line['unit_price'] = $line['line_total'] = $params['total_amount'];
1437 if (!empty($params['tax_amount'])) {
1438 $line['unit_price'] = $line['unit_price'] - $params['tax_amount'];
1439 $line['line_total'] = $line['line_total'] - $params['tax_amount'];
1442 $lineItem[$this->_priceSetId
][$lineKey] = $line;
1444 CRM_Price_BAO_LineItem
::processPriceSet($participants[$num]->id
, $lineItem, CRM_Utils_Array
::value($num, $contributions, NULL), 'civicrm_participant');
1448 foreach ($contributions as $contribution) {
1449 if (!empty($this->getCreatePaymentParams())) {
1450 civicrm_api3('Payment', 'create', array_merge(['contribution_id' => $contribution->id
], $this->getCreatePaymentParams()));
1455 $updateStatusMsg = NULL;
1456 //send mail when participant status changed, CRM-4326
1457 if ($this->_id
&& $this->_statusId
&&
1458 $this->_statusId
!= CRM_Utils_Array
::value('status_id', $params) && !empty($params['is_notify'])
1461 $updateStatusMsg = CRM_Event_BAO_Participant
::updateStatusMessage($this->_id
,
1462 $params['status_id'],
1469 if (!empty($params['send_receipt'])) {
1471 $this->assign('module', 'Event Registration');
1472 $this->assignEventDetailsToTpl($params['event_id'], CRM_Utils_Array
::value('role_id', $params), CRM_Utils_Array
::value('receipt_text', $params), $this->_isPaidEvent
);
1473 $this->assign('isAmountzero', 1);
1475 if ($this->_isPaidEvent
) {
1476 $paymentInstrument = CRM_Contribute_PseudoConstant
::paymentInstrument();
1477 if (!$this->_mode
) {
1478 if (isset($params['payment_instrument_id'])) {
1479 $this->assign('paidBy',
1480 CRM_Utils_Array
::value($params['payment_instrument_id'],
1487 $this->assign('totalAmount', $params['total_amount'] ??
$contributionParams['total_amount']);
1488 $this->assign('isPrimary', 1);
1489 $this->assign('checkNumber', CRM_Utils_Array
::value('check_number', $params));
1492 $this->assignBillingName($params);
1493 $this->assign('address', CRM_Utils_Address
::getFormattedBillingAddressFieldsFromParameters(
1498 $date = CRM_Utils_Date
::format($params['credit_card_exp_date']);
1499 $date = CRM_Utils_Date
::mysqlToIso($date);
1500 $this->assign('credit_card_exp_date', $date);
1501 $this->assign('credit_card_number',
1502 CRM_Utils_System
::mungeCreditCard($params['credit_card_number'])
1504 $this->assign('credit_card_type', $params['credit_card_type']);
1505 // The concept of contributeMode is deprecated.
1506 $this->assign('contributeMode', 'direct');
1507 $this->assign('isAmountzero', 0);
1508 $this->assign('is_pay_later', 0);
1509 $this->assign('isPrimary', 1);
1512 $this->assign('register_date', $params['register_date']);
1513 if (isset($params['receive_date'])) {
1514 $this->assign('receive_date', $params['receive_date']);
1518 //format submitted data
1519 foreach ($params['custom'] as $fieldID => $values) {
1520 foreach ($values as $fieldValue) {
1521 $isPublic = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_CustomGroup', $fieldValue['custom_group_id'], 'is_public');
1523 $customFields[$fieldID]['id'] = $fieldID;
1524 $formattedValue = CRM_Core_BAO_CustomField
::displayValue($fieldValue['value'], $fieldID, $participants[0]->id
);
1525 $customGroup[$customFields[$fieldID]['groupTitle']][$customFields[$fieldID]['label']] = str_replace(' ', '', $formattedValue);
1530 foreach ($this->_contactIds
as $num => $contactID) {
1531 // Retrieve the name and email of the contact - this will be the TO for receipt email
1532 list($this->_contributorDisplayName
, $this->_contributorEmail
, $this->_toDoNotEmail
) = CRM_Contact_BAO_Contact
::getContactDetails($contactID);
1534 $this->_contributorDisplayName
= ($this->_contributorDisplayName
== ' ') ?
$this->_contributorEmail
: $this->_contributorDisplayName
;
1536 $waitStatus = CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Waiting'");
1537 if ($waitingStatus = CRM_Utils_Array
::value($params['status_id'], $waitStatus)) {
1538 $this->assign('isOnWaitlist', TRUE);
1541 $this->assign('customGroup', $customGroup);
1542 $this->assign('contactID', $contactID);
1543 $this->assign('participantID', $participants[$num]->id
);
1545 $this->_id
= $participants[$num]->id
;
1547 if ($this->_isPaidEvent
) {
1548 // fix amount for each of participants ( for bulk mode )
1550 $invoiceSettings = Civi
::settings()->get('contribution_invoice_settings');
1551 $invoicing = $invoiceSettings['invoicing'] ??
NULL;
1552 $totalTaxAmount = 0;
1554 //add dataArray in the receipts in ADD and UPDATE condition
1556 if ($this->_action
& CRM_Core_Action
::ADD
) {
1557 $line = $lineItem[0] ??
[];
1559 elseif ($this->_action
& CRM_Core_Action
::UPDATE
) {
1560 $line = $this->_values
['line_items'];
1563 foreach ($line as $key => $value) {
1564 if (isset($value['tax_amount'])) {
1565 $totalTaxAmount +
= $value['tax_amount'];
1566 if (isset($dataArray[(string) $value['tax_rate']])) {
1567 $dataArray[(string) $value['tax_rate']] = $dataArray[(string) $value['tax_rate']] + CRM_Utils_Array
::value('tax_amount', $value);
1570 $dataArray[(string) $value['tax_rate']] = $value['tax_amount'] ??
NULL;
1574 $this->assign('totalTaxAmount', $totalTaxAmount);
1575 $this->assign('taxTerm', $this->getSalesTaxTerm());
1576 $this->assign('dataArray', $dataArray);
1578 if (!empty($additionalParticipantDetails)) {
1579 $params['amount_level'] = preg_replace('/\ 1/', '', $params['amount_level']) . ' - ' . $this->_contributorDisplayName
;
1582 $eventAmount[$num] = [
1583 'label' => preg_replace('/\ 1/', '', $params['amount_level']),
1584 'amount' => $params['fee_amount'],
1586 //as we are using same template for online & offline registration.
1587 //So we have to build amount as array.
1588 $eventAmount = array_merge($eventAmount, $additionalParticipantDetails);
1589 $this->assign('amount', $eventAmount);
1592 $sendTemplateParams = [
1593 'groupName' => 'msg_tpl_workflow_event',
1594 'valueName' => 'event_offline_receipt',
1595 'contactId' => $contactID,
1596 'isTest' => !empty($this->_defaultValues
['is_test']),
1597 'PDFFilename' => ts('confirmation') . '.pdf',
1600 // try to send emails only if email id is present
1601 // and the do-not-email option is not checked for that contact
1602 if ($this->_contributorEmail
and !$this->_toDoNotEmail
) {
1603 if (array_key_exists($params['from_email_address'], $this->_fromEmails
['from_email_id'])) {
1604 $receiptFrom = $params['from_email_address'];
1606 $sendTemplateParams['from'] = $receiptFrom;
1607 $sendTemplateParams['toName'] = $this->_contributorDisplayName
;
1608 $sendTemplateParams['toEmail'] = $this->_contributorEmail
;
1609 $sendTemplateParams['cc'] = $this->_fromEmails
['cc'] ??
NULL;
1610 $sendTemplateParams['bcc'] = $this->_fromEmails
['bcc'] ??
NULL;
1613 //send email with pdf invoice
1614 $template = CRM_Core_Smarty
::singleton();
1615 $taxAmt = $template->get_template_vars('dataArray');
1616 $contributionId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
1617 $this->_id
, 'contribution_id', 'participant_id'
1619 $prefixValue = Civi
::settings()->get('contribution_invoice_settings');
1620 $invoicing = $prefixValue['invoicing'] ??
NULL;
1621 if (!empty($taxAmt) && (isset($invoicing) && isset($prefixValue['is_email_pdf']))) {
1622 $sendTemplateParams['isEmailPdf'] = TRUE;
1623 $sendTemplateParams['contributionId'] = $contributionId;
1625 list($mailSent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
1627 $sent[] = $contactID;
1628 foreach ($participants as $ids => $values) {
1629 if ($values->contact_id
== $contactID) {
1630 $values->details
= $params['receipt_text'] ??
NULL;
1631 CRM_Activity_BAO_Activity
::addActivity($values, 'Email');
1637 $notSent[] = $contactID;
1642 // set the participant id if it is not set
1644 $this->_id
= $participants[0]->id
;
1647 return $this->getStatusMsg($params, $sent, $updateStatusMsg, $notSent);
1651 * Set the various IDs relating to custom data types.
1653 public function setCustomDataTypes() {
1654 $customDataType = CRM_Core_OptionGroup
::values('custom_data_type', FALSE, FALSE, FALSE, NULL, 'name');
1655 $this->_roleCustomDataTypeID
= array_search('ParticipantRole', $customDataType);
1656 $this->_eventNameCustomDataTypeID
= array_search('ParticipantEventName', $customDataType);
1657 $this->_eventTypeCustomDataTypeID
= array_search('ParticipantEventType', $customDataType);
1658 $this->assign('roleCustomDataTypeID', $this->_roleCustomDataTypeID
);
1659 $this->assign('eventNameCustomDataTypeID', $this->_eventNameCustomDataTypeID
);
1660 $this->assign('eventTypeCustomDataTypeID', $this->_eventTypeCustomDataTypeID
);
1664 * Get status message
1666 * @param array $params
1668 * @param string $updateStatusMsg
1669 * @param int $notSent
1673 protected function getStatusMsg($params, $sent, $updateStatusMsg, $notSent) {
1675 if (($this->_action
& CRM_Core_Action
::UPDATE
)) {
1676 $statusMsg = ts('Event registration information for %1 has been updated.', [1 => $this->_contributorDisplayName
]);
1677 if (!empty($params['send_receipt']) && count($sent)) {
1678 $statusMsg .= ' ' . ts('A confirmation email has been sent to %1', [1 => $this->_contributorEmail
]);
1681 if ($updateStatusMsg) {
1682 $statusMsg = "{$statusMsg} {$updateStatusMsg}";
1685 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
1686 if ($this->_single
) {
1687 $statusMsg = ts('Event registration for %1 has been added.', [1 => $this->_contributorDisplayName
]);
1688 if (!empty($params['send_receipt']) && count($sent)) {
1689 $statusMsg .= ' ' . ts('A confirmation email has been sent to %1.', [1 => $this->_contributorEmail
]);
1693 $statusMsg = ts('Total Participant(s) added to event: %1.', [1 => count($this->_contactIds
)]);
1694 if (count($notSent) > 0) {
1695 $statusMsg .= ' ' . ts('Email has NOT been sent to %1 contact(s) - communication preferences specify DO NOT EMAIL OR valid Email is NOT present. ', [1 => count($notSent)]);
1697 elseif (isset($params['send_receipt'])) {
1698 $statusMsg .= ' ' . ts('A confirmation email has been sent to ALL participants');
1706 * Build the form object.
1708 * @param \CRM_Event_Form_Participant $form
1711 * @throws \CRM_Core_Exception
1712 * @throws \Exception
1714 public function buildEventFeeForm($form) {
1715 if ($form->_eventId
) {
1716 $form->_isPaidEvent
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $form->_eventId
, 'is_monetary');
1717 if ($form->_isPaidEvent
) {
1718 $form->addElement('hidden', 'hidden_feeblock', 1);
1721 $eventfullMsg = CRM_Event_BAO_Participant
::eventFullMessage($form->_eventId
, $this->getParticipantID());
1722 $form->addElement('hidden', 'hidden_eventFullMsg', $eventfullMsg, ['id' => 'hidden_eventFullMsg']);
1725 if ($form->_isPaidEvent
) {
1726 $params = ['id' => $form->_eventId
];
1727 CRM_Event_BAO_Event
::retrieve($params, $event);
1729 //retrieve custom information
1730 $form->_values
= [];
1731 CRM_Event_Form_Registration
::initEventFee($form, $event['id']);
1732 CRM_Event_Form_Registration_Register
::buildAmount($form, TRUE, $form->_discountId
);
1734 $invoiceSettings = Civi
::settings()->get('contribution_invoice_settings');
1735 $invoicing = $invoiceSettings['invoicing'] ??
NULL;
1736 $totalTaxAmount = 0;
1737 if (!CRM_Utils_System
::isNull(CRM_Utils_Array
::value('line_items', $form->_values
))) {
1738 $lineItem[] = $form->_values
['line_items'];
1739 foreach ($form->_values
['line_items'] as $key => $value) {
1740 $totalTaxAmount = $value['tax_amount'] +
$totalTaxAmount;
1744 $form->assign('totalTaxAmount', $totalTaxAmount);
1746 $form->assign('lineItem', empty($lineItem) ?
FALSE : $lineItem);
1748 if (!empty($form->_values
['discount'])) {
1749 foreach ($form->_values
['discount'] as $key => $value) {
1750 $value = current($value);
1751 $discounts[$key] = $value['name'];
1754 $element = $form->add('select', 'discount_id',
1757 0 => ts('- select -'),
1760 ['class' => "crm-select2"]
1763 if (CRM_Financial_BAO_FinancialType
::isACLFinancialTypeStatus()
1764 && !CRM_Utils_Array
::value('fee', $form->_values
)
1765 && CRM_Utils_Array
::value('snippet', $_REQUEST) == CRM_Core_Smarty
::PRINT_NOFORM
1767 CRM_Core_Session
::setStatus(ts('You do not have all the permissions needed for this page.'), 'Permission Denied', 'error');
1771 CRM_Core_Payment_Form
::buildPaymentForm($form, $form->_paymentProcessor
, FALSE, TRUE, self
::getDefaultPaymentInstrumentId());
1772 if (!$form->_mode
) {
1773 $form->addElement('checkbox', 'record_contribution', ts('Record Payment?'), NULL,
1774 ['onclick' => "return showHideByValue('record_contribution','','payment_information','table-row','radio',false);"]
1776 // Check permissions for financial type first
1777 if (CRM_Financial_BAO_FinancialType
::isACLFinancialTypeStatus()) {
1778 CRM_Financial_BAO_FinancialType
::getAvailableFinancialTypes($financialTypes, $form->_action
);
1781 $financialTypes = CRM_Contribute_PseudoConstant
::financialType();
1784 $form->add('select', 'financial_type_id',
1785 ts('Financial Type'),
1786 ['' => ts('- select -')] +
$financialTypes
1789 $form->add('datepicker', 'receive_date', ts('Received'), [], FALSE, ['time' => TRUE]);
1791 $form->add('select', 'payment_instrument_id',
1792 ts('Payment Method'),
1793 ['' => ts('- select -')] + CRM_Contribute_PseudoConstant
::paymentInstrument(),
1794 FALSE, ['onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);"]
1796 // don't show transaction id in batch update mode
1797 $path = CRM_Utils_System
::currentPath();
1798 $form->assign('showTransactionId', FALSE);
1799 if ($path != 'civicrm/contact/search/basic') {
1800 $form->add('text', 'trxn_id', ts('Transaction ID'));
1801 $form->addRule('trxn_id', ts('Transaction ID already exists in Database.'),
1802 'objectExists', ['CRM_Contribute_DAO_Contribution', $form->_eventId
, 'trxn_id']
1804 $form->assign('showTransactionId', TRUE);
1807 $form->add('select', 'contribution_status_id',
1808 ts('Payment Status'), CRM_Contribute_BAO_Contribution_Utils
::getContributionStatuses('participant')
1811 $form->add('text', 'check_number', ts('Check Number'),
1812 CRM_Core_DAO
::getAttribute('CRM_Contribute_DAO_Contribution', 'check_number')
1815 $form->add('text', 'total_amount', ts('Amount'),
1816 CRM_Core_DAO
::getAttribute('CRM_Contribute_DAO_Contribution', 'total_amount')
1821 $form->add('text', 'amount', ts('Event Fee(s)'));
1823 $form->assign('onlinePendingContributionId', $form->get('onlinePendingContributionId'));
1825 $form->assign('paid', $form->_isPaidEvent
);
1827 $form->addElement('checkbox',
1829 ts('Send Confirmation?'), NULL,
1830 ['onclick' => "showHideByValue('send_receipt','','notice','table-row','radio',false); showHideByValue('send_receipt','','from-email','table-row','radio',false);"]
1833 $form->add('select', 'from_email_address', ts('Receipt From'), $form->_fromEmails
['from_email_id']);
1835 $form->add('textarea', 'receipt_text', ts('Confirmation Message'));
1837 // Retrieve the name and email of the contact - form will be the TO for receipt email ( only if context is not standalone)
1838 if ($form->_context
!= 'standalone') {
1839 if ($form->_contactId
) {
1840 list($form->_contributorDisplayName
,
1841 $form->_contributorEmail
1842 ) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($form->_contactId
);
1843 $form->assign('email', $form->_contributorEmail
);
1846 //show email block for batch update for event
1847 $form->assign('batchEmail', TRUE);
1851 $mailingInfo = Civi
::settings()->get('mailing_backend');
1852 $form->assign('outBound_option', $mailingInfo['outBound_option']);
1853 $form->assign('hasPayment', $form->_paymentId
);
1857 * Extracted code relating to paid events.
1863 * @throws \CiviCRM_API3_Exception
1865 protected function preparePaidEventProcessing($params): array {
1866 $participantStatus = CRM_Event_PseudoConstant
::participantStatus();
1867 $contributionParams = [
1868 'skipCleanMoney' => TRUE,
1869 'revenue_recognition_date' => $this->getRevenueRecognitionDate(),
1872 $additionalParticipantDetails = [];
1874 if ($this->isPaymentOnExistingContribution()) {
1875 $contributionParams['total_amount'] = $this->getParticipantValue('fee_amount');
1877 $params['discount_id'] = NULL;
1878 //re-enter the values for UPDATE mode
1879 $params['fee_level'] = $params['amount_level'] = $this->getParticipantValue('fee_level');
1880 $params['fee_amount'] = $this->getParticipantValue('fee_amount');
1881 if (isset($params['priceSetId'])) {
1882 CRM_Core_Error
::deprecatedFunctionWarning('It seems this line is never hit & can go.');
1883 $lineItem[0] = CRM_Price_BAO_LineItem
::getLineItems($this->_id
);
1885 //also add additional participant's fee level/priceset
1886 if (CRM_Event_BAO_Participant
::isPrimaryParticipant($this->_id
)) {
1887 $additionalIds = CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_id
);
1888 $hasLineItems = CRM_Utils_Array
::value('priceSetId', $params, FALSE);
1889 $additionalParticipantDetails = $this->getFeeDetails($additionalIds, $hasLineItems);
1894 // check that discount_id is set
1895 if (empty($params['discount_id'])) {
1896 $params['discount_id'] = 'null';
1899 //lets carry currency, CRM-4453
1900 $params['fee_currency'] = CRM_Core_Config
::singleton()->defaultCurrency
;
1901 if (!isset($lineItem[0])) {
1904 CRM_Price_BAO_PriceSet
::processAmount($this->_values
['fee'],
1905 $params, $lineItem[0]
1907 //CRM-11529 for quick config backoffice transactions
1908 //when financial_type_id is passed in form, update the
1909 //lineitems with the financial type selected in form
1910 $submittedFinancialType = $params['financial_type_id'] ??
NULL;
1911 $isPaymentRecorded = $params['record_contribution'] ??
NULL;
1912 if ($isPaymentRecorded && $this->_quickConfig
&& $submittedFinancialType) {
1913 foreach ($lineItem[0] as &$values) {
1914 $values['financial_type_id'] = $submittedFinancialType;
1918 $params['fee_level'] = $params['amount_level'];
1919 $contributionParams['total_amount'] = $params['amount'];
1920 if ($this->_quickConfig
&& !empty($params['total_amount']) &&
1921 $params['status_id'] != array_search('Partially paid', $participantStatus)
1923 $params['fee_amount'] = $params['total_amount'];
1927 $params['fee_amount'] = $params['amount'];
1931 if (isset($params['priceSetId'])) {
1932 if (!empty($lineItem[0])) {
1933 $this->set('lineItem', $lineItem);
1935 $this->_lineItem
= $lineItem;
1936 $lineItem = array_merge($lineItem, $additionalParticipantDetails);
1938 $participantCount = [];
1939 foreach ($lineItem as $k) {
1940 foreach ($k as $v) {
1941 if (CRM_Utils_Array
::value('participant_count', $v) > 0) {
1942 $participantCount[] = $v['participant_count'];
1947 if (isset($participantCount)) {
1948 $this->assign('pricesetFieldsCount', $participantCount);
1950 $this->assign('lineItem', empty($lineItem[0]) ||
$this->_quickConfig ?
FALSE : $lineItem);
1953 $this->assign('amount_level', $params['amount_level']);
1955 return [$contributionParams, $lineItem, $additionalParticipantDetails, $params];
1960 * @param $participantRoles
1961 * @param $receiptText
1962 * @param $isPaidEvent
1966 protected function assignEventDetailsToTpl($eventID, $participantRoles, $receiptText, $isPaidEvent) {
1967 //use of the message template below requires variables in different format
1969 $returnProperties = ['event_type_id', 'fee_label', 'start_date', 'end_date', 'is_show_location', 'title'];
1971 //get all event details.
1972 CRM_Core_DAO
::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $eventID, $events, $returnProperties);
1973 $event = $events[$eventID];
1974 unset($event['start_date']);
1975 unset($event['end_date']);
1977 $role = CRM_Event_PseudoConstant
::participantRole();
1979 if (is_array($participantRoles)) {
1980 $selectedRoles = [];
1981 foreach ($participantRoles as $roleId) {
1982 $selectedRoles[] = $role[$roleId];
1984 $event['participant_role'] = implode(', ', $selectedRoles);
1987 $event['participant_role'] = $role[$participantRoles] ??
NULL;
1989 $event['is_monetary'] = $isPaidEvent;
1992 $event['confirm_email_text'] = $receiptText;
1994 $this->assign('event', $event);
1995 $this->assign('isShowLocation', $event['is_show_location']);
1996 if (CRM_Utils_Array
::value('is_show_location', $event) == 1) {
1998 'entity_id' => $eventID,
1999 'entity_table' => 'civicrm_event',
2001 $location = CRM_Core_BAO_Location
::getValues($locationParams, TRUE);
2002 $this->assign('location', $location);
2007 * Process the contribution.
2009 * @param CRM_Core_Form $form
2010 * @param array $params
2011 * @param array $result
2012 * @param int $contactID
2013 * @param bool $pending
2014 * @param array $paymentProcessor
2016 * @return \CRM_Contribute_BAO_Contribution
2018 * @throws \CRM_Core_Exception
2019 * @throws \CiviCRM_API3_Exception
2021 public function processContribution(
2022 &$form, $params, $result, $contactID,
2024 $paymentProcessor = NULL
2026 $transaction = new CRM_Core_Transaction();
2028 $now = date('YmdHis');
2029 $receiptDate = NULL;
2031 if (!empty($form->_values
['event']['is_email_confirm'])) {
2032 $receiptDate = $now;
2035 // CRM-20264: fetch CC type ID and number (last 4 digit) and assign it back to $params
2036 CRM_Contribute_Form_AbstractEditPayment
::formatCreditCardDetails($params);
2039 'contact_id' => $contactID,
2040 'financial_type_id' => !empty($form->_values
['event']['financial_type_id']) ?
$form->_values
['event']['financial_type_id'] : $params['financial_type_id'],
2041 'receive_date' => $now,
2042 'total_amount' => $params['amount'],
2043 'tax_amount' => $params['tax_amount'],
2044 'amount_level' => $params['amount_level'],
2045 'invoice_id' => $params['invoiceID'],
2046 'currency' => $params['currencyID'],
2047 'source' => !empty($params['participant_source']) ?
$params['participant_source'] : $params['description'],
2048 'is_pay_later' => CRM_Utils_Array
::value('is_pay_later', $params, 0),
2049 'campaign_id' => $params['campaign_id'] ??
NULL,
2050 'card_type_id' => $params['card_type_id'] ??
NULL,
2051 'pan_truncation' => $params['pan_truncation'] ??
NULL,
2054 if ($paymentProcessor) {
2055 $contribParams['payment_instrument_id'] = $paymentProcessor['payment_instrument_id'];
2056 $contribParams['payment_processor'] = $paymentProcessor['id'];
2059 if (!$pending && $result) {
2061 'fee_amount' => $result['fee_amount'] ??
NULL,
2062 'trxn_id' => $result['trxn_id'],
2063 'receipt_date' => $receiptDate,
2067 $allStatuses = CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name');
2068 $contribParams['contribution_status_id'] = array_search('Completed', $allStatuses);
2070 $contribParams['contribution_status_id'] = array_search('Pending', $allStatuses);
2073 $contribParams['is_test'] = 0;
2074 if ($form->_action
& CRM_Core_Action
::PREVIEW || CRM_Utils_Array
::value('mode', $params) == 'test') {
2075 $contribParams['is_test'] = 1;
2078 if (!empty($contribParams['invoice_id'])) {
2079 $contribParams['id'] = CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_Contribution',
2080 $contribParams['invoice_id'],
2085 $contribParams['revenue_recognition_date'] = $this->getRevenueRecognitionDate();
2087 //create an contribution address
2088 // The concept of contributeMode is deprecated. Elsewhere we use the function processBillingAddress() - although
2089 // currently that is only inherited by back-office forms.
2090 if ($form->_contributeMode
!= 'notify' && empty($params['is_pay_later'])) {
2091 $contribParams['address_id'] = CRM_Contribute_BAO_Contribution
::createAddress($params, $form->_bltID
);
2094 $contribParams['skipLineItem'] = 1;
2095 $contribParams['skipCleanMoney'] = 1;
2096 // create contribution record
2097 $contribution = CRM_Contribute_BAO_Contribution
::add($contribParams);
2099 CRM_Event_BAO_Participant
::createDiscountTrxn($form->_eventId
, $contribParams, NULL, CRM_Price_BAO_PriceSet
::parseFirstPriceSetValueIDFromParams($params));
2101 // process soft credit / pcp pages
2102 if (!empty($params['pcp_made_through_id'])) {
2103 CRM_Contribute_BAO_ContributionSoft
::formatSoftCreditParams($params, $form);
2104 CRM_Contribute_BAO_ContributionSoft
::processSoftContribution($params, $contribution);
2107 $transaction->commit();
2109 return $contribution;
2113 * Process the participant.
2115 * @param CRM_Core_Form $form
2116 * @param array $params
2117 * @param int $contactID
2119 * @return \CRM_Event_BAO_Participant
2120 * @throws \CRM_Core_Exception
2121 * @throws \CiviCRM_API3_Exception
2123 protected function addParticipant(&$form, $params, $contactID) {
2124 $transaction = new CRM_Core_Transaction();
2126 $participantFields = CRM_Event_DAO_Participant
::fields();
2127 $participantParams = [
2128 'id' => $params['participant_id'] ??
NULL,
2129 'contact_id' => $contactID,
2130 'event_id' => $form->_eventId ?
$form->_eventId
: $params['event_id'],
2131 'status_id' => CRM_Utils_Array
::value('participant_status',
2134 'role_id' => CRM_Utils_Array
::value('participant_role_id', $params) ?
: CRM_Event_BAO_Participant
::getDefaultRoleID(),
2135 'register_date' => $params['register_date'],
2136 'source' => CRM_Utils_String
::ellipsify(
2137 isset($params['participant_source']) ? CRM_Utils_Array
::value('participant_source', $params) : CRM_Utils_Array
::value('description', $params),
2138 $participantFields['participant_source']['maxlength']
2140 'fee_level' => $params['amount_level'] ??
NULL,
2141 'is_pay_later' => CRM_Utils_Array
::value('is_pay_later', $params, 0),
2142 'fee_amount' => $params['fee_amount'] ??
NULL,
2143 'registered_by_id' => $params['registered_by_id'] ??
NULL,
2144 'discount_id' => $params['discount_id'] ??
NULL,
2145 'fee_currency' => $params['currencyID'] ??
NULL,
2146 'campaign_id' => $params['campaign_id'] ??
NULL,
2149 if ($form->_action
& CRM_Core_Action
::PREVIEW || CRM_Utils_Array
::value('mode', $params) == 'test') {
2150 $participantParams['is_test'] = 1;
2153 $participantParams['is_test'] = 0;
2156 if (!empty($form->_params
['note'])) {
2157 $participantParams['note'] = $form->_params
['note'];
2159 elseif (!empty($form->_params
['participant_note'])) {
2160 $participantParams['note'] = $form->_params
['participant_note'];
2163 // reuse id if one already exists for this one (can happen
2164 // with back button being hit etc)
2165 if (!$participantParams['id'] && !empty($params['contributionID'])) {
2166 $pID = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
2167 $params['contributionID'],
2171 $participantParams['id'] = $pID;
2173 $participantParams['discount_id'] = CRM_Core_BAO_Discount
::findSet($form->_eventId
, 'civicrm_event');
2175 if (!$participantParams['discount_id']) {
2176 $participantParams['discount_id'] = "null";
2179 $participant = CRM_Event_BAO_Participant
::create($participantParams);
2181 $transaction->commit();
2183 return $participant;
2187 * Is a payment being made on an existing contribution.
2190 * 1) ideally we should not permit this on this form! Perhaps we don't & this is just cruft.
2191 * 2) _paymentID is the contribution id.
2195 protected function isPaymentOnExistingContribution(): bool {
2196 return ($this->getParticipantID() && $this->_action
& CRM_Core_Action
::UPDATE
) && $this->_paymentId
;
2200 * Get the value for a field relating to the event.
2202 * @param string $fieldName
2205 * @throws \CiviCRM_API3_Exception
2207 protected function getEventValue(string $fieldName) {
2208 if (!isset($this->_event
)) {
2209 $this->_event
= civicrm_api3('Event', 'getsingle', ['id' => $this->_eventId
]);
2211 return $this->_event
[$fieldName];
2215 * Get a value from the existing participant record (applies to edits).
2217 * @param string $fieldName
2220 * @throws \CiviCRM_API3_Exception
2222 protected function getParticipantValue($fieldName) {
2223 if (!$this->participantRecord
) {
2224 $this->participantRecord
= civicrm_api3('Participant', 'getsingle', ['id' => $this->_id
]);
2226 return $this->participantRecord
[$fieldName] ??
$this->participantRecord
['participant_' . $fieldName];
2230 * Get id of participant being edited.
2234 protected function getParticipantID() {
2235 return $this->_id ??
$this->_pId
;
2239 * Get the value for the revenue recognition date field.
2243 * @throws \CiviCRM_API3_Exception
2245 protected function getRevenueRecognitionDate() {
2246 if (Civi
::settings()->get('deferred_revenue_enabled')) {
2247 $eventStartDate = $this->getEventValue('start_date');
2248 if (strtotime($eventStartDate) > strtotime(date('Ymt'))) {
2249 return date('Ymd', strtotime($eventStartDate));
2256 * Store the parameters to create a payment, if approprite, on the form.
2258 * @param array $params
2259 * Params as submitted.
2261 protected function storePaymentCreateParams($params) {
2262 if ('Completed' === CRM_Core_PseudoConstant
::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $params['contribution_status_id'])) {
2263 $this->setCreatePaymentParams([
2264 'total_amount' => $params['total_amount'],
2265 'is_send_contribution_notification' => FALSE,
2266 'payment_instrument_id' => $params['payment_instrument_id'],
2267 'trxn_date' => $params['receive_date'] ??
date('Y-m-d'),
2268 'trxn_id' => $params['trxn_id'],
2269 'pan_truncation' => $params['pan_truncation'] ??
'',
2270 'card_type_id' => $params['card_type_id'] ??
'',
2271 'check_number' => $params['check_number'] ??
'',
2272 'skipCleanMoney' => TRUE,
2278 * Get the event fee info for given participant ids
2279 * either from line item table / participant table.
2281 * @param array $participantIds
2283 * @param bool $hasLineItems
2284 * Do fetch from line items.
2288 public function getFeeDetails($participantIds, $hasLineItems = FALSE) {
2290 if (!is_array($participantIds) ||
empty($participantIds)) {
2295 SELECT participant.id as id,
2296 participant.fee_level as fee_level,
2297 participant.fee_amount as fee_amount';
2298 $from = 'FROM civicrm_participant participant';
2299 if ($hasLineItems) {
2301 lineItem.id as lineId,
2302 lineItem.label as label,
2303 lineItem.qty as qty,
2304 lineItem.unit_price as unit_price,
2305 lineItem.line_total as line_total,
2306 field.label as field_title,
2307 field.html_type as html_type,
2308 field.id as price_field_id,
2309 value.id as price_field_value_id,
2310 value.description as description,
2311 IF( value.count, value.count, 0 ) as participant_count';
2313 INNER JOIN civicrm_line_item lineItem ON ( lineItem.entity_table = 'civicrm_participant'
2314 AND lineItem.entity_id = participant.id )
2315 INNER JOIN civicrm_price_field field ON ( field.id = lineItem.price_field_id )
2316 INNER JOIN civicrm_price_field_value value ON ( value.id = lineItem.price_field_value_id )
2319 $where = 'WHERE participant.id IN ( ' . implode(', ', $participantIds) . ' )';
2320 $query = "$select $from $where";
2322 $feeInfo = CRM_Core_DAO
::executeQuery($query);
2323 $feeProperties = ['fee_level', 'fee_amount'];
2333 'participant_count',
2334 'price_field_value_id',
2337 while ($feeInfo->fetch()) {
2338 if ($hasLineItems) {
2339 foreach ($lineProperties as $property) {
2340 $feeDetails[$feeInfo->id
][$feeInfo->lineId
][$property] = $feeInfo->$property;
2344 foreach ($feeProperties as $property) {
2345 $feeDetails[$feeInfo->id
][$property] = $feeInfo->$property;