From 5b217d3fea2aa4e6dc8a3dd63b3a75409ac8ce8a Mon Sep 17 00:00:00 2001 From: eileenmcnaugton Date: Sat, 15 Aug 2015 19:58:21 +1200 Subject: [PATCH] extract setMessageFunction --- CRM/Member/Form/Membership.php | 65 +++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 25 deletions(-) diff --git a/CRM/Member/Form/Membership.php b/CRM/Member/Form/Membership.php index c66bed67ed..06b2868aaa 100644 --- a/CRM/Member/Form/Membership.php +++ b/CRM/Member/Form/Membership.php @@ -1773,28 +1773,8 @@ class CRM_Member_Form_Membership extends CRM_Member_Form { $this->_id = $membership->id; } - $statusMsg = ''; - if (($this->_action & CRM_Core_Action::UPDATE)) { - $statusMsg = $this->getStatusMessageForUpdate($membership, $endDate, $receiptSend); - } - elseif (($this->_action & CRM_Core_Action::ADD)) { - $statusMsg = $this->getStatusMessageForCreate($endDate, $receiptSend, $membershipTypes, $createdMemberships, - $params, $calcDates, $mailSend); - } - - CRM_Core_Session::setStatus($statusMsg, ts('Complete'), 'success'); - //CRM-15187 - // dusplay message when membership type is changed - if (($this->_action & CRM_Core_Action::UPDATE) && $this->_id && !in_array($this->_memType, $this->_memTypeSelected)) { - CRM_Core_Session::setStatus( - ts('The financial types associated with the old and new membership types are different. You may want to edit the contribution associated with this membership to adjust its financial type.'), - ts('Warning') - ); - CRM_Core_Session::setStatus( - ts('The cost of the old and new membership types are different. You may want to edit the contribution associated with this membership to adjust its amount.'), - ts('Warning') - ); - } + $isRecur = CRM_Utils_Array::value('is_recur', $params); + $this->setStatusMessage($membership, $endDate, $receiptSend, $membershipTypes, $createdMemberships, $isRecur, $calcDates, $mailSend); return $createdMemberships; } @@ -1856,14 +1836,14 @@ class CRM_Member_Form_Membership extends CRM_Member_Form { * @param bool $receiptSend * @param array $membershipTypes * @param array $createdMemberships - * @param array $params + * @param bool $isRecur * @param array $calcDates * @param bool $mailSent * * @return array|string */ protected function getStatusMessageForCreate($endDate, $receiptSend, $membershipTypes, $createdMemberships, - $params, $calcDates, $mailSent) { + $isRecur, $calcDates, $mailSent) { // FIX ME: fix status messages $statusMsg = array(); @@ -1877,7 +1857,7 @@ class CRM_Member_Form_Membership extends CRM_Member_Form { $memEndDate = ($membership->end_date) ? $membership->end_date : $endDate; //get the end date from calculated dates. - if (!$memEndDate && empty($params['is_recur'])) { + if (!$memEndDate && !$isRecur) { $memEndDate = CRM_Utils_Array::value('end_date', $calcDates[$memType]); } @@ -1893,4 +1873,39 @@ class CRM_Member_Form_Membership extends CRM_Member_Form { return $statusMsg; } + /** + * @param $membership + * @param $endDate + * @param $receiptSend + * @param $membershipTypes + * @param $createdMemberships + * @param $isRecur + * @param $calcDates + * @param $mailSend + */ + protected function setStatusMessage($membership, $endDate, $receiptSend, $membershipTypes, $createdMemberships, $isRecur, $calcDates, $mailSend) { + $statusMsg = ''; + if (($this->_action & CRM_Core_Action::UPDATE)) { + $statusMsg = $this->getStatusMessageForUpdate($membership, $endDate, $receiptSend); + } + elseif (($this->_action & CRM_Core_Action::ADD)) { + $statusMsg = $this->getStatusMessageForCreate($endDate, $receiptSend, $membershipTypes, $createdMemberships, + $isRecur, $calcDates, $mailSend); + } + + CRM_Core_Session::setStatus($statusMsg, ts('Complete'), 'success'); + //CRM-15187 + // display message when membership type is changed + if (($this->_action & CRM_Core_Action::UPDATE) && $this->_id && !in_array($this->_memType, $this->_memTypeSelected)) { + CRM_Core_Session::setStatus( + ts('The financial types associated with the old and new membership types are different. You may want to edit the contribution associated with this membership to adjust its financial type.'), + ts('Warning') + ); + CRM_Core_Session::setStatus( + ts('The cost of the old and new membership types are different. You may want to edit the contribution associated with this membership to adjust its amount.'), + ts('Warning') + ); + } + } + } -- 2.25.1