Skip to content

Commit

Permalink
Replace CRM_Utils_Array::value in CRM_Member_BAO_Membership
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwire committed Aug 15, 2020
1 parent cbbbf0e commit 699e088
Showing 1 changed file with 20 additions and 24 deletions.
44 changes: 20 additions & 24 deletions CRM/Member/BAO/Membership.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public static function add(&$params) {

$allStatus = CRM_Member_BAO_Membership::buildOptions('status_id', 'get');
$activityParams = [
'status_id' => CRM_Utils_Array::value('membership_activity_status', $params, 'Completed'),
'status_id' => $params['membership_activity_status'] ?? 'Completed',
];
if (in_array($allStatus[$membership->status_id], ['Pending', 'Grace'])) {
$activityParams['status_id'] = 'Scheduled';
Expand Down Expand Up @@ -166,15 +166,11 @@ public static function add(&$params) {
}

foreach (['Membership Signup', 'Membership Renewal'] as $activityType) {
$activityParams['id'] = CRM_Utils_Array::value('id',
civicrm_api3('Activity', 'Get',
[
'source_record_id' => $membership->id,
'activity_type_id' => $activityType,
'status_id' => 'Scheduled',
]
)
);
$activityParams['id'] = civicrm_api3('Activity', 'Get', [
'source_record_id' => $membership->id,
'activity_type_id' => $activityType,
'status_id' => 'Scheduled',
])['id'] ?? NULL;
// 1. Update Schedule Membership Signup/Renwal activity to completed on successful payment of pending membership
// 2. OR Create renewal activity scheduled if its membership renewal will be paid later
if (!empty($params['membership_activity_status']) && (!empty($activityParams['id']) || $activityType == 'Membership Renewal')) {
Expand Down Expand Up @@ -261,15 +257,15 @@ public static function create(&$params, &$ids = []) {
$params['join_date'] = trim($params['join_date']) ? date('Ymd', strtotime(trim($params['join_date']))) : 'null';

//fix for CRM-3570, during import exclude the statuses those having is_admin = 1
$excludeIsAdmin = CRM_Utils_Array::value('exclude_is_admin', $params, FALSE);
$excludeIsAdmin = $params['exclude_is_admin'] ?? FALSE;

//CRM-3724 always skip is_admin if is_override != true.
if (!$excludeIsAdmin && empty($params['is_override'])) {
$excludeIsAdmin = TRUE;
}

$calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($params['start_date'], $params['end_date'], $params['join_date'],
'today', $excludeIsAdmin, CRM_Utils_Array::value('membership_type_id', $params), $params
'today', $excludeIsAdmin, $params['membership_type_id'] ?? NULL, $params
);
if (empty($calcStatus)) {
throw new CRM_Core_Exception(ts("The membership cannot be saved because the status cannot be calculated for start_date: {$params['start_date']} end_date {$params['end_date']} join_date {$params['join_date']} as at " . date('Y-m-d H:i:s')));
Expand All @@ -295,7 +291,7 @@ public static function create(&$params, &$ids = []) {

$transaction = new CRM_Core_Transaction();

$params['id'] = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('membership', $ids));
$params['id'] = $params['id'] ?? $ids['membership'] ?? NULL;
$membership = self::add($params);

if (is_a($membership, 'CRM_Core_Error')) {
Expand Down Expand Up @@ -359,7 +355,7 @@ public static function create(&$params, &$ids = []) {
if (!empty($params['contribution'])) {
$params['line_item'][$priceSetId][$lineIndex]['contribution_id'] = $params['contribution']->id;
}
if ($lineMembershipType && $lineMembershipType == CRM_Utils_Array::value('membership_type_id', $params)) {
if ($lineMembershipType && $lineMembershipType == ($params['membership_type_id'] ?? NULL)) {
$params['line_item'][$priceSetId][$lineIndex]['entity_id'] = $membership->id;
$params['line_item'][$priceSetId][$lineIndex]['entity_table'] = 'civicrm_membership';
}
Expand All @@ -372,7 +368,7 @@ public static function create(&$params, &$ids = []) {
CRM_Price_BAO_LineItem::processPriceSet(
$membership->id,
$params['line_item'],
CRM_Utils_Array::value('contribution', $params)
$params['contribution'] ?? NULL
);
}

Expand Down Expand Up @@ -832,7 +828,7 @@ public static function getContactMembership($contactID, $memType, $isTest, $memb
'limit' => 0,
],
]);
$memberTypesSameParentOrgList = implode(',', array_keys(CRM_Utils_Array::value('values', $memberTypesSameParentOrg, [])));
$memberTypesSameParentOrgList = implode(',', array_keys($memberTypesSameParentOrg['values'] ?? []));
$dao->whereAdd('membership_type_id IN (' . $memberTypesSameParentOrgList . ')');
}
}
Expand Down Expand Up @@ -1143,9 +1139,9 @@ public static function fixMembershipStatusBeforeRenew(&$currentMembership, $chan
}

$status = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate(
CRM_Utils_Array::value('start_date', $currentMembership),
CRM_Utils_Array::value('end_date', $currentMembership),
CRM_Utils_Array::value('join_date', $currentMembership),
$currentMembership['start_date'] ?? NULL,
$currentMembership['end_date'] ?? NULL,
$currentMembership['join_date'] ?? NULL,
$today,
TRUE,
$currentMembership['membership_type_id'],
Expand Down Expand Up @@ -1194,7 +1190,7 @@ public static function fixMembershipStatusBeforeRenew(&$currentMembership, $chan
$format
),
'membership_type_id' => $currentMembership['membership_type_id'],
'max_related' => CRM_Utils_Array::value('max_related', $currentMembership, 0),
'max_related' => $currentMembership['max_related'] ?? 0,
];

$session = CRM_Core_Session::singleton();
Expand Down Expand Up @@ -1371,7 +1367,7 @@ public static function createRelatedMemberships(&$params, &$dao, $reset = FALSE)
$relatedContacts = [];
$allRelatedContacts = CRM_Member_BAO_Membership::checkMembershipRelationship($membership->membership_type_id,
$membership->contact_id,
CRM_Utils_Array::value('action', $params)
$params['action'] ?? NULL
);

// CRM-4213, CRM-19735 check for loops, using static variable to record contacts already processed.
Expand Down Expand Up @@ -1443,7 +1439,7 @@ public static function createRelatedMemberships(&$params, &$dao, $reset = FALSE)
) {
$params['status_id'] = $deceasedStatusId;
}
elseif ((CRM_Utils_Array::value('action', $params) & CRM_Core_Action::UPDATE) &&
elseif ((($params['action'] ?? NULL) & CRM_Core_Action::UPDATE) &&
($relationshipStatus == CRM_Contact_BAO_Relationship::PAST)
) {
$params['status_id'] = $expiredStatusId;
Expand Down Expand Up @@ -1877,7 +1873,7 @@ public static function processMembership($contactID, $membershipTypeID, $is_test
// Insert renewed dates for CURRENT membership
$memParams = [];
$memParams['join_date'] = CRM_Utils_Date::isoToMysql($membership->join_date);
$memParams['start_date'] = CRM_Utils_Array::value('start_date', $formDates, CRM_Utils_Date::isoToMysql($membership->start_date));
$memParams['start_date'] = $formDates['start_date'] ?? CRM_Utils_Date::isoToMysql($membership->start_date);
$memParams['end_date'] = $formDates['end_date'] ?? NULL;
if (empty($memParams['end_date'])) {
$memParams['end_date'] = $dates['end_date'] ?? NULL;
Expand Down Expand Up @@ -2398,7 +2394,7 @@ public static function recordMembershipContribution(&$params) {
$contributionParams = [];
$config = CRM_Core_Config::singleton();
$contributionParams['currency'] = $config->defaultCurrency;
$contributionParams['receipt_date'] = (CRM_Utils_Array::value('receipt_date', $params)) ? $params['receipt_date'] : 'null';
$contributionParams['receipt_date'] = isset($params['receipt_date']) ? $params['receipt_date'] : 'null';
$contributionParams['source'] = $params['contribution_source'] ?? NULL;
$contributionParams['non_deductible_amount'] = 'null';
$contributionParams['skipCleanMoney'] = TRUE;
Expand Down

0 comments on commit 699e088

Please sign in to comment.