X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FContact%2FBAO%2FRelationship.php;h=f856699a3a7aa74d4c91026ec966d5344788537a;hb=93aef68e1e33a2ade20f1523f037b0db44ed2caa;hp=7fe41c1b75e935b4368136bd760f29c4005a9234;hpb=fd377e02836ad47dc4e31f3ecc4e855677c92288;p=civicrm-core.git diff --git a/CRM/Contact/BAO/Relationship.php b/CRM/Contact/BAO/Relationship.php index 7fe41c1b75..f856699a3a 100644 --- a/CRM/Contact/BAO/Relationship.php +++ b/CRM/Contact/BAO/Relationship.php @@ -717,7 +717,7 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship { */ public static function del($id) { // delete from relationship table - CRM_Utils_Hook::pre('delete', 'Relationship', $id, CRM_Core_DAO::$_nullArray); + CRM_Utils_Hook::pre('delete', 'Relationship', $id); $relationship = self::clearCurrentEmployer($id, CRM_Core_Action::DELETE); $relationship->delete(); @@ -1896,14 +1896,15 @@ AND cc.sort_name LIKE '%$name%'"; public static function mergeRelationships($mainId, $otherId, &$sqls) { // Delete circular relationships $sqls[] = "DELETE FROM civicrm_relationship - WHERE (contact_id_a = $mainId AND contact_id_b = $otherId) - OR (contact_id_b = $mainId AND contact_id_a = $otherId)"; + WHERE (contact_id_a = $mainId AND contact_id_b = $otherId AND case_id IS NULL) + OR (contact_id_b = $mainId AND contact_id_a = $otherId AND case_id IS NULL)"; // Delete relationship from other contact if main contact already has that relationship $sqls[] = "DELETE r2 FROM civicrm_relationship r1, civicrm_relationship r2 WHERE r1.relationship_type_id = r2.relationship_type_id AND r1.id <> r2.id + AND r1.case_id IS NULL AND r2.case_id IS NULL AND ( r1.contact_id_a = $mainId AND r2.contact_id_a = $otherId AND r1.contact_id_b = r2.contact_id_b OR r1.contact_id_b = $mainId AND r2.contact_id_b = $otherId AND r1.contact_id_a = r2.contact_id_a @@ -2203,71 +2204,19 @@ AND cc.sort_name LIKE '%$name%'"; * @inheritdoc */ public static function buildOptions($fieldName, $context = NULL, $props = []) { - if ($fieldName === 'relationship_type_id') { - return self::buildRelationshipTypeOptions($props); + // Quickform-specific format, for use when editing relationship type options in a popup from the contact relationship form + if ($fieldName === 'relationship_type_id' && !empty($props['is_form'])) { + return self::getContactRelationshipType( + $props['contact_id'] ?? NULL, + $props['relationship_direction'] ?? 'a_b', + $props['relationship_id'] ?? NULL, + $props['contact_type'] ?? NULL + ); } return parent::buildOptions($fieldName, $context, $props); } - /** - * Builds a list of options available for relationship types - * - * @param array $params - * - contact_type: Limits by contact type on the "A" side - * - relationship_id: Used to find the value for contact type for "B" side. - * If contact_a matches provided contact_id then type of contact_b will - * be used. Otherwise uses type of contact_a. Must be used with contact_id - * - contact_id: Limits by contact types of this contact on the "A" side - * - is_form: Returns array with keys indexed for use in a quickform - * - relationship_direction: For relationship types with duplicate names - * on both sides, defines which option should be returned, a_b or b_a - * - * @return array - */ - public static function buildRelationshipTypeOptions($params = []) { - $contactId = $params['contact_id'] ?? NULL; - $direction = CRM_Utils_Array::value('relationship_direction', $params, 'a_b'); - $relationshipId = $params['relationship_id'] ?? NULL; - $contactType = $params['contact_type'] ?? NULL; - $isForm = $params['is_form'] ?? NULL; - $showAll = FALSE; - - // getContactRelationshipType will return an empty set if these are not set - if (!$contactId && !$relationshipId && !$contactType) { - $showAll = TRUE; - } - - $labels = self::getContactRelationshipType( - $contactId, - $direction, - $relationshipId, - $contactType, - $showAll, - 'label' - ); - - if ($isForm) { - return $labels; - } - - $names = self::getContactRelationshipType( - $contactId, - $direction, - $relationshipId, - $contactType, - $showAll, - 'name' - ); - - // ensure $names contains only entries in $labels - $names = array_intersect_key($names, $labels); - - $nameToLabels = array_combine($names, $labels); - - return $nameToLabels; - } - /** * Process the params from api, form and check if current * employer should be set or unset.