Skip to content

Commit

Permalink
Move status check to shared function
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Nov 15, 2016
1 parent 6687436 commit 8954d98
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
5 changes: 1 addition & 4 deletions CRM/Member/BAO/Membership.php
Original file line number Diff line number Diff line change
Expand Up @@ -1094,12 +1094,9 @@ public static function getMembershipCount($membershipTypeId, $date = NULL, $isTe
/**
* 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();
Expand Down
5 changes: 5 additions & 0 deletions CRM/Member/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ public function preProcess() {
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');
Expand Down
4 changes: 0 additions & 4 deletions CRM/Member/Form/Membership.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,6 @@ public function preProcess() {
}

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();
Expand Down

0 comments on commit 8954d98

Please sign in to comment.