$sharedContact->id = $relationship->contact_id_a;
$sharedContact->find(TRUE);
- if ($relationship->relationship_type_id == 4 && $relationship->contact_id_b == $sharedContact->employer_id) {
+ // CRM-15881 UPDATES
+ // changed FROM "...relationship->relationship_type_id == 4..." TO "...relationship->relationship_type_id == 5..."
+ // As the system should be looking for type "employer of" (id 5) and not "sibling of" (id 4)
+ if ($relationship->relationship_type_id == 5 && $relationship->contact_id_b == $sharedContact->employer_id) {
CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($relationship->contact_id_a);
}
}
}
}
+ // CRM-15829 UPDATES
+ // If we're looking for active memberships we must consider pending (id: 5) ones too.
+ // Hence we can't just call CRM_Member_BAO_Membership::getValues below with the active flag, is it would completely miss pending relatioships.
+
+ $query = 'SELECT * FROM `civicrm_membership_status`';
+ if ($active) {
+ $query .= 'WHERE `is_current_member` = 1 OR `id` = 5';
+ }
+
+ $dao = CRM_Core_DAO::executeQuery($query);
+ while ($dao->fetch()) {
+ $membershipStatusRecordIds[$dao->id] = $dao->id;
+ }
+
// Now get the active memberships for all the contacts.
// If contact have any valid membership(s), then add it to
// 'values' array.
$memParams = array('contact_id' => $cid);
$memberships = array();
- CRM_Member_BAO_Membership::getValues($memParams, $memberships, $active, TRUE);
+ // CRM-15829 UPDATES
+ // Since we want PENDING memberships as well, the $active flag needs to be set to false so that this will return all memberships and we can then filter the memberships based on the status IDs recieved above.
+ CRM_Member_BAO_Membership::getValues($memParams, $memberships, FALSE, TRUE);
+
+ // CRM-15829 UPDATES
+ // filter out the memberships returned by CRM_Member_BAO_Membership::getValues based on the status IDs fetched on line ~1462
+ foreach ($memberships as $key => $membership) {
+
+ if (!isset($memberships[$key]['status_id'])) {
+ continue;
+ }
+
+ $membershipStatusId = $memberships[$key]['status_id'];
+ if (!isset($membershipStatusRecordIds[$membershipStatusId])) {
+ unset($memberships[$key]);
+ }
+ }
if (empty($memberships)) {
continue;
// action is taken depending upon the mode
if ($this->_action & CRM_Core_Action::DELETE) {
CRM_Contact_BAO_Relationship::del($this->_relationshipId);
+
+ // CRM-15881 UPDATES
+ // Since the line above nullifies the organization_name and employer_id fiels in the contact record, we need to reload all blocks to reflect this chage on the user interface.
+ $this->ajaxResponse['reloadBlocks'] = array('#crm-contactinfo-content');
+
return;
}
// clear the current employer. CRM-3235.
$relChanged = $params['relationship_type_id'] != $this->_values['relationship_type_id'];
if (!$params['is_active'] || !$params['is_current_employer'] || $relChanged) {
+
+ // CRM-15881 UPDATES
+ // If not is_active then is_current_employer needs to be set false as well! Logically a contact cannot be a current employee of a disabled employer relationship.
+ // If this is not done, then the below process will go ahead and disable the organization_name and employer_id fields in the contact record (which is what is wanted) but then further down will be re-enabled becuase is_current_employer is not false, therefore undoing what was done correctly.
+ if (!$params['is_active']) {
+ $params['is_current_employer'] = FALSE;
+ }
+
CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($this->_values['contact_id_a']);
// Refresh contact summary if in ajax mode
$this->ajaxResponse['reloadBlocks'] = array('#crm-contactinfo-content');