diff --git a/CRM/Contact/DAO/RelationshipCache.php b/CRM/Contact/DAO/RelationshipCache.php index 5b8f62cb2f59..ddb541bb7027 100644 --- a/CRM/Contact/DAO/RelationshipCache.php +++ b/CRM/Contact/DAO/RelationshipCache.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Contact/RelationshipCache.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:6a586a5a5550a64db4c9907387c1411d) + * (GenCodeChecksum:d511533f30d5d2d8deac82664a6288d1) */ /** @@ -207,6 +207,9 @@ public static function &fields() { 'entity' => 'RelationshipCache', 'bao' => 'CRM_Contact_BAO_RelationshipCache', 'localizable' => 0, + 'pseudoconstant' => [ + 'callback' => 'CRM_Core_SelectValues::relationshipOrientation', + ], 'add' => '5.29', ], 'near_contact_id' => [ @@ -221,6 +224,9 @@ public static function &fields() { 'bao' => 'CRM_Contact_BAO_RelationshipCache', 'localizable' => 0, 'FKClassName' => 'CRM_Contact_DAO_Contact', + 'html' => [ + 'type' => 'EntityRef', + ], 'add' => '5.29', ], 'near_relation' => [ @@ -235,6 +241,9 @@ public static function &fields() { 'entity' => 'RelationshipCache', 'bao' => 'CRM_Contact_BAO_RelationshipCache', 'localizable' => 0, + 'pseudoconstant' => [ + 'callback' => 'CRM_Core_PseudoConstant::relationshipTypeOptions', + ], 'add' => '5.29', ], 'far_contact_id' => [ @@ -266,6 +275,9 @@ public static function &fields() { 'entity' => 'RelationshipCache', 'bao' => 'CRM_Contact_BAO_RelationshipCache', 'localizable' => 0, + 'pseudoconstant' => [ + 'callback' => 'CRM_Core_PseudoConstant::relationshipTypeOptions', + ], 'add' => '5.29', ], 'is_active' => [ diff --git a/CRM/Core/PseudoConstant.php b/CRM/Core/PseudoConstant.php index 2fdc70868235..758db214acba 100644 --- a/CRM/Core/PseudoConstant.php +++ b/CRM/Core/PseudoConstant.php @@ -952,6 +952,23 @@ public static function relationshipType($valueColumnName = 'label', $reset = FAL return self::$relationshipType[$cacheKey]; } + /** + * Name => Label pairs for all relationship types + * + * @return array + */ + public static function relationshipTypeOptions() { + $relationshipTypes = []; + $relationshipLabels = self::relationshipType(); + foreach (self::relationshipType('name') as $id => $type) { + $relationshipTypes[$type['name_a_b']] = $relationshipLabels[$id]['label_a_b']; + if ($type['name_b_a'] && $type['name_b_a'] != $type['name_a_b']) { + $relationshipTypes[$type['name_b_a']] = $relationshipLabels[$id]['label_b_a']; + } + } + return $relationshipTypes; + } + /** * Get all the ISO 4217 currency codes * diff --git a/CRM/Core/SelectValues.php b/CRM/Core/SelectValues.php index 02d654549993..92a534d37d92 100644 --- a/CRM/Core/SelectValues.php +++ b/CRM/Core/SelectValues.php @@ -1196,4 +1196,14 @@ public static function navigationMenuSeparator() { ]; } + /** + * @return array + */ + public static function relationshipOrientation() { + return [ + 'a_b' => ts('A to B'), + 'b_a' => ts('B to A'), + ]; + } + } diff --git a/Civi/Api4/RelationshipCache.php b/Civi/Api4/RelationshipCache.php new file mode 100644 index 000000000000..4030d331807b --- /dev/null +++ b/Civi/Api4/RelationshipCache.php @@ -0,0 +1,49 @@ +setCheckPermissions($checkPermissions); + } + + /** + * @param bool $checkPermissions + * @return Generic\DAOGetFieldsAction + */ + public static function getFields($checkPermissions = TRUE) { + return (new Generic\DAOGetFieldsAction(static::class, __FUNCTION__)) + ->setCheckPermissions($checkPermissions); + } + +} diff --git a/tests/phpunit/api/v4/Entity/RelationshipTest.php b/tests/phpunit/api/v4/Entity/RelationshipTest.php new file mode 100644 index 000000000000..81ab67d9b1bf --- /dev/null +++ b/tests/phpunit/api/v4/Entity/RelationshipTest.php @@ -0,0 +1,50 @@ +addValue('first_name', '1')->execute()->first()['id']; + $c2 = Contact::create(FALSE)->addValue('first_name', '2')->execute()->first()['id']; + Relationship::create(FALSE) + ->setValues([ + 'contact_id_a' => $c1, + 'contact_id_b' => $c2, + 'relationship_type_id' => 1, + ])->execute(); + $cacheRecords = RelationshipCache::get(FALSE) + ->addClause('OR', ['near_contact_id', '=', $c1], ['far_contact_id', '=', $c1]) + ->execute(); + $this->assertCount(2, $cacheRecords); + } + +} diff --git a/xml/schema/Contact/RelationshipCache.xml b/xml/schema/Contact/RelationshipCache.xml index e522e4588b3f..dd6c2c401a7d 100644 --- a/xml/schema/Contact/RelationshipCache.xml +++ b/xml/schema/Contact/RelationshipCache.xml @@ -60,7 +60,9 @@ 3 Orientation (a_b or b_a) true - + + CRM_Core_SelectValues::relationshipOrientation + The cache record is a permutation of the original relationship record. The orientation indicates whether it is forward (a_b) or reverse (b_a) relationship. 5.29 @@ -72,6 +74,9 @@ true id of the first contact 5.29 + + EntityRef + near_contact_id @@ -88,6 +93,9 @@ 64 name for relationship of near_contact to far_contact. 5.29 + + CRM_Core_PseudoConstant::relationshipTypeOptions + @@ -116,6 +124,9 @@ 64 name for relationship of far_contact to near_contact. 5.29 + + CRM_Core_PseudoConstant::relationshipTypeOptions +