Skip to content

Commit

Permalink
Merge pull request #11284 from eileenmcnaughton/towards1
Browse files Browse the repository at this point in the history
[NFC] code cleanup: split out 2 functions that are mostly unrelated.
  • Loading branch information
mlutfy authored Nov 18, 2017
2 parents b8dd91f + ed0cb2f commit f0e4d11
Showing 1 changed file with 35 additions and 11 deletions.
46 changes: 35 additions & 11 deletions CRM/Price/BAO/LineItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ public static function changeFeeSelections(
if (!empty($trxn->id)) {
$trxnId['id'] = $trxn->id;
}
$lineItemObj->addLineItemOnChangeFeeSelection($requiredChanges['line_items_to_add'], $entityID, $entityTable, $contributionId, $trxnId, TRUE);
$lineItemObj->addFinancialItemsOnLineItemsChange($requiredChanges['line_items_to_add'], $entityID, $entityTable, $contributionId, $trxnId);

// update participant fee_amount column
$lineItemObj->updateEntityRecordOnChangeFeeSelection($params, $entityID, $entity);
Expand Down Expand Up @@ -945,6 +945,37 @@ protected function getLineItemsToAlter($submittedLineItems, $entityID, $entity)
);
}

/**
* Helper function to add lineitems or financial item related to it, to as result of fee change
*
* @param array $lineItemsToAdd
* @param int $entityID
* @param string $entityTable
* @param int $contributionID
*/
protected function addLineItemOnChangeFeeSelection(
$lineItemsToAdd,
$entityID,
$entityTable,
$contributionID
) {
// if there is no line item to add, do not proceed
if (empty($lineItemsToAdd)) {
return;
}

foreach ($lineItemsToAdd as $priceFieldValueID => $lineParams) {
$lineParams = array_merge($lineParams, array(
'entity_table' => $entityTable,
'entity_id' => $entityID,
'contribution_id' => $contributionID,
));
if (!array_key_exists('skip', $lineParams)) {
self::create($lineParams);
}
}
}

/**
* Helper function to add lineitems or financial item related to it, to as result of fee change
*
Expand All @@ -953,17 +984,15 @@ protected function getLineItemsToAlter($submittedLineItems, $entityID, $entity)
* @param string $entityTable
* @param int $contributionID
* @param array $adjustedFinancialTrxnID
* @param bool $addFinancialItemOnly
*
* @return void
*/
protected function addLineItemOnChangeFeeSelection(
protected function addFinancialItemsOnLineItemsChange(
$lineItemsToAdd,
$entityID,
$entityTable,
$contributionID,
$adjustedFinancialTrxnID = NULL,
$addFinancialItemOnly = FALSE
$adjustedFinancialTrxnID = NULL
) {
// if there is no line item to add, do not proceed
if (empty($lineItemsToAdd)) {
Expand All @@ -981,12 +1010,7 @@ protected function addLineItemOnChangeFeeSelection(
'entity_id' => $entityID,
'contribution_id' => $contributionID,
));
if ($addFinancialItemOnly) {
$changedFinancialTypeID = $this->addFinancialItemsOnLineItemChange(empty($adjustedFinancialTrxnID), $lineParams, $updatedContribution, $tempFinancialTrxnID, $changedFinancialTypeID);
}
elseif (!array_key_exists('skip', $lineParams)) {
self::create($lineParams);
}
$changedFinancialTypeID = $this->addFinancialItemsOnLineItemChange(empty($adjustedFinancialTrxnID), $lineParams, $updatedContribution, $tempFinancialTrxnID, $changedFinancialTypeID);
}

if ($changedFinancialTypeID) {
Expand Down

0 comments on commit f0e4d11

Please sign in to comment.