CRM-21849: Add getoptions spec params for relationship_type_id
authorMichael Devery <michael@compucorp.co.uk>
Wed, 21 Mar 2018 16:34:11 +0000 (16:34 +0000)
committerMichael Devery <michael@compucorp.co.uk>
Mon, 16 Apr 2018 12:45:59 +0000 (13:45 +0100)
api/v3/Relationship.php

index bab339b835ac1dbcce3a2d538394f8506deb2dcf..22cd6ddf0a30d61d4ecff09f2461e485dccec730 100644 (file)
@@ -169,3 +169,53 @@ function civicrm_api3_relationship_setvalue($params) {
   }
   return $result;
 }
+
+function _civicrm_api3_relationship_getoptions_spec(&$params) {
+  $params['field']['options']['relationship_type_id'] = ts('Relationship Type ID');
+
+  // Add parameters for limiting relationship type ID
+  $relationshipTypePrefix = ts('(For relationship_type_id only) ');
+  $params['contact_id'] = [
+    'title' => ts('Contact ID'),
+    'description' => $relationshipTypePrefix . ts('Limits options to those'
+      . ' available to give contact'),
+    'type' => CRM_Utils_Type::T_INT,
+    'FKClassName' => 'CRM_Contact_DAO_Contact',
+    'FKApiName' => 'Contact',
+  ];
+  $params['relationship_direction'] = [
+    'title' => ts('Relationship Direction'),
+    'description' => $relationshipTypePrefix . ts('For relationships where the '
+      . 'name is the same for both sides (i.e. "Spouse Of") show the option '
+      . 'from "A" (origin) side or "B" (target) side of the relationship?'),
+    'type' => CRM_Utils_Type::T_STRING,
+    'options' => ['a_b' => 'a_b', 'b_a' => 'b_a'],
+    'api.default' => 'a_b',
+  ];
+  $params['relationship_id'] = [
+    'title' => ts('Reference Relationship ID'),
+    'description' => $relationshipTypePrefix . ts('If provided alongside '
+      . 'contact ID it will be used to establish the contact type of the "B" '
+      . 'side of the relationship and limit options based on it. If the '
+      . 'provided contact ID does not match the "A" side of this relationship '
+      . 'then the "A" side of this relationship will be used to limit options'),
+    'type' => CRM_Utils_Type::T_INT,
+    'FKClassName' => 'CRM_Contact_DAO_Relationship',
+    'FKApiName' => 'Relationship',
+  ];
+  $contactTypes = CRM_Contact_BAO_ContactType::contactTypes();
+  $params['contact_type'] = [
+    'title' => ts('Contact Type'),
+    'description' => $relationshipTypePrefix . ts('Limits options to those '
+    . 'available to this contact type. Overridden by the contact type of '
+    . 'contact ID (if provided)'),
+    'type' => CRM_Utils_Type::T_STRING,
+    'options' => array_combine($contactTypes, $contactTypes),
+  ];
+  $params['is_form'] = [
+    'title' => ts('Is Form?'),
+    'description' => $relationshipTypePrefix . ts('Formats the options for use'
+      . ' in a form if true. The format is &lt;id&gt;_a_b => &lt;label&gt;'),
+    'type' => CRM_Utils_Type::T_BOOLEAN
+  ];
+}