X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FContact%2FBAO%2FRelationship.php;h=fc8f192a0a55f449885e338474accf3ea276df1a;hb=d0592c3d38c59d5a263a5fb70be8af6dc97f1692;hp=68bb10fcd8ee1587c57136ab67718e93810f0af2;hpb=992fa840d8ba027c64fc1a46c77d6b288337222b;p=civicrm-core.git diff --git a/CRM/Contact/BAO/Relationship.php b/CRM/Contact/BAO/Relationship.php index 68bb10fcd8..fc8f192a0a 100644 --- a/CRM/Contact/BAO/Relationship.php +++ b/CRM/Contact/BAO/Relationship.php @@ -963,15 +963,24 @@ LEFT JOIN civicrm_country ON (civicrm_address.country_id = civicrm_country.id) $order = $limit = ''; if (!$count) { - $order = ' ORDER BY civicrm_relationship_type_id, sort_name '; + if (empty($params['sort'])) { + $order = ' ORDER BY civicrm_relationship_type_id, sort_name '; + } + else { + $order = " ORDER BY {$params['sort']} "; + } + + $offset = 0; + if (!empty($params['offset'])) { + $offset = $params['offset']; + } if ($numRelationship) { - $limit = " LIMIT 0, $numRelationship"; + $limit = " LIMIT {$offset}, $numRelationship"; } } // building the query string - $queryString = ''; $queryString = $select1 . $from1 . $where1 . $select2 . $from2 . $where2 . $order . $limit; $relationship = new CRM_Contact_DAO_Relationship(); @@ -1496,36 +1505,6 @@ AND cc.sort_name LIKE '%$name%'"; return $contacts; } - static function getValidContactTypeList($relType) { - // string looks like 4_a_b - $rel_parts = explode('_', $relType); - $allRelationshipType = CRM_Core_PseudoConstant::relationshipType('label'); - $contactProfiles = CRM_Core_BAO_UFGroup::getReservedProfiles('Contact', NULL); - - if ($rel_parts[1] == 'a') { - $leftType = $allRelationshipType[$rel_parts[0]]['contact_type_b']; - } - else { - $leftType = $allRelationshipType[$rel_parts[0]]['contact_type_a']; - } - - // Handle 'All Contacts' contact type for left side of relationship ($leftType is empty in this case) - // In this case all reserved profiles are available - if ($leftType == '') { - $contactTypes = $contactProfiles; - } else { - $contactTypes = array(); - foreach ($contactProfiles as $key => $value) { - $groupTypes = CRM_Core_BAO_UFGroup::profileGroups($key); - if (in_array($leftType, $groupTypes)) { - $contactTypes = array($key => $value); - } - } - } - - return $contactTypes; - } - /** * Merge relationships from otherContact to mainContact * Called during contact merge operation @@ -1629,5 +1608,115 @@ AND cc.sort_name LIKE '%$name%'"; } } } + + + /** + * This function is a wrapper for contact relationship selector + * + * @param array $params associated array for params record id. + * + * @return array $contactRelationships associated array of contact relationships + * @access public + */ + public static function getContactRelationshipSelector(&$params) { + // format the params + $params['offset'] = ($params['page'] - 1) * $params['rp']; + $params['sort'] = CRM_Utils_Array::value('sortBy', $params); + + if ($params['context'] == 'past') { + $relationshipStatus = CRM_Contact_BAO_Relationship::INACTIVE; + } + else { + $relationshipStatus = CRM_Contact_BAO_Relationship::CURRENT; + } + + // check logged in user for permission + $page = new CRM_Core_Page(); + CRM_Contact_Page_View::checkUserPermission($page, $params['contact_id']); + $permissions = array($page->_permission); + if ($page->_permission == CRM_Core_Permission::EDIT) { + $permissions[] = CRM_Core_Permission::DELETE; + } + $mask = CRM_Core_Action::mask($permissions); + + if ($params['context'] != 'user') { + $links = CRM_Contact_Page_View_Relationship::links(); + $permissionedContacts = FALSE; + } + else { + $links = CRM_Contact_Page_View_UserDashBoard::links(); + $permissionedContacts = TRUE; + $mask = NULL; + } + // get contact relationships + $relationships = CRM_Contact_BAO_Relationship::getRelationship($params['contact_id'], + $relationshipStatus, + $params['rp'], 0, 0, + $links, $mask, + $permissionedContacts, + $params + ); + + $contactRelationships = array(); + $params['total'] = 0; + if (!empty($relationships)) { + // get the total relationships + if ($params['context'] != 'user') { + $params['total'] = CRM_Contact_BAO_Relationship::getRelationship($params['contact_id'], + $relationshipStatus, 0, 1, 0, NULL, NULL, $permissionedContacts); + } + else { + // FIX ME: we cannot directly determine total permissioned relationship, hence re-fire query + $permissionedRelationships = CRM_Contact_BAO_Relationship::getRelationship($params['contact_id'], + $relationshipStatus, + 0, 0, 0, + NULL, NULL, TRUE + ); + $params['total'] = count($permissionedRelationships); + } + + // format params + foreach ($relationships as $relationshipId => $values) { + $contactRelationships[$relationshipId]['name'] = CRM_Utils_System::href( + $values['name'], + 'civicrm/contact/view', + "reset=1&cid={$values['contact_id_b']}"); + + $contactRelationships[$relationshipId]['relation'] = CRM_Utils_System::href( + $values['relation'], + 'civicrm/contact/view/rel', + "action=view&reset=1&cid={$values['contact_id_a']}&id={$values['id']}&rtype={$values['rtype']}"); + + if ($params['context'] == 'current') { + if (($params['contact_id'] == $values['contact_id_a'] AND $values['is_permission_a_b'] == 1) OR + ($params['contact_id'] == $values['contact_id_b'] AND $values['is_permission_b_a'] == 1) + ) { + $contactRelationships[$relationshipId]['name'] .= ' *'; + } + + if (($values['cid'] == $values['contact_id_a'] AND $values['is_permission_a_b'] == 1) OR + ($values['cid'] == $values['contact_id_b'] AND $values['is_permission_b_a'] == 1) + ) { + $contactRelationships[$relationshipId]['relation'] .= ' *'; + } + } + + if (!empty($values['description'])) { + $contactRelationships[$relationshipId]['relation'] .= "

{$values['description']}

"; + } + + $contactRelationships[$relationshipId]['start_date'] = CRM_Utils_Date::customFormat($values['start_date']); + $contactRelationships[$relationshipId]['end_date'] = CRM_Utils_Date::customFormat($values['end_date']); + $contactRelationships[$relationshipId]['city'] = $values['city']; + $contactRelationships[$relationshipId]['state'] = $values['state']; + $contactRelationships[$relationshipId]['email'] = $values['email']; + $contactRelationships[$relationshipId]['phone'] = $values['phone']; + $contactRelationships[$relationshipId]['links'] = $values['action']; + $contactRelationships[$relationshipId]['id'] = $values['id']; + } + } + return $contactRelationships; + } + }