/** * This is the function to get the list of relationships * * @param int $contactId contact id * @param int $status 1: Past 2: Disabled 3: Current * @param int $numRelationship no of relationships to display (limit) * @param int $count get the no of relationships * $param int $relationshipId relationship id * $param array $links the list of links to display * $param int $permissionMask the permission mask to be applied for the actions * * return array $values relationship records * @static * @access public */ function getRelationship($contactId, $status = 0, $numRelationship = 0, $count = 0, $relationshipId = 0, $links = null, $permissionMask = null) { list($select1, $from1, $where1) = CRM_Contact_BAO_Relationship::makeURLClause($contactId, $status, $numRelationship, $count, $relationshipId, 'a_b'); list($select2, $from2, $where2) = CRM_Contact_BAO_Relationship::makeURLClause($contactId, $status, $numRelationship, $count, $relationshipId, 'b_a'); $order = $limit = ''; if (!$count) { $order = ' ORDER BY civicrm_relationship_type_id, sort_name '; if ($numRelationship) { $limit = " LIMIT 0, {$numRelationship}"; } } // building the query string $queryString = ''; $queryString = $select1 . $from1 . $where1 . $select2 . $from2 . $where2 . $order . $limit; $relationship =& new CRM_Contact_DAO_Relationship(); $relationship->query($queryString); $row = array(); if ($count) { $relationshipCount = 0; while ($relationship->fetch()) { $relationshipCount += $relationship->cnt1 + $relationship->cnt2; } return $relationshipCount; } else { $values = array(); $mask = null; if ($links) { $mask = array_sum(array_keys($links)); if ($mask & CRM_CORE_ACTION_DISABLE) { $mask -= CRM_CORE_ACTION_DISABLE; } if ($mask & CRM_CORE_ACTION_ENABLE) { $mask -= CRM_CORE_ACTION_ENABLE; } if ($status == CRM_CONTACT_BAO_RELATIONSHIP_CURRENT) { $mask |= CRM_CORE_ACTION_DISABLE; } else { if ($status == CRM_CONTACT_BAO_RELATIONSHIP_DISABLED) { $mask |= CRM_CORE_ACTION_ENABLE; } } $mask = $mask & $permissionMask; } while ($relationship->fetch()) { $rid = $relationship->civicrm_relationship_id; $values[$rid]['id'] = $rid; $values[$rid]['cid'] = $relationship->civicrm_contact_id; $values[$rid]['relation'] = $relationship->relation; $values[$rid]['name'] = $relationship->sort_name; $values[$rid]['email'] = $relationship->email; $values[$rid]['phone'] = $relationship->phone; $values[$rid]['city'] = $relationship->city; $values[$rid]['state'] = $relationship->state; $values[$rid]['start_date'] = $relationship->start_date; $values[$rid]['end_date'] = $relationship->end_date; $values[$rid]['is_active'] = $relationship->is_active; if ($relationship->name_a_b == $relationship->relation) { $values[$rid]['rtype'] = 'a_b'; } else { $values[$rid]['rtype'] = 'b_a'; } if ($links) { $replace = array('id' => $rid, 'rtype' => $values[$rid]['rtype'], 'cid' => $contactId); $values[$rid]['action'] = CRM_Core_Action::formLink($links, $mask, $replace); } } return $values; } }