diff --git a/CRM/Contact/BAO/Relationship.php b/CRM/Contact/BAO/Relationship.php index c942c3f7a890..cde90f8bc056 100644 --- a/CRM/Contact/BAO/Relationship.php +++ b/CRM/Contact/BAO/Relationship.php @@ -120,7 +120,7 @@ public static function createMultiple($params, $primaryContactLetter) { foreach ($secondaryContactIDs as $secondaryContactID) { try { $params['contact_id_' . $secondaryContactLetter] = $secondaryContactID; - $relationship = civicrm_api3('relationship', 'create', $params); + $relationship = \Civi\Api4\Relationship::create(FALSE)->setValues($params)->execute()->first(); $relationshipIDs[] = $relationship['id']; $valid++; } @@ -1774,10 +1774,11 @@ public static function disableExpiredRelationships() { * @throws \CRM_Core_Exception */ public static function membershipTypeToRelationshipTypes(&$params, $direction = NULL) { - $membershipType = civicrm_api3('membership_type', 'getsingle', [ - 'id' => $params['membership_type_id'], - 'return' => 'relationship_type_id, relationship_direction', - ]); + $membershipType = \Civi\Api4\MembershipType::get(FALSE) + ->addSelect('relationship_type_id', 'relationship_direction') + ->addWhere('id', '=', $params['membership_type_id']) + ->execute() + ->first(); $relationshipTypes = $membershipType['relationship_type_id']; if (empty($relationshipTypes)) { return NULL; @@ -2047,7 +2048,7 @@ public static function buildOptions($fieldName, $context = NULL, $props = []) { public static function isCurrentEmployerNeedingToBeCleared($params, $relationshipId, $updatedRelTypeID = NULL) { $existingTypeID = (int) CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Relationship', $relationshipId, 'relationship_type_id'); $updatedRelTypeID = $updatedRelTypeID ?: $existingTypeID; - $currentEmployerID = (int) civicrm_api3('Contact', 'getvalue', ['return' => 'current_employer_id', 'id' => $params['contact_id_a']]); + $currentEmployerID = (int) \Civi\Api4\Contact::get(FALSE)->addSelect('current_employer_id')->addWhere('id', '=', $params['contact_id_a'])->execute()->first()['current_employer_id']; if ($currentEmployerID !== (int) $params['contact_id_b'] || !self::isRelationshipTypeCurrentEmployer($existingTypeID)) { return FALSE; @@ -2062,13 +2063,7 @@ public static function isCurrentEmployerNeedingToBeCleared($params, $relationshi || ((isset($params['is_active']) && empty($params['is_active']))) || $existingTypeID != $updatedRelTypeID) { // If there are no other active employer relationships between the same 2 contacts... - if (!civicrm_api3('Relationship', 'getcount', [ - 'is_active' => 1, - 'relationship_type_id' => $existingTypeID, - 'id' => ['<>' => $params['id']], - 'contact_id_a' => $params['contact_id_a'], - 'contact_id_b' => $params['contact_id_b'], - ])) { + if (!\Civi\Api4\Relationship::get(FALSE)->selectRowCount()->addWhere('is_active', '=', TRUE)->addWhere('relationship_type_id', '=', $existingTypeID)->addWhere('id', '!=', $params['id'])->addWhere('contact_id_a', '=', $params['contact_id_a'])->addWhere('contact_id_b', '=', $params['contact_id_b'])->execute()->count()) { return TRUE; } }