Skip to content
Snippets Groups Projects
Commit 51e89def authored by Deepak Srivastava's avatar Deepak Srivastava
Browse files

CRM-13333 - renewal of inherited memberships other than on-behalf-of organization

parent 1d0c696a
Branches
Tags
No related merge requests found
......@@ -1417,38 +1417,59 @@ WHERE id IN ( {$contacts} )
* @return array array of employers.
*
*/
static function getPermissionedEmployer($contactID, $name = '%') {
$employers = array();
static function getPermissionedEmployer($contactID, $name = NULL) {
//get the relationship id
$relTypeId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType',
'Employee of', 'id', 'name_a_b'
);
return self::getPermissionedContacts($contactID, $relTypeId, $name);
}
/**
* Function to return list of permissioned contacts for a given contact and relationship type
*
* @param $contactID int contact id whose permissioned contacts are to be found.
* @param $relTypeId relationship type id
* @param $name string
*
* @static
*
* @return array of contacts
*/
static function getPermissionedContacts($contactID, $relTypeId, $name = NULL) {
$contacts = array();
if ($relTypeId) {
$query = "
SELECT cc.id as id, cc.sort_name as name
FROM civicrm_relationship cr, civicrm_contact cc
WHERE cr.contact_id_a = $contactID AND
cr.relationship_type_id = $relTypeId AND
cr.is_permission_a_b = 1 AND
WHERE
cr.contact_id_a = %1 AND
cr.relationship_type_id = %2 AND
cr.is_permission_a_b = 1 AND
IF(cr.end_date IS NULL, 1, (DATEDIFF( CURDATE( ), cr.end_date ) <= 0)) AND
cr.is_active = 1 AND
cc.id = cr.contact_id_b AND
cc.sort_name LIKE '%$name%'";
cc.id = cr.contact_id_b";
if (!empty($name)) {
$name = CRM_Utils_Type::escape($name, 'String');
$query .= "
AND cc.sort_name LIKE '%$name%'";
}
$nullArray = array();
$dao = CRM_Core_DAO::executeQuery($query, $nullArray);
$args = array(1 => array($contactID, 'Integer'), 2 => array($relTypeId, 'Integer'));
$dao = CRM_Core_DAO::executeQuery($query, $args);
while ($dao->fetch()) {
$employers[$dao->id] = array(
$contacts[$dao->id] = array(
'name' => $dao->name,
'value' => $dao->id,
);
}
}
return $employers;
return $contacts;
}
static function getValidContactTypeList($relType) {
......
......@@ -822,6 +822,15 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr
);
}
if (!empty($this->_membershipContactID) && $contactID != $this->_membershipContactID) {
// this is an onbehalf renew case for inherited membership. For e.g a permissioned member of household,
// store current user id as related contact for later use for mailing / activity..
$this->_values['related_contact'] = $contactID;
$this->_params['related_contact'] = $contactID;
// swap contact like we do for on-behalf-org case, so parent/primary membership is affected
$contactID = $this->_membershipContactID;
}
// lets store the contactID in the session
// for things like tell a friend
$session = CRM_Core_Session::singleton();
......
......@@ -237,7 +237,17 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
}
}
else {
$this->_membershipContactID = $membership->contact_id;
$membershipType = new CRM_Member_BAO_MembershipType();
$membershipType->id = $membership->membership_type_id;
if ($membershipType->find(TRUE)) {
$permContacts = CRM_Contact_BAO_Relationship::getPermissionedContacts($this->_userID, $membershipType->relationship_type_id);
if (array_key_exists($membership->contact_id, $permContacts)) {
$this->_membershipContactID = $membership->contact_id;
}
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');
}
}
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment