Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions CRM/Contact/BAO/Relationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
}
Expand Down