From 6a38708bd1c39b30aa710171ed4640935b37e36d Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 15 Nov 2016 15:15:59 +1300 Subject: [PATCH] Move status check to shared function --- CRM/Member/BAO/Membership.php | 5 +---- CRM/Member/Form.php | 5 +++++ CRM/Member/Form/Membership.php | 4 ---- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/CRM/Member/BAO/Membership.php b/CRM/Member/BAO/Membership.php index 1805b76426..71f68a6ef4 100644 --- a/CRM/Member/BAO/Membership.php +++ b/CRM/Member/BAO/Membership.php @@ -1094,12 +1094,9 @@ AND civicrm_membership.is_test = %2"; /** * Function check the status of the membership before adding membership for a contact. * - * @param int $contactId - * Contact id. - * * @return int */ - public static function statusAvailabilty($contactId) { + public static function statusAvailabilty() { $membership = new CRM_Member_DAO_MembershipStatus(); $membership->whereAdd('is_active=1'); return $membership->count(); diff --git a/CRM/Member/Form.php b/CRM/Member/Form.php index 222fcb4c8f..65f7ae9a95 100644 --- a/CRM/Member/Form.php +++ b/CRM/Member/Form.php @@ -96,6 +96,11 @@ class CRM_Member_Form extends CRM_Contribute_Form_AbstractEditPayment { if (!CRM_Core_Permission::checkActionPermission('CiviMember', $this->_action)) { CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); } + if (!CRM_Member_BAO_Membership::statusAvailabilty()) { + // all possible statuses are disabled - redirect back to contact form + CRM_Core_Error::statusBounce(ts('There are no configured membership statuses. You cannot add this membership until your membership statuses are correctly configured')); + } + parent::preProcess(); $params = array(); $params['context'] = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'membership'); diff --git a/CRM/Member/Form/Membership.php b/CRM/Member/Form/Membership.php index e8b2b10c52..53de647a0d 100644 --- a/CRM/Member/Form/Membership.php +++ b/CRM/Member/Form/Membership.php @@ -187,10 +187,6 @@ class CRM_Member_Form_Membership extends CRM_Member_Form { } if ($this->_action & CRM_Core_Action::ADD) { - if (!CRM_Member_BAO_Membership::statusAvailabilty($this->_contactID)) { - // all possible statuses are disabled - redirect back to contact form - CRM_Core_Error::statusBounce(ts('There are no configured membership statuses. You cannot add this membership until your membership statuses are correctly configured')); - } if ($this->_contactID) { //check whether contact has a current membership so we can alert user that they may want to do a renewal instead $contactMemberships = array(); -- 2.25.1