$this->_emailExists = $this->get('emailExists');
$this->_contactID = $this->_membershipContactID = $this->getContactID();
- $this->getRenewalMembershipID();
if ($this->getRenewalMembershipID()) {
- $membership = new CRM_Member_DAO_Membership();
- $membership->id = $this->getRenewalMembershipID();
-
- if ($membership->find(TRUE)) {
- $this->_defaultMemTypeId = $membership->membership_type_id;
- if ($membership->contact_id != $this->_contactID) {
- $validMembership = FALSE;
- $organizations = CRM_Contact_BAO_Relationship::getPermissionedContacts($this->getAuthenticatedContactID(), NULL, NULL, 'Organization');
- if (!empty($organizations) && array_key_exists($membership->contact_id, $organizations)) {
- $this->_membershipContactID = $membership->contact_id;
- $this->assign('membershipContactID', $this->_membershipContactID);
- $this->assign('membershipContactName', $organizations[$this->_membershipContactID]['name']);
- $validMembership = TRUE;
- }
- else {
- $membershipType = new CRM_Member_BAO_MembershipType();
- $membershipType->id = $membership->membership_type_id;
- if ($membershipType->find(TRUE)) {
- // CRM-14051 - membership_type.relationship_type_id is a CTRL-A padded string w one or more ID values.
- // Convert to comma separated list.
- $inheritedRelTypes = implode(',', CRM_Utils_Array::explodePadded($membershipType->relationship_type_id));
- $permContacts = CRM_Contact_BAO_Relationship::getPermissionedContacts($this->getAuthenticatedContactID(), $membershipType->relationship_type_id);
- if (array_key_exists($membership->contact_id, $permContacts)) {
- $this->_membershipContactID = $membership->contact_id;
- $validMembership = TRUE;
- }
- }
- }
- if (!$validMembership) {
- CRM_Core_Session::setStatus(ts("Oops. The membership you're trying to renew appears to be invalid. Contact your site administrator if you need assistance. If you continue, you will be issued a new membership."), ts('Membership Invalid'), 'alert');
- }
- }
- }
- else {
- CRM_Core_Session::setStatus(ts("Oops. The membership you're trying to renew appears to be invalid. Contact your site administrator if you need assistance. If you continue, you will be issued a new membership."), ts('Membership Invalid'), 'alert');
- }
- unset($membership);
+ $this->defineRenewalMembership();
}
// we do not want to display recently viewed items, so turn off
$this->order->setForm($this);
}
+ protected function defineRenewalMembership(): void {
+ $membership = new CRM_Member_DAO_Membership();
+ $membership->id = $this->getRenewalMembershipID();
+
+ if ($membership->find(TRUE)) {
+ $this->_defaultMemTypeId = $membership->membership_type_id;
+ if ($membership->contact_id != $this->_contactID) {
+ $validMembership = FALSE;
+ $organizations = CRM_Contact_BAO_Relationship::getPermissionedContacts($this->getAuthenticatedContactID(), NULL, NULL, 'Organization');
+ if (!empty($organizations) && array_key_exists($membership->contact_id, $organizations)) {
+ $this->_membershipContactID = $membership->contact_id;
+ $this->assign('membershipContactID', $this->_membershipContactID);
+ $this->assign('membershipContactName', $organizations[$this->_membershipContactID]['name']);
+ $validMembership = TRUE;
+ }
+ else {
+ $membershipType = new CRM_Member_BAO_MembershipType();
+ $membershipType->id = $membership->membership_type_id;
+ if ($membershipType->find(TRUE)) {
+ // CRM-14051 - membership_type.relationship_type_id is a CTRL-A padded string w one or more ID values.
+ // Convert to comma separated list.
+ $inheritedRelTypes = implode(',', CRM_Utils_Array::explodePadded($membershipType->relationship_type_id));
+ $permContacts = CRM_Contact_BAO_Relationship::getPermissionedContacts($this->getAuthenticatedContactID(), $membershipType->relationship_type_id);
+ if (array_key_exists($membership->contact_id, $permContacts)) {
+ $this->_membershipContactID = $membership->contact_id;
+ $validMembership = TRUE;
+ }
+ }
+ }
+ if (!$validMembership) {
+ CRM_Core_Session::setStatus(ts("Oops. The membership you're trying to renew appears to be invalid. Contact your site administrator if you need assistance. If you continue, you will be issued a new membership."), ts('Membership Invalid'), 'alert');
+ }
+ }
+ }
+ else {
+ CRM_Core_Session::setStatus(ts("Oops. The membership you're trying to renew appears to be invalid. Contact your site administrator if you need assistance. If you continue, you will be issued a new membership."), ts('Membership Invalid'), 'alert');
+ }
+ }
+
}