3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
32 * @copyright CiviCRM LLC (c) 2004-2019
38 * This class generates form components for processing a participation
41 class CRM_Event_Form_Participant
extends CRM_Contribute_Form_AbstractEditPayment
{
43 public $useLivePageJS = TRUE;
46 * The values for the contribution db object.
53 * The values for the quickconfig for priceset.
57 public $_quickConfig = NULL;
60 * Price Set ID, if the new price set method is used
67 * Array of fields for the price set.
74 * The id of the participation that we are processing.
85 protected $_noteId = NULL;
89 * Use parent $this->contactID
91 * The id of the contact associated with this participation.
99 * Array of event values.
106 * Are we operating in "single mode", i.e. adding / editing only
107 * one participant record, or is this a batch add operation
111 public $_single = FALSE;
114 * If event is paid or unpaid.
117 public $_isPaidEvent;
129 protected $_roleId = NULL;
135 protected $_eventTypeId = NULL;
138 * Participant status Id.
141 protected $_statusId = NULL;
144 * Cache all the participant statuses.
147 protected $_participantStatuses;
153 public $_mode = NULL;
156 * Event ID preselect.
162 * Line Item for Price Set.
165 public $_lineItem = NULL;
168 * Contribution mode for event registration for offline mode.
172 public $_contributeMode = 'direct';
177 * Store id of role custom data type ( option value )
180 protected $_roleCustomDataTypeID;
183 * Store id of event Name custom data type ( option value)
186 protected $_eventNameCustomDataTypeID;
189 * Selected discount id.
192 public $_originalDiscountId = NULL;
198 public $_eventId = NULL;
201 * Id of payment, if any
204 public $_paymentId = NULL;
208 * @todo add explanatory note about this
210 public $_onlinePendingContributionId = NULL;
213 * Explicitly declare the entity api name.
215 public function getDefaultEntity() {
216 return 'Participant';
220 * Default form context used as part of addField()
222 public function getDefaultContext() {
227 * Set variables up before form is built.
230 * @throws \CRM_Core_Exception
232 public function preProcess() {
233 parent
::preProcess();
234 $this->_showFeeBlock
= CRM_Utils_Array
::value('eventId', $_GET);
235 $this->assign('showFeeBlock', FALSE);
236 $this->assign('feeBlockPaid', FALSE);
238 // @todo eliminate this duplication.
239 $this->_contactId
= $this->_contactID
;
240 $this->_eID
= CRM_Utils_Request
::retrieve('eid', 'Positive', $this);
241 $this->_context
= CRM_Utils_Request
::retrieve('context', 'Alphanumeric', $this);
242 $this->assign('context', $this->_context
);
244 if ($this->_contactID
) {
245 $this->setPageTitle(ts('Event Registration for %1', [1 => $this->userDisplayName
]));
248 $this->setPageTitle(ts('Event Registration'));
251 // check the current path, if search based, then dont get participantID
253 $path = CRM_Utils_System
::currentPath();
255 strpos($path, 'civicrm/contact/search') === 0 ||
256 strpos($path, 'civicrm/group/search') === 0
261 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
265 $this->assign('participantId', $this->_id
);
267 $this->_paymentId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
268 $this->_id
, 'id', 'participant_id'
271 $this->assign('hasPayment', $this->_paymentId
);
272 $this->assign('componentId', $this->_id
);
273 $this->assign('component', 'event');
275 // CRM-12615 - Get payment information from the primary registration
276 if ((!$this->_paymentId
) && ($this->_action
== CRM_Core_Action
::UPDATE
)) {
277 $registered_by_id = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant',
278 $this->_id
, 'registered_by_id', 'id'
280 if ($registered_by_id) {
281 $this->_paymentId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
282 $registered_by_id, 'id', 'participant_id'
284 $this->assign('registeredByParticipantId', $registered_by_id);
288 $this->setCustomDataTypes();
291 $this->assign('participantMode', $this->_mode
);
294 if ($this->_showFeeBlock
) {
295 $this->assign('showFeeBlock', TRUE);
296 $isMonetary = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $this->_showFeeBlock
, 'is_monetary');
298 $this->assign('feeBlockPaid', TRUE);
300 return CRM_Event_Form_EventFees
::preProcess($this);
303 //check the mode when this form is called either single or as
305 if ($this->_id ||
$this->_contactId ||
$this->_context
== 'standalone') {
306 $this->_single
= TRUE;
307 $this->assign('urlPath', 'civicrm/contact/view/participant');
308 if (!$this->_id
&& !$this->_contactId
) {
311 'title' => ts('CiviEvent Dashboard'),
312 'url' => CRM_Utils_System
::url('civicrm/event', 'reset=1'),
316 CRM_Utils_System
::appendBreadCrumb($breadCrumbs);
320 //set the appropriate action
321 $context = $this->get('context');
322 $urlString = 'civicrm/contact/search';
323 $this->_action
= CRM_Core_Action
::BASIC
;
326 $urlString = 'civicrm/contact/search/advanced';
327 $this->_action
= CRM_Core_Action
::ADVANCED
;
331 $urlString = 'civicrm/contact/search/builder';
332 $this->_action
= CRM_Core_Action
::PROFILE
;
336 $urlString = 'civicrm/contact/search/basic';
337 $this->_action
= CRM_Core_Action
::BASIC
;
341 $urlString = 'civicrm/contact/search/custom';
342 $this->_action
= CRM_Core_Action
::COPY
;
345 CRM_Contact_Form_Task
::preProcessCommon($this);
347 $this->_single
= FALSE;
348 $this->_contactId
= NULL;
350 //set ajax path, this used for custom data building
351 $this->assign('urlPath', $urlString);
352 $this->assign('urlPathVar', "_qf_Participant_display=true&qfKey={$this->controller->_key}");
355 $this->assign('single', $this->_single
);
358 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'add');
360 $this->assign('action', $this->_action
);
362 // check for edit permission
363 if (!CRM_Core_Permission
::checkActionPermission('CiviEvent', $this->_action
)) {
364 CRM_Core_Error
::fatal(ts('You do not have permission to access this page.'));
367 if ($this->_action
& CRM_Core_Action
::DELETE
) {
368 // check delete permission for contribution
369 if ($this->_id
&& $this->_paymentId
&& !CRM_Core_Permission
::checkActionPermission('CiviContribute', $this->_action
)) {
370 CRM_Core_Error
::fatal(ts("This Participant is linked to a contribution. You must have 'delete in CiviContribute' permission in order to delete this record."));
376 // assign participant id to the template
377 $this->assign('participantId', $this->_id
);
378 $this->_roleId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'role_id');
381 // when fee amount is included in form
382 if (!empty($_POST['hidden_feeblock']) ||
!empty($_POST['send_receipt'])) {
383 CRM_Event_Form_EventFees
::preProcess($this);
384 CRM_Event_Form_EventFees
::buildQuickForm($this);
385 CRM_Event_Form_EventFees
::setDefaultValues($this);
388 // when custom data is included in this page
389 if (!empty($_POST['hidden_custom'])) {
390 $eventId = (int) CRM_Utils_Array
::value('event_id', $_POST);
391 // Custom data of type participant role
392 // Note: Some earlier commits imply $_POST['role_id'] could be a comma separated string,
393 // not sure if that ever really happens
394 if (!empty($_POST['role_id'])) {
395 foreach ($_POST['role_id'] as $roleID) {
396 CRM_Custom_Form_CustomData
::preProcess($this, $this->_roleCustomDataTypeID
, $roleID, 1, 'Participant', $this->_id
);
397 CRM_Custom_Form_CustomData
::buildQuickForm($this);
398 CRM_Custom_Form_CustomData
::setDefaultValues($this);
402 //custom data of type participant event
403 CRM_Custom_Form_CustomData
::preProcess($this, $this->_eventNameCustomDataTypeID
, $eventId, 1, 'Participant', $this->_id
);
404 CRM_Custom_Form_CustomData
::buildQuickForm($this);
405 CRM_Custom_Form_CustomData
::setDefaultValues($this);
407 // custom data of type participant event type
410 $eventTypeId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventId, 'event_type_id', 'id');
412 CRM_Custom_Form_CustomData
::preProcess($this, $this->_eventTypeCustomDataTypeID
, $eventTypeId,
413 1, 'Participant', $this->_id
415 CRM_Custom_Form_CustomData
::buildQuickForm($this);
416 CRM_Custom_Form_CustomData
::setDefaultValues($this);
418 //custom data of type participant, ( we 'null' to reset subType and subName)
419 CRM_Custom_Form_CustomData
::preProcess($this, 'null', 'null', 1, 'Participant', $this->_id
);
420 CRM_Custom_Form_CustomData
::buildQuickForm($this);
421 CRM_Custom_Form_CustomData
::setDefaultValues($this);
424 // CRM-4395, get the online pending contribution id.
425 $this->_onlinePendingContributionId
= NULL;
426 if (!$this->_mode
&& $this->_id
&& ($this->_action
& CRM_Core_Action
::UPDATE
)) {
427 $this->_onlinePendingContributionId
= CRM_Contribute_BAO_Contribution
::checkOnlinePendingContribution($this->_id
,
431 $this->set('onlinePendingContributionId', $this->_onlinePendingContributionId
);
435 * This function sets the default values for the form in edit/view mode
436 * the default values are retrieved from the database
439 * @throws \CRM_Core_Exception
441 public function setDefaultValues() {
442 if ($this->_showFeeBlock
) {
443 return CRM_Event_Form_EventFees
::setDefaultValues($this);
448 if ($this->_action
& CRM_Core_Action
::DELETE
) {
454 $params = ['id' => $this->_id
];
456 CRM_Event_BAO_Participant
::getValues($params, $defaults, $ids);
457 $sep = CRM_Core_DAO
::VALUE_SEPARATOR
;
458 if ($defaults[$this->_id
]['role_id']) {
459 $roleIDs = explode($sep, $defaults[$this->_id
]['role_id']);
461 $this->_contactId
= $defaults[$this->_id
]['contact_id'];
462 $this->_statusId
= $defaults[$this->_id
]['participant_status_id'];
464 //set defaults for note
465 $noteDetails = CRM_Core_BAO_Note
::getNote($this->_id
, 'civicrm_participant');
466 $defaults[$this->_id
]['note'] = array_pop($noteDetails);
468 // Check if this is a primaryParticipant (registered for others) and retrieve additional participants if true (CRM-4859)
469 if (CRM_Event_BAO_Participant
::isPrimaryParticipant($this->_id
)) {
470 $this->assign('additionalParticipants', CRM_Event_BAO_Participant
::getAdditionalParticipants($this->_id
));
473 // Get registered_by contact ID and display_name if participant was registered by someone else (CRM-4859)
474 if (!empty($defaults[$this->_id
]['participant_registered_by_id'])) {
475 $registered_by_contact_id = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant',
476 $defaults[$this->_id
]['participant_registered_by_id'],
479 $this->assign('participant_registered_by_id', $defaults[$this->_id
]['participant_registered_by_id']);
480 $this->assign('registered_by_contact_id', $registered_by_contact_id);
481 $this->assign('registered_by_display_name', CRM_Contact_BAO_Contact
::displayName($registered_by_contact_id));
485 //setting default register date
486 if ($this->_action
== CRM_Core_Action
::ADD
) {
487 $statuses = array_flip(CRM_Event_PseudoConstant
::participantStatus());
488 $defaults[$this->_id
]['status_id'] = CRM_Utils_Array
::value('Registered', $statuses);
489 if (!empty($defaults[$this->_id
]['event_id'])) {
490 $contributionTypeId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event',
491 $defaults[$this->_id
]['event_id'],
494 if ($contributionTypeId) {
495 $defaults[$this->_id
]['financial_type_id'] = $contributionTypeId;
500 $fields["email-{$this->_bltID}"] = 1;
501 $fields['email-Primary'] = 1;
503 if ($this->_contactId
) {
504 CRM_Core_BAO_UFGroup
::setProfileDefaults($this->_contactId
, $fields, $defaults);
507 if (empty($defaults["email-{$this->_bltID}"]) &&
508 !empty($defaults['email-Primary'])
510 $defaults[$this->_id
]["email-{$this->_bltID}"] = $defaults['email-Primary'];
514 $submittedRole = $this->getElementValue('role_id');
515 if (!empty($submittedRole[0])) {
516 $roleID = $submittedRole[0];
518 $submittedEvent = $this->getElementValue('event_id');
519 if (!empty($submittedEvent[0])) {
520 $eventID = $submittedEvent[0];
522 $defaults[$this->_id
]['register_date'] = date('Y-m-d H:i:s');
525 $defaults[$this->_id
]['record_contribution'] = 0;
527 if ($defaults[$this->_id
]['participant_is_pay_later']) {
528 $this->assign('participant_is_pay_later', TRUE);
531 $this->assign('participant_status_id', $defaults[$this->_id
]['participant_status_id']);
532 $eventID = $defaults[$this->_id
]['event_id'];
534 $this->_eventTypeId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventID, 'event_type_id', 'id');
536 $this->_discountId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'discount_id');
537 if ($this->_discountId
) {
538 $this->set('discountId', $this->_discountId
);
542 //assign event and role id, this is needed for Custom data building
543 $sep = CRM_Core_DAO
::VALUE_SEPARATOR
;
544 if (!empty($defaults[$this->_id
]['participant_role_id'])) {
545 $roleIDs = explode($sep, $defaults[$this->_id
]['participant_role_id']);
547 if (isset($_POST['event_id'])) {
548 $eventID = $_POST['event_id'];
552 $eventID = $this->_eID
;
553 //@todo - rationalise the $this->_eID with $POST['event_id'], $this->_eid is set when eid=x is in the url
554 $roleID = CRM_Core_DAO
::getFieldValue(
555 'CRM_Event_DAO_Event',
559 if (empty($roleIDs)) {
560 $roleIDs = (array) $defaults[$this->_id
]['participant_role_id'] = $roleID;
562 $defaults[$this->_id
]['event_id'] = $eventID;
564 if (!empty($eventID)) {
565 $this->_eventTypeId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventID, 'event_type_id', 'id');
567 //these should take precedence so we state them last
568 $urlRoleIDS = CRM_Utils_Request
::retrieve('roles', 'String');
570 $roleIDs = explode(',', $urlRoleIDS);
572 if (isset($roleIDs)) {
573 $defaults[$this->_id
]['role_id'] = implode(',', $roleIDs);
576 if (isset($eventID)) {
577 $this->assign('eventID', $eventID);
578 $this->set('eventId', $eventID);
581 if (isset($this->_eventTypeId
)) {
582 $this->assign('eventTypeID', $this->_eventTypeId
);
585 $this->assign('event_is_test', CRM_Utils_Array
::value('event_is_test', $defaults[$this->_id
]));
586 return $defaults[$this->_id
];
590 * Build the form object.
593 * @throws \CRM_Core_Exception
594 * @throws \CiviCRM_API3_Exception
596 public function buildQuickForm() {
598 $participantStatuses = CRM_Event_PseudoConstant
::participantStatus();
599 $partiallyPaidStatusId = array_search('Partially paid', $participantStatuses);
600 $this->assign('partiallyPaidStatusId', $partiallyPaidStatusId);
602 if ($this->_showFeeBlock
) {
603 return CRM_Event_Form_EventFees
::buildQuickForm($this);
606 //need to assign custom data type to the template
607 $this->assign('customDataType', 'Participant');
609 $this->applyFilter('__ALL__', 'trim');
611 if ($this->_action
& CRM_Core_Action
::DELETE
) {
612 if ($this->_single
) {
613 $additionalParticipant = count(CRM_Event_BAO_Event
::buildCustomProfile($this->_id
,
619 if ($additionalParticipant) {
620 $deleteParticipants = [
621 1 => ts('Delete this participant record along with associated participant record(s).'),
622 2 => ts('Delete only this participant record.'),
624 $this->addRadio('delete_participant', NULL, $deleteParticipants, NULL, '<br />');
625 $this->setDefaults(['delete_participant' => 1]);
626 $this->assign('additionalParticipant', $additionalParticipant);
632 'name' => ts('Delete'),
633 'spacing' => ' ',
638 'name' => ts('Cancel'),
644 if ($this->_single
&& $this->_context
== 'standalone') {
645 $this->addEntityRef('contact_id', ts('Contact'), [
647 'api' => ['extra' => ['email']],
651 $eventFieldParams = [
653 'select' => ['minimumInputLength' => 0],
655 'extra' => ['campaign_id', 'default_role_id', 'event_type_id'],
660 // exclude events which are not monetary when credit card registration is used
661 $eventFieldParams['api']['params']['is_monetary'] = 1;
663 $this->addPaymentProcessorSelect(TRUE, FALSE, FALSE);
665 $element = $this->addEntityRef('event_id', ts('Event'), $eventFieldParams, TRUE);
667 //frozen the field fix for CRM-4171
668 if ($this->_action
& CRM_Core_Action
::UPDATE
&& $this->_id
) {
669 if (CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
670 $this->_id
, 'contribution_id', 'participant_id'
677 //CRM-7362 --add campaigns.
680 $campaignId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'campaign_id');
683 $eventId = CRM_Utils_Request
::retrieve('eid', 'Positive', $this);
685 $campaignId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventId, 'campaign_id');
688 CRM_Campaign_BAO_Campaign
::addCampaign($this, $campaignId);
689 $this->add('datepicker', 'register_date', ts('Registration Date'), [], TRUE, ['time' => TRUE]);
692 $this->assign('entityID', $this->_id
);
695 $this->addSelect('role_id', ['multiple' => TRUE, 'class' => 'huge'], TRUE);
698 $checkCancelledJs = ['onchange' => "return sendNotification( );"];
700 if ($this->_onlinePendingContributionId
) {
701 $cancelledparticipantStatusId = array_search('Cancelled', CRM_Event_PseudoConstant
::participantStatus());
702 $cancelledContributionStatusId = array_search('Cancelled',
703 CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name')
705 $checkCancelledJs = [
706 'onchange' => "checkCancelled( this.value, {$cancelledparticipantStatusId},{$cancelledContributionStatusId});",
709 $participantStatusId = array_search('Pending from pay later',
710 CRM_Event_PseudoConstant
::participantStatus()
712 $contributionStatusId = array_search('Completed',
713 CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name')
715 $confirmJS = ['onclick' => "return confirmStatus( {$participantStatusId}, {$contributionStatusId} );"];
718 // get the participant status names to build special status array which is used to show notification
719 // checkbox below participant status select
720 $participantStatusName = CRM_Event_PseudoConstant
::participantStatus();
721 $notificationStatuses = [
723 'Pending from waitlist',
724 'Pending from approval',
728 // get the required status and then implode only ids
729 $notificationStatusIds = implode(',', array_keys(array_intersect($participantStatusName, $notificationStatuses)));
730 $this->assign('notificationStatusIds', $notificationStatusIds);
732 $this->_participantStatuses
= $statusOptions = CRM_Event_BAO_Participant
::buildOptions('status_id', 'create');
734 // Only show refund status when editing
735 if ($this->_action
& CRM_Core_Action
::ADD
) {
736 $pendingRefundStatusId = array_search('Pending refund', $participantStatusName);
737 if ($pendingRefundStatusId) {
738 unset($statusOptions[$pendingRefundStatusId]);
742 $this->addSelect('status_id', $checkCancelledJs +
[
743 'options' => $statusOptions,
744 'option_url' => 'civicrm/admin/participant_status',
747 $this->addElement('checkbox', 'is_notify', ts('Send Notification'), NULL);
749 $this->addField('source', ['entity' => 'Participant', 'name' => 'source']);
750 $noteAttributes = CRM_Core_DAO
::getAttribute('CRM_Core_DAO_Note');
751 $this->add('textarea', 'note', ts('Notes'), $noteAttributes['note']);
755 'name' => ts('Save'),
760 $path = CRM_Utils_System
::currentPath();
762 'civicrm/contact/search',
763 'civicrm/group/search',
765 if (!in_array($path, $excludeForPaths)) {
768 'name' => ts('Save and New'),
776 'name' => ts('Cancel'),
779 $this->addButtons($buttons);
780 if ($this->_action
== CRM_Core_Action
::VIEW
) {
786 * Add local and global form rules.
790 public function addRules() {
791 $this->addFormRule(['CRM_Event_Form_Participant', 'formRule'], $this);
795 * Global validation rules for the form.
797 * @param array $values
798 * Posted values of the form.
803 * list of errors to be posted back to the form
805 public static function formRule($values, $files, $self) {
806 // If $values['_qf_Participant_next'] is Delete or
807 // $values['event_id'] is empty, then return
808 // instead of proceeding further.
810 if ((CRM_Utils_Array
::value('_qf_Participant_next', $values) == 'Delete') ||
811 (!$values['event_id'])
818 if (!empty($values['payment_processor_id'])) {
819 // make sure that payment instrument values (e.g. credit card number and cvv) are valid
820 CRM_Core_Payment_Form
::validatePaymentInstrument($values['payment_processor_id'], $values, $errorMsg, NULL);
823 if (!empty($values['record_contribution'])) {
824 if (empty($values['financial_type_id'])) {
825 $errorMsg['financial_type_id'] = ts('Please enter the associated Financial Type');
827 if (empty($values['payment_instrument_id'])) {
828 $errorMsg['payment_instrument_id'] = ts('Payment Method is a required field.');
830 if (!empty($values['priceSetId'])) {
831 CRM_Price_BAO_PriceField
::priceSetValidation($values['priceSetId'], $values, $errorMsg);
835 // validate contribution status for 'Failed'.
836 if ($self->_onlinePendingContributionId
&& !empty($values['record_contribution']) &&
837 (CRM_Utils_Array
::value('contribution_status_id', $values) ==
838 array_search('Failed', CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name'))
841 $errorMsg['contribution_status_id'] = ts('Please select a valid payment status before updating.');
844 // do the amount validations.
845 //skip for update mode since amount is freeze, CRM-6052
846 if ((!$self->_id
&& empty($values['total_amount']) &&
847 empty($self->_values
['line_items'])
849 ($self->_id
&& !$self->_paymentId
&& isset($self->_values
['line_items']) && is_array($self->_values
['line_items']))
851 if ($priceSetId = CRM_Utils_Array
::value('priceSetId', $values)) {
852 CRM_Price_BAO_PriceField
::priceSetValidation($priceSetId, $values, $errorMsg, TRUE);
855 // For single additions - show validation error if the contact has already been registered
857 if ($self->_single
&& ($self->_action
& CRM_Core_Action
::ADD
)) {
858 if ($self->_context
== 'standalone') {
859 $contactId = CRM_Utils_Array
::value('contact_id', $values);
862 $contactId = $self->_contactId
;
865 $eventId = CRM_Utils_Array
::value('event_id', $values);
867 $event = new CRM_Event_DAO_Event();
868 $event->id
= $eventId;
871 if (!$event->allow_same_participant_emails
&& !empty($contactId) && !empty($eventId)) {
872 $cancelledStatusID = CRM_Core_PseudoConstant
::getKey('CRM_Event_BAO_Participant', 'status_id', 'Cancelled');
873 $dupeCheck = new CRM_Event_BAO_Participant();
874 $dupeCheck->contact_id
= $contactId;
875 $dupeCheck->event_id
= $eventId;
876 $dupeCheck->whereAdd("status_id != {$cancelledStatusID} ");
877 $dupeCheck->find(TRUE);
878 if (!empty($dupeCheck->id
)) {
879 $errorMsg['event_id'] = ts("This contact has already been assigned to this event.");
883 return CRM_Utils_Array
::crmIsEmptyArray($errorMsg) ?
TRUE : $errorMsg;
887 * Process the form submission.
889 public function postProcess() {
890 // get the submitted form values.
891 $params = $this->controller
->exportValues($this->_name
);
893 if ($this->_action
& CRM_Core_Action
::DELETE
) {
894 if (CRM_Utils_Array
::value('delete_participant', $params) == 2) {
895 $additionalId = (CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_id
));
896 $participantLinks = (CRM_Event_BAO_Participant
::getAdditionalParticipantUrl($additionalId));
898 if (CRM_Utils_Array
::value('delete_participant', $params) == 1) {
899 $additionalIds = CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_id
);
900 foreach ($additionalIds as $value) {
901 CRM_Event_BAO_Participant
::deleteParticipant($value);
904 CRM_Event_BAO_Participant
::deleteParticipant($this->_id
);
905 CRM_Core_Session
::setStatus(ts('Selected participant was deleted successfully.'), ts('Record Deleted'), 'success');
906 if (!empty($participantLinks)) {
907 $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;
908 CRM_Core_Session
::setStatus($status, ts('Group Payment Deleted'));
912 // When adding a single contact, the formRule prevents you from adding duplicates
913 // (See above in formRule()). When adding more than one contact, the duplicates are
914 // removed automatically and the user receives one notification.
915 if ($this->_action
& CRM_Core_Action
::ADD
) {
916 $event_id = $this->_eventId
;
917 if (empty($event_id) && !empty($params['event_id'])) {
918 $event_id = $params['event_id'];
920 if (!$this->_single
&& !empty($event_id)) {
921 $duplicateContacts = 0;
922 foreach ($this->_contactIds
as $k => $dupeCheckContactId) {
923 // Eliminate contacts that have already been assigned to this event.
924 $dupeCheck = new CRM_Event_BAO_Participant();
925 $dupeCheck->contact_id
= $dupeCheckContactId;
926 $dupeCheck->event_id
= $event_id;
927 $dupeCheck->find(TRUE);
928 if (!empty($dupeCheck->id
)) {
929 $duplicateContacts++
;
930 unset($this->_contactIds
[$k]);
933 if ($duplicateContacts > 0) {
935 "%1 contacts have already been assigned to this event. They were not added a second time.",
936 [1 => $duplicateContacts]
938 CRM_Core_Session
::setStatus($msg);
940 if (count($this->_contactIds
) == 0) {
941 CRM_Core_Session
::setStatus(ts("No participants were added."));
944 // We have to re-key $this->_contactIds so each contact has the same
945 // key as their corresponding record in the $participants array that
946 // will be created below.
947 $this->_contactIds
= array_values($this->_contactIds
);
951 $statusMsg = $this->submit($params);
952 CRM_Core_Session
::setStatus($statusMsg, ts('Saved'), 'success');
953 $session = CRM_Core_Session
::singleton();
954 $buttonName = $this->controller
->getButtonName();
955 if ($this->_context
== 'standalone') {
956 if ($buttonName == $this->getButtonName('upload', 'new')) {
957 $urlParams = 'reset=1&action=add&context=standalone';
959 $urlParams .= '&mode=' . $this->_mode
;
962 $urlParams .= '&eid=' . $this->_eID
;
964 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/participant/add', $urlParams));
967 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/contact/view',
968 "reset=1&cid={$this->_contactId}&selectedChild=participant"
972 elseif ($buttonName == $this->getButtonName('upload', 'new')) {
973 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/contact/view/participant',
974 "reset=1&action=add&context={$this->_context}&cid={$this->_contactId}"
982 * @param array $params
985 * @throws \CRM_Core_Exception
986 * @throws \CiviCRM_API3_Exception
988 public function submit($params) {
989 $participantStatus = CRM_Event_PseudoConstant
::participantStatus();
990 // set the contact, when contact is selected
991 if (!empty($params['contact_id'])) {
992 $this->_contactID
= $this->_contactId
= $params['contact_id'];
994 if ($this->_priceSetId
&& $isQuickConfig = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId
, 'is_quick_config')) {
995 $this->_quickConfig
= $isQuickConfig;
999 $params['id'] = $this->_id
;
1002 $config = CRM_Core_Config
::singleton();
1003 if (isset($params['total_amount'])) {
1004 $params['total_amount'] = CRM_Utils_Rule
::cleanMoney($params['total_amount']);
1006 if ($this->_isPaidEvent
) {
1008 $contributionParams = ['skipCleanMoney' => TRUE];
1010 $additionalParticipantDetails = [];
1011 if (Civi
::settings()->get('deferred_revenue_enabled')) {
1012 $eventStartDate = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $this->_eventId
, 'start_date');
1013 if (strtotime($eventStartDate) > strtotime(date('Ymt'))) {
1014 $contributionParams['revenue_recognition_date'] = date('Ymd', strtotime($eventStartDate));
1017 if (($this->_id
&& $this->_action
& CRM_Core_Action
::UPDATE
) && $this->_paymentId
) {
1018 $participantBAO = new CRM_Event_BAO_Participant();
1019 $participantBAO->id
= $this->_id
;
1020 $participantBAO->find(TRUE);
1021 $contributionParams['total_amount'] = $participantBAO->fee_amount
;
1023 $params['discount_id'] = NULL;
1024 //re-enter the values for UPDATE mode
1025 $params['fee_level'] = $params['amount_level'] = $participantBAO->fee_level
;
1026 $params['fee_amount'] = $participantBAO->fee_amount
;
1027 if (isset($params['priceSetId'])) {
1028 $lineItem[0] = CRM_Price_BAO_LineItem
::getLineItems($this->_id
);
1030 //also add additional participant's fee level/priceset
1031 if (CRM_Event_BAO_Participant
::isPrimaryParticipant($this->_id
)) {
1032 $additionalIds = CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_id
);
1033 $hasLineItems = CRM_Utils_Array
::value('priceSetId', $params, FALSE);
1034 $additionalParticipantDetails = CRM_Event_BAO_Participant
::getFeeDetails($additionalIds,
1041 // check that discount_id is set
1042 if (empty($params['discount_id'])) {
1043 $params['discount_id'] = 'null';
1046 //lets carry currency, CRM-4453
1047 $params['fee_currency'] = $config->defaultCurrency
;
1048 if (!isset($lineItem[0])) {
1051 CRM_Price_BAO_PriceSet
::processAmount($this->_values
['fee'],
1052 $params, $lineItem[0]
1054 //CRM-11529 for quick config backoffice transactions
1055 //when financial_type_id is passed in form, update the
1056 //lineitems with the financial type selected in form
1057 $submittedFinancialType = CRM_Utils_Array
::value('financial_type_id', $params);
1058 $isPaymentRecorded = CRM_Utils_Array
::value('record_contribution', $params);
1059 if ($isPaymentRecorded && $this->_quickConfig
&& $submittedFinancialType) {
1060 foreach ($lineItem[0] as &$values) {
1061 $values['financial_type_id'] = $submittedFinancialType;
1065 $params['fee_level'] = $params['amount_level'];
1066 $contributionParams['total_amount'] = $params['amount'];
1067 if ($this->_quickConfig
&& !empty($params['total_amount']) &&
1068 $params['status_id'] != array_search('Partially paid', $participantStatus)
1070 $params['fee_amount'] = $params['total_amount'];
1074 $params['fee_amount'] = $params['amount'];
1078 if (isset($params['priceSetId'])) {
1079 if (!empty($lineItem[0])) {
1080 $this->set('lineItem', $lineItem);
1082 $this->_lineItem
= $lineItem;
1083 $lineItem = array_merge($lineItem, $additionalParticipantDetails);
1085 $participantCount = [];
1086 foreach ($lineItem as $k) {
1087 foreach ($k as $v) {
1088 if (CRM_Utils_Array
::value('participant_count', $v) > 0) {
1089 $participantCount[] = $v['participant_count'];
1094 if (isset($participantCount)) {
1095 $this->assign('pricesetFieldsCount', $participantCount);
1097 $this->assign('lineItem', empty($lineItem[0]) ||
$this->_quickConfig ?
FALSE : $lineItem);
1100 $this->assign('amount_level', $params['amount_level']);
1104 $this->_params
= $params;
1105 parent
::beginPostProcess();
1107 if (isset($params['amount'])) {
1108 $amountOwed = $params['amount'];
1109 unset($params['amount']);
1111 $params['contact_id'] = $this->_contactId
;
1113 // overwrite actual payment amount if entered
1114 if (!empty($params['total_amount'])) {
1115 $contributionParams['total_amount'] = CRM_Utils_Array
::value('total_amount', $params);
1118 // Retrieve the name and email of the current user - this will be the FROM for the receipt email
1119 $userName = CRM_Core_Session
::singleton()->getLoggedInContactDisplayName();
1121 if ($this->_contactId
) {
1122 list($this->_contributorDisplayName
, $this->_contributorEmail
, $this->_toDoNotEmail
) = CRM_Contact_BAO_Contact
::getContactDetails($this->_contactId
);
1125 //modify params according to parameter used in create
1126 //participant method (addParticipant)
1127 $this->_params
['participant_status_id'] = $params['status_id'];
1128 $this->_params
['participant_role_id'] = is_array($params['role_id']) ?
$params['role_id'] : explode(',', $params['role_id']);
1129 $this->_params
['participant_register_date'] = $params['register_date'];
1130 $roleIdWithSeparator = implode(CRM_Core_DAO
::VALUE_SEPARATOR
, $this->_params
['participant_role_id']);
1132 $now = date('YmdHis');
1135 if (!$this->_isPaidEvent
) {
1136 CRM_Core_Error
::fatal(ts('Selected Event is not Paid Event '));
1140 = CRM_Core_DAO
::getFieldValue(
1141 'CRM_Event_DAO_Event',
1142 $params['event_id'],
1146 // set source if not set
1147 if (empty($params['source'])) {
1148 $this->_params
['participant_source'] = ts('Offline Registration for Event: %2 by: %1', [
1154 $this->_params
['participant_source'] = $params['source'];
1156 $this->_params
['description'] = $this->_params
['participant_source'];
1158 $this->_paymentProcessor
= CRM_Financial_BAO_PaymentProcessor
::getPayment($this->_params
['payment_processor_id'],
1163 // set email for primary location.
1164 $fields['email-Primary'] = 1;
1165 $params['email-Primary'] = $params["email-{$this->_bltID}"] = $this->_contributorEmail
;
1167 $params['register_date'] = $now;
1169 // now set the values for the billing location.
1170 foreach ($this->_fields
as $name => $dontCare) {
1174 // also add location name to the array
1175 $params["address_name-{$this->_bltID}"]
1176 = CRM_Utils_Array
::value('billing_first_name', $params) . ' ' .
1177 CRM_Utils_Array
::value('billing_middle_name', $params) . ' ' .
1178 CRM_Utils_Array
::value('billing_last_name', $params);
1180 $params["address_name-{$this->_bltID}"] = trim($params["address_name-{$this->_bltID}"]);
1181 $fields["address_name-{$this->_bltID}"] = 1;
1182 $fields["email-{$this->_bltID}"] = 1;
1183 $ctype = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId
, 'contact_type');
1185 $nameFields = ['first_name', 'middle_name', 'last_name'];
1187 foreach ($nameFields as $name) {
1189 if (array_key_exists("billing_$name", $params)) {
1190 $params[$name] = $params["billing_{$name}"];
1191 $params['preserveDBName'] = TRUE;
1194 $contactID = CRM_Contact_BAO_Contact
::createProfileContact($params, $fields, $this->_contactId
, NULL, NULL, $ctype);
1197 if (!empty($this->_params
['participant_role_id'])) {
1198 $customFieldsRole = [];
1199 foreach ($this->_params
['participant_role_id'] as $roleKey) {
1200 $customFieldsRole = CRM_Utils_Array
::crmArrayMerge(CRM_Core_BAO_CustomField
::getFields('Participant',
1201 FALSE, FALSE, $roleKey, $this->_roleCustomDataTypeID
), $customFieldsRole);
1203 $customFieldsEvent = CRM_Core_BAO_CustomField
::getFields('Participant',
1206 CRM_Utils_Array
::value('event_id', $params),
1207 $this->_eventNameCustomDataTypeID
1209 $customFieldsEventType = CRM_Core_BAO_CustomField
::getFields('Participant',
1212 $this->_eventTypeId
,
1213 $this->_eventTypeCustomDataTypeID
1215 $customFields = CRM_Utils_Array
::crmArrayMerge($customFieldsRole,
1216 CRM_Core_BAO_CustomField
::getFields('Participant', FALSE, FALSE, NULL, NULL, TRUE)
1218 $customFields = CRM_Utils_Array
::crmArrayMerge($customFieldsEvent, $customFields);
1219 $customFields = CRM_Utils_Array
::crmArrayMerge($customFieldsEventType, $customFields);
1221 $params['custom'] = CRM_Core_BAO_CustomField
::postProcess($params, $this->_id
, $this->getDefaultEntity());
1224 //do cleanup line items if participant edit the Event Fee.
1225 if (($this->_lineItem ||
!isset($params['proceSetId'])) && !$this->_paymentId
&& $this->_id
) {
1226 CRM_Price_BAO_LineItem
::deleteLineItems($this->_id
, 'civicrm_participant');
1230 // add all the additional payment params we need
1231 $this->_params
= $this->prepareParamsForPaymentProcessor($this->_params
);
1232 $this->_params
['amount'] = $params['fee_amount'];
1233 $this->_params
['amount_level'] = $params['amount_level'];
1234 $this->_params
['currencyID'] = $config->defaultCurrency
;
1235 $this->_params
['invoiceID'] = md5(uniqid(rand(), TRUE));
1237 // at this point we've created a contact and stored its address etc
1238 // all the payment processors expect the name and address to be in the
1239 // so we copy stuff over to first_name etc.
1240 $paymentParams = $this->_params
;
1241 if (!empty($this->_params
['send_receipt'])) {
1242 $paymentParams['email'] = $this->_contributorEmail
;
1245 // The only reason for merging in the 'contact_id' rather than ensuring it is set
1246 // is that this patch is being done around the time of the stable release
1247 // so more conservative approach is called for.
1248 // In fact the use of $params and $this->_params & $this->_contactId vs $contactID
1249 // needs rationalising.
1250 $mapParams = array_merge(['contact_id' => $contactID], $this->_params
);
1251 CRM_Core_Payment_Form
::mapParams($this->_bltID
, $mapParams, $paymentParams, TRUE);
1253 $payment = $this->_paymentProcessor
['object'];
1255 // CRM-15622: fix for incorrect contribution.fee_amount
1256 $paymentParams['fee_amount'] = NULL;
1258 $result = $payment->doPayment($paymentParams);
1260 catch (\Civi\Payment\Exception\PaymentProcessorException
$e) {
1261 // @todo un comment the following line out when we are creating a contribution before we get to this point
1262 // see dev/financial#53 about ensuring we create a pending contribution before we try processing payment
1263 // CRM_Contribute_BAO_Contribution::failPayment($contributionID);
1264 CRM_Core_Session
::singleton()->setStatus($e->getMessage());
1265 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/contact/view/participant',
1266 "reset=1&action=add&cid={$this->_contactId}&context=participant&mode={$this->_mode}"
1271 $this->_params
= array_merge($this->_params
, $result);
1274 $this->_params
['receive_date'] = $now;
1276 if (!empty($this->_params
['send_receipt'])) {
1277 $this->_params
['receipt_date'] = $now;
1280 $this->_params
['receipt_date'] = NULL;
1283 $this->set('params', $this->_params
);
1284 $this->assign('trxn_id', $result['trxn_id']);
1285 $this->assign('receive_date', $this->_params
['receive_date']);
1287 //add contribution record
1288 $this->_params
['financial_type_id']
1289 = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'financial_type_id');
1290 $this->_params
['mode'] = $this->_mode
;
1292 //add contribution record
1293 $contributions[] = $contribution = CRM_Event_Form_Registration_Confirm
::processContribution(
1294 $this, $this->_params
,
1295 $result, $contactID,
1297 $this->_paymentProcessor
1300 // add participant record
1302 if (!empty($this->_params
['role_id']) && is_array($this->_params
['role_id'])) {
1303 $this->_params
['role_id'] = implode(CRM_Core_DAO
::VALUE_SEPARATOR
,
1304 $this->_params
['role_id']
1308 //CRM-15372 patch to fix fee amount replacing amount
1309 $this->_params
['fee_amount'] = $this->_params
['amount'];
1311 $participants[] = CRM_Event_Form_Registration
::addParticipant($this, $contactID);
1313 //add custom data for participant
1314 CRM_Core_BAO_CustomValueTable
::postProcess($this->_params
,
1315 'civicrm_participant',
1316 $participants[0]->id
,
1319 //add participant payment
1320 $paymentParticipant = [
1321 'participant_id' => $participants[0]->id
,
1322 'contribution_id' => $contribution->id
,
1325 CRM_Event_BAO_ParticipantPayment
::create($paymentParticipant);
1326 $this->_contactIds
[] = $this->_contactId
;
1330 if ($this->_single
) {
1331 if ($params['role_id']) {
1332 $params['role_id'] = $roleIdWithSeparator;
1335 $params['role_id'] = 'NULL';
1337 $participants[] = CRM_Event_BAO_Participant
::create($params);
1340 foreach ($this->_contactIds
as $contactID) {
1341 $commonParams = $params;
1342 $commonParams['contact_id'] = $contactID;
1343 if ($commonParams['role_id']) {
1344 $commonParams['role_id'] = $commonParams['role_id'] = str_replace(',', CRM_Core_DAO
::VALUE_SEPARATOR
, $params['role_id']);
1347 $commonParams['role_id'] = 'NULL';
1349 $participants[] = CRM_Event_BAO_Participant
::create($commonParams);
1353 if (isset($params['event_id'])) {
1354 $eventTitle = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event',
1355 $params['event_id'],
1360 if ($this->_single
) {
1361 $this->_contactIds
[] = $this->_contactId
;
1364 $contributions = [];
1365 if (!empty($params['record_contribution'])) {
1366 if (!empty($params['id'])) {
1367 if ($this->_onlinePendingContributionId
) {
1368 $ids['contribution'] = $this->_onlinePendingContributionId
;
1371 $ids['contribution'] = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
1378 unset($params['note']);
1380 //build contribution params
1381 if (!$this->_onlinePendingContributionId
) {
1382 if (empty($params['source'])) {
1383 $contributionParams['source'] = ts('%1 : Offline registration (by %2)', [
1389 $contributionParams['source'] = $params['source'];
1393 $contributionParams['currency'] = $config->defaultCurrency
;
1394 $contributionParams['non_deductible_amount'] = 'null';
1395 $contributionParams['receipt_date'] = !empty($params['send_receipt']) ? CRM_Utils_Array
::value('receive_date', $params) : 'null';
1396 $contributionParams['contact_id'] = $this->_contactID
;
1397 $contributionParams['receive_date'] = CRM_Utils_Array
::value('receive_date', $params, 'null');
1399 $recordContribution = [
1400 'financial_type_id',
1401 'payment_instrument_id',
1403 'contribution_status_id',
1410 foreach ($recordContribution as $f) {
1411 $contributionParams[$f] = CRM_Utils_Array
::value($f, $this->_params
);
1412 if ($f == 'trxn_id') {
1413 $this->assign('trxn_id', $contributionParams[$f]);
1417 //insert financial type name in receipt.
1418 $this->assign('financialTypeName', CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_FinancialType',
1419 $contributionParams['financial_type_id']));
1421 $this->assign('contributionTypeName', CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_FinancialType', $contributionParams['financial_type_id']));
1422 $contributionParams['skipLineItem'] = 1;
1424 $contributionParams['contribution_mode'] = 'participant';
1425 $contributionParams['participant_id'] = $this->_id
;
1427 // Set is_pay_later flag for back-office offline Pending status contributions
1428 if ($contributionParams['contribution_status_id'] == CRM_Core_PseudoConstant
::getKey('CRM_Contribute_DAO_Contribution', 'contribution_status_id', 'Pending')) {
1429 $contributionParams['is_pay_later'] = 1;
1431 elseif ($contributionParams['contribution_status_id'] == CRM_Core_PseudoConstant
::getKey('CRM_Contribute_DAO_Contribution', 'contribution_status_id', 'Completed')) {
1432 $contributionParams['is_pay_later'] = 0;
1435 if ($params['status_id'] == array_search('Partially paid', $participantStatus)) {
1436 if (!$amountOwed && $this->_action
& CRM_Core_Action
::UPDATE
) {
1437 $amountOwed = $params['fee_amount'];
1440 // if multiple participants are link, consider contribution total amount as the amount Owed
1441 if ($this->_id
&& CRM_Event_BAO_Participant
::isPrimaryParticipant($this->_id
)) {
1442 $amountOwed = CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_Contribution',
1443 $ids['contribution'],
1448 // CRM-13964 partial_payment_total
1449 if ($amountOwed > $params['total_amount']) {
1451 $contributionParams['partial_payment_total'] = $amountOwed;
1452 // the actual amount paid
1453 $contributionParams['partial_amount_to_pay'] = $params['total_amount'];
1457 if (CRM_Utils_Array
::value('tax_amount', $this->_params
)) {
1458 $contributionParams['tax_amount'] = $this->_params
['tax_amount'];
1461 if ($this->_single
) {
1465 $contributions[] = CRM_Contribute_BAO_Contribution
::create($contributionParams, $ids);
1469 foreach ($this->_contactIds
as $contactID) {
1470 $contributionParams['contact_id'] = $contactID;
1471 $contributions[] = CRM_Contribute_BAO_Contribution
::create($contributionParams, $ids);
1475 //insert payment record for this participation
1476 if (empty($ids['contribution'])) {
1477 foreach ($this->_contactIds
as $num => $contactID) {
1478 $ppDAO = new CRM_Event_DAO_ParticipantPayment();
1479 $ppDAO->participant_id
= $participants[$num]->id
;
1480 $ppDAO->contribution_id
= $contributions[$num]->id
;
1486 if ($this->_params
['discount_id']) {
1487 CRM_Event_BAO_Participant
::createDiscountTrxn(
1489 $contributionParams,
1491 CRM_Price_BAO_PriceSet
::parseFirstPriceSetValueIDFromParams($this->_params
)
1497 // also store lineitem stuff here
1498 if ((($this->_lineItem
& $this->_action
& CRM_Core_Action
::ADD
) ||
1499 ($this->_lineItem
&& CRM_Core_Action
::UPDATE
&& !$this->_paymentId
))
1501 foreach ($this->_contactIds
as $num => $contactID) {
1502 foreach ($this->_lineItem
as $key => $value) {
1503 if (is_array($value) && $value != 'skip') {
1504 foreach ($value as $lineKey => $line) {
1505 //10117 update the line items for participants if contribution amount is recorded
1506 if ($this->_quickConfig
&& !empty($params['total_amount']) &&
1507 ($params['status_id'] != array_search('Partially paid', $participantStatus))
1509 $line['unit_price'] = $line['line_total'] = $params['total_amount'];
1510 if (!empty($params['tax_amount'])) {
1511 $line['unit_price'] = $line['unit_price'] - $params['tax_amount'];
1512 $line['line_total'] = $line['line_total'] - $params['tax_amount'];
1515 $lineItem[$this->_priceSetId
][$lineKey] = $line;
1517 CRM_Price_BAO_LineItem
::processPriceSet($participants[$num]->id
, $lineItem, CRM_Utils_Array
::value($num, $contributions, NULL), 'civicrm_participant');
1518 CRM_Contribute_BAO_Contribution
::addPayments($contributions);
1524 $updateStatusMsg = NULL;
1525 //send mail when participant status changed, CRM-4326
1526 if ($this->_id
&& $this->_statusId
&&
1527 $this->_statusId
!= CRM_Utils_Array
::value('status_id', $params) && !empty($params['is_notify'])
1530 $updateStatusMsg = CRM_Event_BAO_Participant
::updateStatusMessage($this->_id
,
1531 $params['status_id'],
1538 if (!empty($params['send_receipt'])) {
1539 if (array_key_exists($params['from_email_address'], $this->_fromEmails
['from_email_id'])) {
1540 $receiptFrom = $params['from_email_address'];
1543 $this->assign('module', 'Event Registration');
1544 //use of the message template below requires variables in different format
1545 $event = $events = [];
1546 $returnProperties = ['event_type_id', 'fee_label', 'start_date', 'end_date', 'is_show_location', 'title'];
1548 //get all event details.
1549 CRM_Core_DAO
::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $params['event_id'], $events, $returnProperties);
1550 $event = $events[$params['event_id']];
1551 unset($event['start_date']);
1552 unset($event['end_date']);
1554 $role = CRM_Event_PseudoConstant
::participantRole();
1555 $participantRoles = CRM_Utils_Array
::value('role_id', $params);
1556 if (is_array($participantRoles)) {
1557 $selectedRoles = [];
1558 foreach ($participantRoles as $roleId) {
1559 $selectedRoles[] = $role[$roleId];
1561 $event['participant_role'] = implode(', ', $selectedRoles);
1564 $event['participant_role'] = CRM_Utils_Array
::value($participantRoles, $role);
1566 $event['is_monetary'] = $this->_isPaidEvent
;
1568 if ($params['receipt_text']) {
1569 $event['confirm_email_text'] = $params['receipt_text'];
1572 $this->assign('isAmountzero', 1);
1573 $this->assign('event', $event);
1575 $this->assign('isShowLocation', $event['is_show_location']);
1576 if (CRM_Utils_Array
::value('is_show_location', $event) == 1) {
1578 'entity_id' => $params['event_id'],
1579 'entity_table' => 'civicrm_event',
1581 $location = CRM_Core_BAO_Location
::getValues($locationParams, TRUE);
1582 $this->assign('location', $location);
1585 $status = CRM_Event_PseudoConstant
::participantStatus();
1586 if ($this->_isPaidEvent
) {
1587 $paymentInstrument = CRM_Contribute_PseudoConstant
::paymentInstrument();
1588 if (!$this->_mode
) {
1589 if (isset($params['payment_instrument_id'])) {
1590 $this->assign('paidBy',
1591 CRM_Utils_Array
::value($params['payment_instrument_id'],
1598 $this->assign('totalAmount', $contributionParams['total_amount']);
1599 if (isset($contributionParams['partial_payment_total'])) {
1601 $balanceAmount = $contributionParams['partial_payment_total'] - $contributionParams['partial_amount_to_pay'];
1602 $this->assign('balanceAmount', $balanceAmount);
1604 $this->assign('isPrimary', 1);
1605 $this->assign('checkNumber', CRM_Utils_Array
::value('check_number', $params));
1608 $this->assignBillingName($params);
1609 $this->assign('address', CRM_Utils_Address
::getFormattedBillingAddressFieldsFromParameters(
1614 $date = CRM_Utils_Date
::format($params['credit_card_exp_date']);
1615 $date = CRM_Utils_Date
::mysqlToIso($date);
1616 $this->assign('credit_card_exp_date', $date);
1617 $this->assign('credit_card_number',
1618 CRM_Utils_System
::mungeCreditCard($params['credit_card_number'])
1620 $this->assign('credit_card_type', $params['credit_card_type']);
1621 // The concept of contributeMode is deprecated.
1622 $this->assign('contributeMode', 'direct');
1623 $this->assign('isAmountzero', 0);
1624 $this->assign('is_pay_later', 0);
1625 $this->assign('isPrimary', 1);
1628 $this->assign('register_date', $params['register_date']);
1629 if (isset($params['receive_date'])) {
1630 $this->assign('receive_date', $params['receive_date']);
1633 $participant = [['participant_id', '=', $participants[0]->id
, 0, 0]];
1634 // check whether its a test drive ref CRM-3075
1635 if (!empty($this->_defaultValues
['is_test'])) {
1636 $participant[] = ['participant_test', '=', 1, 0, 0];
1640 //format submitted data
1641 foreach ($params['custom'] as $fieldID => $values) {
1642 foreach ($values as $fieldValue) {
1643 $isPublic = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_CustomGroup', $fieldValue['custom_group_id'], 'is_public');
1645 $customFields[$fieldID]['id'] = $fieldID;
1646 $formattedValue = CRM_Core_BAO_CustomField
::displayValue($fieldValue['value'], $fieldID, $participants[0]->id
);
1647 $customGroup[$customFields[$fieldID]['groupTitle']][$customFields[$fieldID]['label']] = str_replace(' ', '', $formattedValue);
1652 foreach ($this->_contactIds
as $num => $contactID) {
1653 // Retrieve the name and email of the contact - this will be the TO for receipt email
1654 list($this->_contributorDisplayName
, $this->_contributorEmail
, $this->_toDoNotEmail
) = CRM_Contact_BAO_Contact
::getContactDetails($contactID);
1656 $this->_contributorDisplayName
= ($this->_contributorDisplayName
== ' ') ?
$this->_contributorEmail
: $this->_contributorDisplayName
;
1658 $waitStatus = CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Waiting'");
1659 if ($waitingStatus = CRM_Utils_Array
::value($params['status_id'], $waitStatus)) {
1660 $this->assign('isOnWaitlist', TRUE);
1663 $this->assign('customGroup', $customGroup);
1664 $this->assign('contactID', $contactID);
1665 $this->assign('participantID', $participants[$num]->id
);
1667 $this->_id
= $participants[$num]->id
;
1669 if ($this->_isPaidEvent
) {
1670 // fix amount for each of participants ( for bulk mode )
1672 $invoiceSettings = Civi
::settings()->get('contribution_invoice_settings');
1673 $invoicing = CRM_Utils_Array
::value('invoicing', $invoiceSettings);
1674 $totalTaxAmount = 0;
1676 //add dataArray in the receipts in ADD and UPDATE condition
1678 if ($this->_action
& CRM_Core_Action
::ADD
) {
1679 $line = isset($lineItem[0]) ?
$lineItem[0] : [];
1681 elseif ($this->_action
& CRM_Core_Action
::UPDATE
) {
1682 $line = $this->_values
['line_items'];
1685 foreach ($line as $key => $value) {
1686 if (isset($value['tax_amount'])) {
1687 $totalTaxAmount +
= $value['tax_amount'];
1688 if (isset($dataArray[(string) $value['tax_rate']])) {
1689 $dataArray[(string) $value['tax_rate']] = $dataArray[(string) $value['tax_rate']] + CRM_Utils_Array
::value('tax_amount', $value);
1692 $dataArray[(string) $value['tax_rate']] = CRM_Utils_Array
::value('tax_amount', $value);
1696 $this->assign('totalTaxAmount', $totalTaxAmount);
1697 $this->assign('taxTerm', $this->getSalesTaxTerm());
1698 $this->assign('dataArray', $dataArray);
1700 if (!empty($additionalParticipantDetails)) {
1701 $params['amount_level'] = preg_replace('/\ 1/', '', $params['amount_level']) . ' - ' . $this->_contributorDisplayName
;
1704 $eventAmount[$num] = [
1705 'label' => preg_replace('/\ 1/', '', $params['amount_level']),
1706 'amount' => $params['fee_amount'],
1708 //as we are using same template for online & offline registration.
1709 //So we have to build amount as array.
1710 $eventAmount = array_merge($eventAmount, $additionalParticipantDetails);
1711 $this->assign('amount', $eventAmount);
1714 $sendTemplateParams = [
1715 'groupName' => 'msg_tpl_workflow_event',
1716 'valueName' => 'event_offline_receipt',
1717 'contactId' => $contactID,
1718 'isTest' => !empty($this->_defaultValues
['is_test']),
1719 'PDFFilename' => ts('confirmation') . '.pdf',
1722 // try to send emails only if email id is present
1723 // and the do-not-email option is not checked for that contact
1724 if ($this->_contributorEmail
and !$this->_toDoNotEmail
) {
1725 $sendTemplateParams['from'] = $receiptFrom;
1726 $sendTemplateParams['toName'] = $this->_contributorDisplayName
;
1727 $sendTemplateParams['toEmail'] = $this->_contributorEmail
;
1728 $sendTemplateParams['cc'] = CRM_Utils_Array
::value('cc', $this->_fromEmails
);
1729 $sendTemplateParams['bcc'] = CRM_Utils_Array
::value('bcc', $this->_fromEmails
);
1732 //send email with pdf invoice
1733 $template = CRM_Core_Smarty
::singleton();
1734 $taxAmt = $template->get_template_vars('dataArray');
1735 $contributionId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
1736 $this->_id
, 'contribution_id', 'participant_id'
1738 $prefixValue = Civi
::settings()->get('contribution_invoice_settings');
1739 $invoicing = CRM_Utils_Array
::value('invoicing', $prefixValue);
1740 if (!empty($taxAmt) && (isset($invoicing) && isset($prefixValue['is_email_pdf']))) {
1741 $sendTemplateParams['isEmailPdf'] = TRUE;
1742 $sendTemplateParams['contributionId'] = $contributionId;
1744 list($mailSent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
1746 $sent[] = $contactID;
1747 foreach ($participants as $ids => $values) {
1748 if ($values->contact_id
== $contactID) {
1749 $values->details
= CRM_Utils_Array
::value('receipt_text', $params);
1750 CRM_Activity_BAO_Activity
::addActivity($values, 'Email');
1756 $notSent[] = $contactID;
1761 // set the participant id if it is not set
1763 $this->_id
= $participants[0]->id
;
1766 return $this->getStatusMsg($params, $sent, $updateStatusMsg, $notSent);
1770 * Set the various IDs relating to custom data types.
1772 public function setCustomDataTypes() {
1773 $customDataType = CRM_Core_OptionGroup
::values('custom_data_type', FALSE, FALSE, FALSE, NULL, 'name');
1774 $this->_roleCustomDataTypeID
= array_search('ParticipantRole', $customDataType);
1775 $this->_eventNameCustomDataTypeID
= array_search('ParticipantEventName', $customDataType);
1776 $this->_eventTypeCustomDataTypeID
= array_search('ParticipantEventType', $customDataType);
1777 $this->assign('roleCustomDataTypeID', $this->_roleCustomDataTypeID
);
1778 $this->assign('eventNameCustomDataTypeID', $this->_eventNameCustomDataTypeID
);
1779 $this->assign('eventTypeCustomDataTypeID', $this->_eventTypeCustomDataTypeID
);
1783 * Get status message
1785 * @param array $params
1787 * @param string $updateStatusMsg
1788 * @param int $notSent
1792 protected function getStatusMsg($params, $sent, $updateStatusMsg, $notSent) {
1794 if (($this->_action
& CRM_Core_Action
::UPDATE
)) {
1795 $statusMsg = ts('Event registration information for %1 has been updated.', [1 => $this->_contributorDisplayName
]);
1796 if (!empty($params['send_receipt']) && count($sent)) {
1797 $statusMsg .= ' ' . ts('A confirmation email has been sent to %1', [1 => $this->_contributorEmail
]);
1800 if ($updateStatusMsg) {
1801 $statusMsg = "{$statusMsg} {$updateStatusMsg}";
1804 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
1805 if ($this->_single
) {
1806 $statusMsg = ts('Event registration for %1 has been added.', [1 => $this->_contributorDisplayName
]);
1807 if (!empty($params['send_receipt']) && count($sent)) {
1808 $statusMsg .= ' ' . ts('A confirmation email has been sent to %1.', [1 => $this->_contributorEmail
]);
1812 $statusMsg = ts('Total Participant(s) added to event: %1.', [1 => count($this->_contactIds
)]);
1813 if (count($notSent) > 0) {
1814 $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)]);
1816 elseif (isset($params['send_receipt'])) {
1817 $statusMsg .= ' ' . ts('A confirmation email has been sent to ALL participants');