[REF] Simplify calcdates
authoreileen <emcnaughton@wikimedia.org>
Fri, 26 Mar 2021 03:47:56 +0000 (16:47 +1300)
committereileen <emcnaughton@wikimedia.org>
Fri, 9 Apr 2021 00:07:01 +0000 (12:07 +1200)
CRM/Member/Form/Membership.php

index c435bde7294f48ab14a8f3494128c95dab9e51f0..797faf20db4e920dd23b0c622000c2bae81bb696 100644 (file)
@@ -1853,28 +1853,19 @@ DESC limit 1");
     foreach ($this->_memTypeSelected as $memType) {
       $membershipTypeValues[$memType]['membership_type_id'] = $memType;
     }
-    $joinDate = $formValues['join_date'];
-    $startDate = $formValues['start_date'];
-    $endDate = $formValues['end_date'];
 
-    $calcDates = [];
     foreach ($this->order->getMembershipLineItems() as $membershipLineItem) {
       $memTypeNumTerms = $this->getSubmittedValue('num_terms') ?: $membershipLineItem['membership_num_terms'];
-      $calcDates[$membershipLineItem['membership_type_id']] = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membershipLineItem['membership_type_id'],
-        $joinDate, $startDate, $endDate, $memTypeNumTerms
+      $calcDates = CRM_Member_BAO_MembershipType::getDatesForMembershipType(
+        $membershipLineItem['membership_type_id'],
+        $this->getSubmittedValue('join_date'),
+        $this->getSubmittedValue('start_date'),
+        $this->getSubmittedValue('end_date'),
+        $memTypeNumTerms
       );
-    }
-
-    foreach ($calcDates as $memType => $calcDate) {
-      foreach (['join_date', 'start_date', 'end_date'] as $d) {
-        //first give priority to form values then calDates.
-        $date = $formValues[$d] ?? NULL;
-        if (!$date) {
-          $date = $calcDate[$d] ?? NULL;
-        }
-
-        $membershipTypeValues[$memType][$d] = CRM_Utils_Date::processDate($date);
-      }
+      $membershipTypeValues[$membershipLineItem['membership_type_id']]['join_date'] = $calcDates['join_date'];
+      $membershipTypeValues[$membershipLineItem['membership_type_id']]['start_date'] = $calcDates['start_date'];
+      $membershipTypeValues[$membershipLineItem['membership_type_id']]['end_date'] = $calcDates['end_date'];
     }
 
     foreach ($this->_memTypeSelected as $memType) {