Commit 526703f4 authored by bgm's avatar bgm Committed by Stéphane Lussier

dev/event#6 Allow registering duplicate participants if the event allows it.

parent 014c7950
<?php
class CRM_Boxoffice_Event_Form_BoxofficeParticipant extends CRM_Event_Form_Participant {
/**
* Add local and global form rules.
*
* @return void
*/
public function addRules() {
$this->addFormRule(['CRM_Boxoffice_Event_Form_BoxofficeParticipant', 'formRule'], $this);
}
/**
* Global validation rules for the form.
*
* XXX overrides the parent to remove some of the duplicate checks.
* https://lab.civicrm.org/dev/event/issues/6
*
* @param array $values
* Posted values of the form.
* @param $files
* @param $self
*
* @return array
* list of errors to be posted back to the form
*/
public static function formRule($values, $files, $self) {
// If $values['_qf_Participant_next'] is Delete or
// $values['event_id'] is empty, then return
// instead of proceeding further.
if ((CRM_Utils_Array::value('_qf_Participant_next', $values) == 'Delete') ||
(!$values['event_id'])
) {
return TRUE;
}
$errorMsg = [];
if (!empty($values['payment_processor_id'])) {
// make sure that payment instrument values (e.g. credit card number and cvv) are valid
CRM_Core_Payment_Form::validatePaymentInstrument($values['payment_processor_id'], $values, $errorMsg, NULL);
}
if (!empty($values['record_contribution'])) {
if (empty($values['financial_type_id'])) {
$errorMsg['financial_type_id'] = ts('Please enter the associated Financial Type');
}
if (empty($values['payment_instrument_id'])) {
$errorMsg['payment_instrument_id'] = ts('Payment Method is a required field.');
}
if (!empty($values['priceSetId'])) {
CRM_Price_BAO_PriceField::priceSetValidation($values['priceSetId'], $values, $errorMsg);
}
}
// validate contribution status for 'Failed'.
if ($self->_onlinePendingContributionId && !empty($values['record_contribution']) &&
(CRM_Utils_Array::value('contribution_status_id', $values) ==
array_search('Failed', CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'))
)
) {
$errorMsg['contribution_status_id'] = ts('Please select a valid payment status before updating.');
}
// do the amount validations.
//skip for update mode since amount is freeze, CRM-6052
if ((!$self->_id && empty($values['total_amount']) &&
empty($self->_values['line_items'])
) ||
($self->_id && !$self->_paymentId && isset($self->_values['line_items']) && is_array($self->_values['line_items']))
) {
if ($priceSetId = CRM_Utils_Array::value('priceSetId', $values)) {
CRM_Price_BAO_PriceField::priceSetValidation($priceSetId, $values, $errorMsg, TRUE);
}
}
// For single additions - show validation error if the contact has already been registered
// for this event.
if ($self->_single && ($self->_action & CRM_Core_Action::ADD)) {
if ($self->_context == 'standalone') {
$contactId = CRM_Utils_Array::value('contact_id', $values);
}
else {
$contactId = $self->_contactId;
}
$eventId = CRM_Utils_Array::value('event_id', $values);
// https://lab.civicrm.org/dev/event/issues/6
$event = new CRM_Event_DAO_Event();
$event->id = $eventId;
$event->find(TRUE);
if (!$event->allow_same_participant_emails && !empty($contactId) && !empty($eventId)) {
$cancelledStatusID = CRM_Core_PseudoConstant::getKey('CRM_Event_BAO_Participant', 'status_id', 'Cancelled');
$dupeCheck = new CRM_Event_BAO_Participant();
$dupeCheck->contact_id = $contactId;
$dupeCheck->event_id = $eventId;
$dupeCheck->whereAdd("status_id != {$cancelledStatusID} ");
$dupeCheck->find(TRUE);
if (!empty($dupeCheck->id)) {
$errorMsg['event_id'] = ts("This contact has already been assigned to this event.");
}
}
}
return CRM_Utils_Array::crmIsEmptyArray($errorMsg) ? TRUE : $errorMsg;
}
}
<?php
class CRM_Boxoffice_Event_Page_BoxofficeTab extends CRM_Event_Page_Tab {
/**
* called when action is update or new.
*
* XXX Overrides the parent so that we can call our own Form,
* which in turn removes some of the event participant duplicate checks.
*
* @return null
*/
public function edit() {
// set https for offline cc transaction
$mode = CRM_Utils_Request::retrieve('mode', 'Alphanumeric', $this);
if ($mode == 'test' || $mode == 'live') {
CRM_Utils_System::redirectToSSL();
}
if ($this->_action != CRM_Core_Action::ADD) {
// get associated contributions only on edit/delete
$this->associatedContribution();
}
// XXX This is the main change
$controller = new CRM_Core_Controller_Simple(
'CRM_Boxoffice_Event_Form_BoxofficeParticipant',
'Create Participation',
$this->_action
);
$controller->setEmbedded(TRUE);
$controller->set('id', $this->_id);
$controller->set('cid', $this->_contactId);
return $controller->run();
}
/**
* Use the same tpl as the parent.
*/
public function getTemplateFileName() {
return 'CRM/Event/Page/Tab.tpl';
}
}
......@@ -16,4 +16,9 @@
<is_public>true</is_public>
<is_ssl>false</is_ssl>
</item>
<item>
<path>civicrm/contact/view/participant</path>
<page_callback>CRM_Boxoffice_Event_Page_BoxofficeTab</page_callback>
<weight>4</weight>
</item>
</menu>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment