Skip to content

Commit

Permalink
Merge pull request #12170 from seamuslee001/php72_pledge_foreach
Browse files Browse the repository at this point in the history
dev/core#117 Fix use of each in CRM/Pledge
  • Loading branch information
monishdeb authored May 22, 2018
2 parents 0e4e454 + 9de112c commit a4ee75b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 56 deletions.
45 changes: 23 additions & 22 deletions CRM/Pledge/BAO/Pledge.php
Original file line number Diff line number Diff line change
Expand Up @@ -1200,32 +1200,33 @@ public static function buildRecurParams($params) {
*/
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;
}
Expand Down
69 changes: 35 additions & 34 deletions CRM/Pledge/BAO/PledgeBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,41 +305,42 @@ public static function buildPledgeBlock($form) {
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));
}
}
}
}
Expand Down

0 comments on commit a4ee75b

Please sign in to comment.