From 9de112cd5d3730fee6a928dc515ab48a66eeb1c3 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Sun, 20 May 2018 12:29:42 +1000 Subject: [PATCH] dev/core#117 Fix Pledge each use in CRM/Pledge --- CRM/Pledge/BAO/Pledge.php | 45 +++++++++++----------- CRM/Pledge/BAO/PledgeBlock.php | 69 +++++++++++++++++----------------- 2 files changed, 58 insertions(+), 56 deletions(-) diff --git a/CRM/Pledge/BAO/Pledge.php b/CRM/Pledge/BAO/Pledge.php index 633cbea65e..b2c436584d 100644 --- a/CRM/Pledge/BAO/Pledge.php +++ b/CRM/Pledge/BAO/Pledge.php @@ -1200,32 +1200,33 @@ SELECT pledge.contact_id as contact_id, */ public static function getPledgeStartDate($date, $pledgeBlock) { $startDate = (array) json_decode($pledgeBlock['pledge_start_date']); - list($field, $value) = each($startDate); - if (!empty($date) && !CRM_Utils_Array::value('is_pledge_start_date_editable', $pledgeBlock)) { - return $date; - } - if (empty($date)) { - $date = $value; - } - switch ($field) { - case 'contribution_date': - if (empty($date)) { - $date = date('Ymd'); - } - break; + foreach ($startDate as $field => $value) { + if (!empty($date) && !CRM_Utils_Array::value('is_pledge_start_date_editable', $pledgeBlock)) { + return $date; + } + if (empty($date)) { + $date = $value; + } + switch ($field) { + case 'contribution_date': + if (empty($date)) { + $date = date('Ymd'); + } + break; - case 'calendar_date': - $date = date('Ymd', strtotime($date)); - break; + case 'calendar_date': + $date = date('Ymd', strtotime($date)); + break; - case 'calendar_month': - $date = self::getPaymentDate($date); - $date = date('Ymd', strtotime($date)); - break; + case 'calendar_month': + $date = self::getPaymentDate($date); + $date = date('Ymd', strtotime($date)); + break; - default: - break; + default: + break; + } } return $date; } diff --git a/CRM/Pledge/BAO/PledgeBlock.php b/CRM/Pledge/BAO/PledgeBlock.php index 263788146e..4762ce1839 100644 --- a/CRM/Pledge/BAO/PledgeBlock.php +++ b/CRM/Pledge/BAO/PledgeBlock.php @@ -305,41 +305,42 @@ class CRM_Pledge_BAO_PledgeBlock extends CRM_Pledge_DAO_PledgeBlock { if (CRM_Utils_Array::value('pledge_start_date', $pledgeBlock)) { $defaults = array(); $date = (array) json_decode($pledgeBlock['pledge_start_date']); - list($field, $value) = each($date); - switch ($field) { - case 'contribution_date': - $form->addDate('start_date', ts('First installment payment')); - $paymentDate = $value = date('m/d/Y'); - list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date::setDateDefaults(NULL); - $form->assign('is_date', TRUE); - break; - - case 'calendar_date': - $form->addDate('start_date', ts('First installment payment')); - list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date::setDateDefaults($value); - $form->assign('is_date', TRUE); - $paymentDate = $value; - break; - - case 'calendar_month': - $month = CRM_Utils_Date::getCalendarDayOfMonth(); - $form->add('select', 'start_date', ts('Day of month installments paid'), $month); - $paymentDate = CRM_Pledge_BAO_Pledge::getPaymentDate($value); - list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date::setDateDefaults($paymentDate); - break; - - default: - break; + foreach ($date as $field => $value) { + switch ($field) { + case 'contribution_date': + $form->addDate('start_date', ts('First installment payment')); + $paymentDate = $value = date('m/d/Y'); + list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date::setDateDefaults(NULL); + $form->assign('is_date', TRUE); + break; + + case 'calendar_date': + $form->addDate('start_date', ts('First installment payment')); + list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date::setDateDefaults($value); + $form->assign('is_date', TRUE); + $paymentDate = $value; + break; + + case 'calendar_month': + $month = CRM_Utils_Date::getCalendarDayOfMonth(); + $form->add('select', 'start_date', ts('Day of month installments paid'), $month); + $paymentDate = CRM_Pledge_BAO_Pledge::getPaymentDate($value); + list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date::setDateDefaults($paymentDate); + break; + + default: + break; - } - $form->setDefaults($defaults); - $form->assign('start_date_display', $paymentDate); - $form->assign('start_date_editable', FALSE); - if (CRM_Utils_Array::value('is_pledge_start_date_editable', $pledgeBlock)) { - $form->assign('start_date_editable', TRUE); - if ($field == 'calendar_month') { - $form->assign('is_date', FALSE); - $form->setDefaults(array('start_date' => $value)); + } + $form->setDefaults($defaults); + $form->assign('start_date_display', $paymentDate); + $form->assign('start_date_editable', FALSE); + if (CRM_Utils_Array::value('is_pledge_start_date_editable', $pledgeBlock)) { + $form->assign('start_date_editable', TRUE); + if ($field == 'calendar_month') { + $form->assign('is_date', FALSE); + $form->setDefaults(array('start_date' => $value)); + } } } } -- 2.25.1