Skip to content

Commit

Permalink
Fix another entity to be standardised & support custom data
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Feb 26, 2018
1 parent bc17b73 commit a575050
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 31 deletions.
22 changes: 14 additions & 8 deletions CRM/Event/BAO/ParticipantPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,31 +41,37 @@ class CRM_Event_BAO_ParticipantPayment extends CRM_Event_DAO_ParticipantPayment
* @param array $params
* of values to initialize the record with.
* @param array $ids
* with one values of id for this participantPayment record (for update).
* deprecated array.
*
* @return object
* the partcipant payment record
*/
public static function create(&$params, &$ids) {
if (isset($ids['id'])) {
CRM_Utils_Hook::pre('edit', 'ParticipantPayment', $ids['id'], $params);
public static function create(&$params, $ids = []) {
$id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('id', $ids));
if ($id) {
CRM_Utils_Hook::pre('edit', 'ParticipantPayment', $id, $params);
}
else {
CRM_Utils_Hook::pre('create', 'ParticipantPayment', NULL, $params);
}

$participantPayment = new CRM_Event_BAO_ParticipantPayment();
$participantPayment->copyValues($params);
if (isset($ids['id'])) {
$participantPayment->id = CRM_Utils_Array::value('id', $ids);
if ($id) {
$participantPayment->id = $id;
}
else {
$participantPayment->find(TRUE);
}
$participantPayment->save();

if (isset($ids['id'])) {
CRM_Utils_Hook::post('edit', 'ParticipantPayment', $ids['id'], $participantPayment);
if (empty($participantPayment->contribution_id)) {
// For an id update contribution_id may be unknown. We want it
// further down so perhaps get it before the hooks.
$participantPayment->find(TRUE);
}
if ($id) {
CRM_Utils_Hook::post('edit', 'ParticipantPayment', $id, $participantPayment);
}
else {
CRM_Utils_Hook::post('create', 'ParticipantPayment', NULL, $participantPayment);
Expand Down
3 changes: 1 addition & 2 deletions CRM/Event/Cart/Form/Checkout/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ public function registerParticipant($params, &$participant, $event) {
'participant_id' => $participant->id,
'contribution_id' => $params['contributionID'],
);
$ids = array();
CRM_Event_BAO_ParticipantPayment::create($payment_params, $ids);
CRM_Event_BAO_ParticipantPayment::create($payment_params);
}

$transaction->commit();
Expand Down
3 changes: 1 addition & 2 deletions CRM/Event/Form/Participant.php
Original file line number Diff line number Diff line change
Expand Up @@ -1308,9 +1308,8 @@ public function submit($params) {
'participant_id' => $participants[0]->id,
'contribution_id' => $contribution->id,
);
$ids = array();

CRM_Event_BAO_ParticipantPayment::create($paymentParticipant, $ids);
CRM_Event_BAO_ParticipantPayment::create($paymentParticipant);
$this->_contactIds[] = $this->_contactId;
}
else {
Expand Down
3 changes: 1 addition & 2 deletions CRM/Event/Form/Registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -761,8 +761,7 @@ public function confirmPostProcess($contactID = NULL, $contribution = NULL, $pay
'participant_id' => $participant->id,
'contribution_id' => $contribution->id,
);
$ids = array();
$paymentPartcipant = CRM_Event_BAO_ParticipantPayment::create($paymentParams, $ids);
$paymentPartcipant = CRM_Event_BAO_ParticipantPayment::create($paymentParams);
}

//set only primary participant's params for transfer checkout.
Expand Down
12 changes: 1 addition & 11 deletions api/v3/ParticipantPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,7 @@
* @return array
*/
function civicrm_api3_participant_payment_create($params) {

$ids = array();
if (!empty($params['id'])) {
$ids['id'] = $params['id'];
}
$participantPayment = CRM_Event_BAO_ParticipantPayment::create($params, $ids);

$payment = array();
_civicrm_api3_object_to_array($participantPayment, $payment[$participantPayment->id]);

return civicrm_api3_create_success($payment, $params);
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'ParticipantPayment');
}

/**
Expand Down
3 changes: 1 addition & 2 deletions tests/phpunit/CRM/Contribute/BAO/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -748,8 +748,7 @@ public function addParticipantWithContribution() {
'participant_id' => $participant->id,
'contribution_id' => $contribution['id'],
);
$ids = array();
CRM_Event_BAO_ParticipantPayment::create($paymentParticipant, $ids);
CRM_Event_BAO_ParticipantPayment::create($paymentParticipant);

$contributionObject = new CRM_Contribute_BAO_Contribution();
$contributionObject->id = $contribution['id'];
Expand Down
4 changes: 0 additions & 4 deletions tests/phpunit/api/v3/SyntaxConformanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,15 +393,13 @@ public static function toBeSkipped_custom_data_creatable($sequential = FALSE) {
'UFJoin',
'UFField',
'PriceFieldValue',
'Website',
'JobLog',
'GroupContact',
'EntityTag',
'PledgePayment',
'PaymentProcessorType',
'Relationship',
'RelationshipType',
'ParticipantPayment',

// ones that are not real entities hence not extendable.
'ActivityType',
Expand Down Expand Up @@ -466,7 +464,6 @@ public static function toBeSkipped_automock($sequential = FALSE) {
'MailingContact',
'EntityTag',
'Participant',
'ParticipantPayment',
'Setting',
'SurveyRespondant',
'MailingRecipients',
Expand Down Expand Up @@ -535,7 +532,6 @@ public static function toBeSkipped_updatesingle($sequential = FALSE) {
'GroupContact',
'MembershipPayment',
'Participant',
'ParticipantPayment',
'LineItem',
'PledgePayment',
'ContributionPage',
Expand Down

0 comments on commit a575050

Please sign in to comment.