}
}
- $query = 'select role_id, source, fee_level, is_test, is_pay_later, fee_amount, discount_id, fee_currency,campaign_id, discount_amount from civicrm_participant where id = ' . $this->_from_participant_id;
- $dao = CRM_Core_DAO::executeQuery($query);
- $value_to = [];
- while ($dao->fetch()) {
- $value_to['role_id'] = $dao->role_id;
- $value_to['source'] = $dao->source;
- $value_to['fee_level'] = $dao->fee_level;
- $value_to['is_test'] = $dao->is_test;
- $value_to['is_pay_later'] = $dao->is_pay_later;
- $value_to['fee_amount'] = $dao->fee_amount;
- }
- $value_to['contact_id'] = $contact_id;
- $value_to['event_id'] = $this->_event_id;
- $value_to['status_id'] = CRM_Core_PseudoConstant::getKey(
- 'CRM_Event_BAO_Participant',
- 'status_id',
- 'Registered'
- );
- $value_to['register_date'] = date("Y-m-d");
- //first create the new participant row -don't set registered_by yet or email won't be sent
- $participant = CRM_Event_BAO_Participant::create($value_to);
- //send a confirmation email to the new participant
- $this->participantTransfer($participant);
- //now update registered_by_id
- $query = "UPDATE civicrm_participant cp SET cp.registered_by_id = %1 WHERE cp.id = ({$participant->id})";
- $params = [1 => [$this->_from_participant_id, 'Integer']];
- $dao = CRM_Core_DAO::executeQuery($query, $params);
- //copy line items to new participant
- $line_items = CRM_Price_BAO_LineItem::getLineItems($this->_from_participant_id);
- foreach ($line_items as $item) {
- $item['entity_id'] = $participant->id;
- $item['id'] = NULL;
- $item['entity_table'] = "civicrm_participant";
- $new_item = CRM_Price_BAO_LineItem::create($item);
- }
- //now cancel the from participant record, leaving the original line-item(s)
- $value_from = [];
- $value_from['id'] = $this->_from_participant_id;
- $tansferId = array_search('Transferred', CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Negative'"));
- $value_from['status_id'] = $tansferId;
- $value_from['transferred_to_contact_id'] = $contact_id;
+ $this->transferParticipantRegistration($contact_id, $this->_from_participant_id, $this->_event_id);
+
$contact_details = CRM_Contact_BAO_Contact::getContactDetails($contact_id);
$display_name = current($contact_details);
$this->assign('to_participant', $display_name);
- CRM_Event_BAO_Participant::create($value_from);
$this->sendCancellation();
list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contact_id);
$statusMsg = ts('Event registration information for %1 has been updated.', [1 => $displayName]);
CRM_Core_Session::setStatus($statusMsg, ts('Thanks'), 'success');
}
+ /**
+ * Move Participant registration to new contact.
+ *
+ * @param int $toContactID
+ * @param int $fromParticipantID
+ * @param int $eventID
+ *
+ * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
+ */
+ public function transferParticipantRegistration($toContactID, $fromParticipantID, $eventID) {
+ $query = 'select role_id, source, fee_level, is_test, is_pay_later, fee_amount, discount_id, fee_currency,campaign_id, discount_amount from civicrm_participant where id = ' . $fromParticipantID;
+ $dao = CRM_Core_DAO::executeQuery($query);
+ $value_to = [];
+ while ($dao->fetch()) {
+ $value_to['role_id'] = $dao->role_id;
+ $value_to['source'] = $dao->source;
+ $value_to['fee_level'] = $dao->fee_level;
+ $value_to['is_test'] = $dao->is_test;
+ $value_to['is_pay_later'] = $dao->is_pay_later;
+ $value_to['fee_amount'] = $dao->fee_amount;
+ }
+ $value_to['contact_id'] = $toContactID;
+ $value_to['event_id'] = $eventID;
+ $value_to['status_id'] = CRM_Core_PseudoConstant::getKey(
+ 'CRM_Event_BAO_Participant',
+ 'status_id',
+ 'Registered'
+ );
+ $value_to['register_date'] = date("Y-m-d");
+ //first create the new participant row -don't set registered_by yet or email won't be sent
+ $participant = CRM_Event_BAO_Participant::create($value_to);
+ //send a confirmation email to the new participant
+ $this->participantTransfer($participant);
+ //now update registered_by_id
+ $query = "UPDATE civicrm_participant cp SET cp.registered_by_id = %1 WHERE cp.id = ({$participant->id})";
+ $params = [1 => [$fromParticipantID, 'Integer']];
+ $dao = CRM_Core_DAO::executeQuery($query, $params);
+ //copy line items to new participant
+ $line_items = CRM_Price_BAO_LineItem::getLineItems($this->_from_participant_id);
+ foreach ($line_items as $item) {
+ $item['entity_id'] = $participant->id;
+ $item['id'] = NULL;
+ $item['entity_table'] = "civicrm_participant";
+ $new_item = CRM_Price_BAO_LineItem::create($item);
+ }
+ //now cancel the from participant record, leaving the original line-item(s)
+ $value_from = [];
+ $value_from['id'] = $fromParticipantID;
+ $tansferId = array_search('Transferred', CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Negative'"));
+ $value_from['status_id'] = $tansferId;
+ $value_from['transferred_to_contact_id'] = $toContactID;
+ CRM_Event_BAO_Participant::create($value_from);
+ }
+
}
return $submitParams;
}
+ /**
+ * Check if participant is transferred correctly.
+ *
+ * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
+ */
+ public function testTransferParticipantRegistration() {
+ //Register a contact to a sample event.
+ $this->createParticipantRecordsFromTwoFieldPriceSet();
+ $contribution = $this->callAPISuccessGetSingle('Contribution', []);
+ //Check line item count of the contribution id before transfer.
+ $lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($contribution['id']);
+ $this->assertEquals(count($lineItems), 2);
+ $participantId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_ParticipantPayment', $contribution['id'], 'participant_id', 'contribution_id');
+ /* @var CRM_Event_Form_SelfSvcTransfer $form */
+ $form = $this->getFormObject('CRM_Event_Form_SelfSvcTransfer');
+ $toContactId = $this->individualCreate();
+ $form->transferParticipantRegistration($toContactId, $participantId, CRM_Core_DAO::getFieldValue('CRM_Event_BAO_Participant', $participantId, 'event_id'));
+
+ //Assert participant is transferred to $toContactId.
+ $participant = $this->callAPISuccess('Participant', 'getsingle', [
+ 'return' => ["transferred_to_contact_id"],
+ 'id' => $participantId,
+ ]);
+ $this->assertEquals($participant['transferred_to_contact_id'], $toContactId);
+
+ //Assert $toContactId has a new registration.
+ $toParticipant = $this->callAPISuccess('Participant', 'getsingle', [
+ 'contact_id' => $toContactId,
+ ]);
+ $this->assertEquals($toParticipant['participant_registered_by_id'], $participantId);
+
+ //Check line item count of the contribution id remains the same.
+ $lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($contribution['id']);
+ $this->assertEquals(count($lineItems), 2);
+ }
+
/**
* Get the id of the created event.
*