CRM-20091 - Specify return params from getTree
authorColeman Watts <coleman@civicrm.org>
Fri, 2 Jun 2017 22:08:34 +0000 (18:08 -0400)
committerColeman Watts <coleman@civicrm.org>
Sat, 3 Jun 2017 00:35:36 +0000 (20:35 -0400)
31 files changed:
CRM/Activity/Form/Activity.php
CRM/Case/Form/CaseView.php
CRM/Case/Form/CustomData.php
CRM/Contact/Form/CustomData.php
CRM/Contact/Form/Edit/Address.php
CRM/Contact/Form/Search/Custom/MultipleValues.php
CRM/Contact/Import/Parser/Contact.php
CRM/Contact/Page/Inline/Address.php
CRM/Contact/Page/Inline/CustomData.php
CRM/Contact/Page/View/CustomData.php
CRM/Contact/Page/View/Relationship.php
CRM/Contact/Page/View/Summary.php
CRM/Contribute/BAO/Contribution.php
CRM/Contribute/Form/ContributionView.php
CRM/Core/BAO/CustomGroup.php
CRM/Core/BAO/UFGroup.php
CRM/Custom/Form/CustomData.php
CRM/Dedupe/BAO/RuleGroup.php
CRM/Dedupe/Finder.php
CRM/Dedupe/Merger.php
CRM/Event/Form/ParticipantView.php
CRM/Event/Form/Registration/Confirm.php
CRM/Event/Page/EventInfo.php
CRM/Grant/Form/GrantView.php
CRM/Member/Form/MembershipRenewal.php
CRM/Member/Form/MembershipView.php
CRM/Pledge/BAO/Pledge.php
CRM/Pledge/Form/PledgeView.php
api/v3/CustomValue.php
templates/CRM/Admin/Page/APIExplorer.js
tests/phpunit/api/v3/CustomValueTest.php

index d0b6dad586a68ee646e7877f25f092ed264e5ac3..071e3c1bad94d60c9de8422c07902cb917360858 100644 (file)
@@ -377,7 +377,7 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task {
 
     if ($this->_action & CRM_Core_Action::VIEW) {
       // Get the tree of custom fields.
-      $this->_groupTree = CRM_Core_BAO_CustomGroup::getTree('Activity', $this,
+      $this->_groupTree = CRM_Core_BAO_CustomGroup::getTree('Activity', NULL,
         $this->_activityId, 0, $this->_activityTypeId
       );
     }
index a25e79ae17690809f4d92c363b4c2d9d8128da69..07a24dc106e484b3989a6e3237fe565b5b6c75f1 100644 (file)
@@ -162,7 +162,7 @@ class CRM_Case_Form_CaseView extends CRM_Core_Form {
     $entitySubType = !empty($values['case_type_id']) ? $values['case_type_id'] : NULL;
     $this->assign('caseTypeID', $entitySubType);
     $groupTree = CRM_Core_BAO_CustomGroup::getTree('Case',
-      $this,
+      NULL,
       $this->_caseID,
       NULL,
       $entitySubType
index 5b2b3c551f09f422cbcfe82b92f409a7d9329cd5..e7b7e139ace1521b2ea5476dd42ebb157b6cc8f2 100644 (file)
@@ -66,7 +66,7 @@ class CRM_Case_Form_CustomData extends CRM_Core_Form {
     $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
 
     $groupTree = CRM_Core_BAO_CustomGroup::getTree('Case',
-      $this,
+      NULL,
       $this->_entityID,
       $this->_groupID,
       $this->_subTypeID
index a9aad3381c110afe3a511d4f380e6ba24be0420c..fa4bf98db578711efc29c7d89bd8f65b7b47db88 100644 (file)
@@ -231,7 +231,7 @@ class CRM_Contact_Form_CustomData extends CRM_Core_Form {
       if ($this->_copyValueId) {
         // cached tree is fetched
         $groupTree = CRM_Core_BAO_CustomGroup::getTree($this->_type,
-          $this,
+          NULL,
           $this->_entityId,
           $this->_groupID,
           array(),
@@ -261,7 +261,7 @@ class CRM_Contact_Form_CustomData extends CRM_Core_Form {
     }
 
     $groupTree = CRM_Core_BAO_CustomGroup::getTree($this->_contactType,
-      $this,
+      NULL,
       $this->_tableID,
       $this->_groupID,
       $this->_contactSubType
@@ -269,7 +269,7 @@ class CRM_Contact_Form_CustomData extends CRM_Core_Form {
 
     if (empty($_POST['hidden_custom_group_count'])) {
       // custom data building in edit mode (required to handle multi-value)
-      $groupTree = CRM_Core_BAO_CustomGroup::getTree($this->_contactType, $this, $this->_tableID,
+      $groupTree = CRM_Core_BAO_CustomGroup::getTree($this->_contactType, NULL, $this->_tableID,
         $this->_groupID, $this->_contactSubType
       );
       $customValueCount = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, TRUE, $this->_groupID, NULL, NULL, $this->_tableID);
index f8a0a1a9bc838281d7abd7a95ffe0510a4c64d06..d7b0275ad92ea9b79414dd52201b9c371071f25d 100644 (file)
@@ -163,10 +163,7 @@ class CRM_Contact_Form_Edit_Address {
     $form->assign('geoCode', $geoCode);
 
     // Process any address custom data -
-    $groupTree = CRM_Core_BAO_CustomGroup::getTree('Address',
-      $form,
-      $entityId
-    );
+    $groupTree = CRM_Core_BAO_CustomGroup::getTree('Address', NULL, $entityId);
 
     if (isset($groupTree) && is_array($groupTree)) {
       // use simplified formatted groupTree
index ad6809484c220af4a7225c8b4a144f461209a2f4..af2ed673370de14d419e40cf36875d0a900bac4a 100644 (file)
@@ -47,10 +47,7 @@ class CRM_Contact_Form_Search_Custom_MultipleValues extends CRM_Contact_Form_Sea
   public function __construct(&$formValues) {
     parent::__construct($formValues);
 
-    $this->_groupTree = CRM_Core_BAO_CustomGroup::getTree("'Contact', 'Individual', 'Organization', 'Household'",
-      CRM_Core_DAO::$_nullObject,
-      NULL, -1
-    );
+    $this->_groupTree = CRM_Core_BAO_CustomGroup::getTree("'Contact', 'Individual', 'Organization', 'Household'", NULL, NULL, -1);
 
     $this->_group = CRM_Utils_Array::value('group', $this->_formValues);
 
index aa4a3fde5d21228b0e025275571edaf26a676cd9..599e952c23559e67eaa9492646f1753db7f0e268 100644 (file)
@@ -1750,7 +1750,7 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Contact_Import_Parser {
       $modeFill = TRUE;
     }
 
-    $groupTree = CRM_Core_BAO_CustomGroup::getTree($params['contact_type'], CRM_Core_DAO::$_nullObject, $cid, 0, NULL);
+    $groupTree = CRM_Core_BAO_CustomGroup::getTree($params['contact_type'], NULL, $cid, 0, NULL);
     CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $defaults, FALSE, FALSE);
 
     $locationFields = array(
index 115078880bea6dbd49a4519a45d6b2482aadd03a..8819dfda98e1392afaa31ad64ed55b6765233ef2 100644 (file)
@@ -83,9 +83,7 @@ class CRM_Contact_Page_Inline_Address extends CRM_Core_Page {
       }
 
       // add custom data of type address
-      $groupTree = CRM_Core_BAO_CustomGroup::getTree('Address',
-        $this, $idValue
-      );
+      $groupTree = CRM_Core_BAO_CustomGroup::getTree('Address', NULL, $idValue);
 
       // we setting the prefix to dnc_ below so that we don't overwrite smarty's grouptree var.
       $currentAddressBlock['address'][$locBlockNo]['custom'] = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, "dnc_");
index 3b87f36acae108f2a3a504ea2a68a996d8bbc989..8705b3ddc6e9834732dcab5b3c8a4fef77533918 100644 (file)
@@ -51,7 +51,7 @@ class CRM_Contact_Page_Inline_CustomData extends CRM_Core_Page {
     //custom groups Inline
     $entityType = CRM_Contact_BAO_Contact::getContactType($contactId);
     $entitySubType = CRM_Contact_BAO_Contact::getContactSubType($contactId);
-    $groupTree = CRM_Core_BAO_CustomGroup::getTree($entityType, $this, $contactId,
+    $groupTree = CRM_Core_BAO_CustomGroup::getTree($entityType, NULL, $contactId,
       $cgId, $entitySubType
     );
     $details = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $contactId);
index 4ecfa0bcd634db413f11d88ce2874f4a28777fb4..33e6ca6bb6b2383e2c48c7c73c0004daece5553d 100644 (file)
@@ -140,7 +140,7 @@ class CRM_Contact_Page_View_CustomData extends CRM_Core_Page {
         if ($this->_multiRecordDisplay == 'single') {
           $groupTitle = CRM_Core_BAO_CustomGroup::getTitle($this->_groupId);
           CRM_Utils_System::setTitle(ts('View %1 Record', array(1 => $groupTitle)));
-          $groupTree = CRM_Core_BAO_CustomGroup::getTree($entityType, $this, $this->_contactId,
+          $groupTree = CRM_Core_BAO_CustomGroup::getTree($entityType, NULL, $this->_contactId,
             $this->_groupId, $entitySubType, NULL, TRUE, NULL, FALSE, TRUE, $this->_cgcount
           );
 
@@ -149,7 +149,7 @@ class CRM_Contact_Page_View_CustomData extends CRM_Core_Page {
           $this->assign('skipTitle', 1);
         }
         else {
-          $groupTree = CRM_Core_BAO_CustomGroup::getTree($entityType, $this, $this->_contactId,
+          $groupTree = CRM_Core_BAO_CustomGroup::getTree($entityType, NULL, $this->_contactId,
             $this->_groupId, $entitySubType
           );
         }
index 5e886b0f106024e5fbfad39e054533d7f2250830..47665c20cb08fcd9cae15d979dd77ed213573d6c 100644 (file)
@@ -86,7 +86,7 @@ class CRM_Contact_Page_View_Relationship extends CRM_Core_Page {
     $viewNote = CRM_Core_BAO_Note::getNote($this->_id);
     $this->assign('viewNote', $viewNote);
 
-    $groupTree = CRM_Core_BAO_CustomGroup::getTree('Relationship', $this, $this->_id, 0, $relType);
+    $groupTree = CRM_Core_BAO_CustomGroup::getTree('Relationship', NULL, $this->_id, 0, $relType);
     CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $this->_id);
 
     $rType = CRM_Utils_Array::value('rtype', $viewRelationship[$this->_id]);
index ef4b9c6dfdc91a00d247de36a57b74cc7d55ab17..dd9ec548c7d76fe2df0543e1017eba57d5c864b7 100644 (file)
@@ -57,7 +57,7 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View {
       );
     }
     $groupTree = CRM_Core_BAO_CustomGroup::getTree($entityType,
-      $this,
+      NULL,
       $this->_contactId,
       NULL,
       $entitySubType
@@ -182,10 +182,7 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View {
                 $idValue = $blockVal['master_id'];
               }
             }
-            $groupTree = CRM_Core_BAO_CustomGroup::getTree(ucfirst($key),
-              $this,
-              $idValue
-            );
+            $groupTree = CRM_Core_BAO_CustomGroup::getTree(ucfirst($key), NULL, $idValue);
             // we setting the prefix to dnc_ below so that we don't overwrite smarty's grouptree var.
             $defaults[$key][$blockId]['custom'] = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, "dnc_");
           }
index 64e0ed7596a4fe3213af868d6a51e5e6b9a1709b..7e4cc23a423d6fb8c918148182560033972ff10d 100644 (file)
@@ -2747,7 +2747,7 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac
 
       CRM_Event_BAO_Event::retrieve($eventParams, $values['event']);
       // add custom fields for event
-      $eventGroupTree = CRM_Core_BAO_CustomGroup::getTree('Event', $this->_relatedObjects['event'], $this->_relatedObjects['event']->id);
+      $eventGroupTree = CRM_Core_BAO_CustomGroup::getTree('Event', NULL, $this->_relatedObjects['event']->id);
 
       $eventCustomGroup = array();
       foreach ($eventGroupTree as $key => $group) {
@@ -2775,7 +2775,7 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac
 
       CRM_Event_BAO_Participant::getValues($participantParams, $values['participant'], $participantIds);
       // add custom fields for event
-      $participantGroupTree = CRM_Core_BAO_CustomGroup::getTree('Participant', $this->_relatedObjects['participant'], $this->_relatedObjects['participant']->id);
+      $participantGroupTree = CRM_Core_BAO_CustomGroup::getTree('Participant', NULL, $this->_relatedObjects['participant']->id);
       $participantCustomGroup = array();
       foreach ($participantGroupTree as $key => $group) {
         if ($key === 'info') {
@@ -2827,7 +2827,7 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac
       }
     }
 
-    $groupTree = CRM_Core_BAO_CustomGroup::getTree('Contribution', $this, $this->id);
+    $groupTree = CRM_Core_BAO_CustomGroup::getTree('Contribution', NULL, $this->id);
 
     $customGroup = array();
     foreach ($groupTree as $key => $group) {
index c7866a45bdb440e1945c9219a00a623975fddf2c..21a6fa560f0c7909dfe3c7a2fcebd24f5a88662c 100644 (file)
@@ -103,7 +103,7 @@ class CRM_Contribute_Form_ContributionView extends CRM_Core_Form {
       }
     }
 
-    $groupTree = CRM_Core_BAO_CustomGroup::getTree('Contribution', $this, $id, 0, CRM_Utils_Array::value('financial_type_id', $values));
+    $groupTree = CRM_Core_BAO_CustomGroup::getTree('Contribution', NULL, $id, 0, CRM_Utils_Array::value('financial_type_id', $values));
     CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $id);
 
     $premiumId = NULL;
index 74eac1fc6d4e39a03739e9a2234e31ff2740f4b2..12016aa21f94a1071c104d00e3b4e91e5f6ef889 100644 (file)
@@ -317,8 +317,8 @@ class CRM_Core_BAO_CustomGroup extends CRM_Core_DAO_CustomGroup {
    *
    * @param string $entityType
    *   Of the contact whose contact type is needed.
-   * @param CRM_Core_Form $deprecated
-   *   Not used.
+   * @param array $toReturn
+   *   What data should be returned. ['custom_group' => ['id', 'name', etc.], 'custom_field' => ['id', 'label', etc.]]
    * @param int $entityID
    * @param int $groupID
    * @param array $subTypes
@@ -331,7 +331,7 @@ class CRM_Core_BAO_CustomGroup extends CRM_Core_DAO_CustomGroup {
    *   api - through which it is properly tested - so can be refactored with some comfort.)
    *
    * @param bool $checkPermission
-   * @param varchar $singleRecord
+   * @param string|int $singleRecord
    *   holds 'new' or id if view/edit/copy form for a single record is being loaded.
    * @param bool $showPublicOnly
    *
@@ -349,7 +349,7 @@ class CRM_Core_BAO_CustomGroup extends CRM_Core_DAO_CustomGroup {
    */
   public static function getTree(
     $entityType,
-    $deprecated = NULL,
+    $toReturn = array(),
     $entityID = NULL,
     $groupID = NULL,
     $subTypes = array(),
@@ -381,9 +381,9 @@ class CRM_Core_BAO_CustomGroup extends CRM_Core_DAO_CustomGroup {
     // create a new tree
     $strWhere = $orderBy = '';
 
-    // using tableData to build the queryString
+    // legacy hardcoded list of data to return
     $tableData = array(
-      'civicrm_custom_field' => array(
+      'custom_field' => array(
         'id',
         'name',
         'label',
@@ -404,7 +404,7 @@ class CRM_Core_BAO_CustomGroup extends CRM_Core_DAO_CustomGroup {
         'option_group_id',
         'in_selector',
       ),
-      'civicrm_custom_group' => array(
+      'custom_group' => array(
         'id',
         'name',
         'table_name',
@@ -421,13 +421,24 @@ class CRM_Core_BAO_CustomGroup extends CRM_Core_DAO_CustomGroup {
         'is_public',
       ),
     );
+    if (!$toReturn || !is_array($toReturn)) {
+      $toReturn = $tableData;
+    }
+    else {
+      $toReturn = array_filter($toReturn) + $tableData;
+      // Merge in required fields that we must have
+      $toReturn['custom_field'] = array_unique(array_merge($toReturn['custom_field'], array('id', 'column_name', 'data_type')));
+      $toReturn['custom_group'] = array_unique(array_merge($toReturn['custom_group'], array('id', 'is_multiple', 'table_name', 'name')));
+      // Validate return fields
+      $toReturn['custom_field'] = array_intersect($toReturn['custom_field'], array_keys(CRM_Core_DAO_CustomField::fieldKeys()));
+      $toReturn['custom_group'] = array_intersect($toReturn['custom_group'], array_keys(CRM_Core_DAO_CustomGroup::fieldKeys()));
+    }
 
     // create select
     $select = array();
-    foreach ($tableData as $tableName => $tableColumn) {
+    foreach ($toReturn as $tableName => $tableColumn) {
       foreach ($tableColumn as $columnName) {
-        $alias = $tableName . "_" . $columnName;
-        $select[] = "{$tableName}.{$columnName} as {$tableName}_{$columnName}";
+        $select[] = "civicrm_{$tableName}.{$columnName} as civicrm_{$tableName}_{$columnName}";
       }
     }
     $strSelect = "SELECT " . implode(', ', $select);
@@ -552,7 +563,7 @@ ORDER BY civicrm_custom_group.weight,
           $groupTree[$groupID]['id'] = $groupID;
 
           // populate the group information
-          foreach ($tableData['civicrm_custom_group'] as $fieldName) {
+          foreach ($toReturn['custom_group'] as $fieldName) {
             $fullFieldName = "civicrm_custom_group_$fieldName";
             if ($fieldName == 'id' ||
               is_null($crmDAO->$fullFieldName)
@@ -581,7 +592,7 @@ ORDER BY civicrm_custom_group.weight,
         $customValueTables[$crmDAO->civicrm_custom_group_table_name][$crmDAO->civicrm_custom_field_column_name] = 1;
         $groupTree[$groupID]['fields'][$fieldId]['id'] = $fieldId;
         // populate information for a custom field
-        foreach ($tableData['civicrm_custom_field'] as $fieldName) {
+        foreach ($toReturn['custom_field'] as $fieldName) {
           $fullFieldName = "civicrm_custom_field_$fieldName";
           if ($fieldName == 'id' ||
             is_null($crmDAO->$fullFieldName)
index a5944a5994a2d6ac199046711099359d1ac4bd2b..77400aeeeb1d326fa702fe674476ca7d4cbcaca5 100644 (file)
@@ -3237,7 +3237,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
           //get the groupTree as per subTypes.
           $groupTree = array();
           foreach ($componentSubType as $subType) {
-            $subTree = CRM_Core_BAO_CustomGroup::getTree($componentBAOName, CRM_Core_DAO::$_nullObject,
+            $subTree = CRM_Core_BAO_CustomGroup::getTree($componentBAOName, NULL,
               $componentId, 0, $values[$subType]
             );
             $groupTree = CRM_Utils_Array::crmArrayMerge($groupTree, $subTree);
index 27b23d300736b5df116a00141dd139893a84adb3..83eaacb5c771a2d2312f4115deeccb0f96a4b47a 100644 (file)
@@ -163,7 +163,7 @@ class CRM_Custom_Form_CustomData {
     }
 
     $groupTree = CRM_Core_BAO_CustomGroup::getTree($form->_type,
-      $form,
+      NULL,
       $form->_entityId,
       $gid,
       $subType,
index 5fd7abb1e9d4297c98916725abfcfa6772408453..5e4096a55aff1eb3cffd720e481522897a3c0d81 100644 (file)
@@ -115,7 +115,7 @@ class CRM_Dedupe_BAO_RuleGroup extends CRM_Dedupe_DAO_RuleGroup {
           }
         }
         // add custom data fields
-        foreach (CRM_Core_BAO_CustomGroup::getTree($ctype, CRM_Core_DAO::$_nullObject, NULL, -1) as $key => $cg) {
+        foreach (CRM_Core_BAO_CustomGroup::getTree($ctype, NULL, NULL, -1) as $key => $cg) {
           if (!is_int($key)) {
             continue;
           }
index f0f17167528638f3ce4050b96457a997834d579b..4504447023001a2eb5a9898a77595e30953e2739 100644 (file)
@@ -238,7 +238,7 @@ class CRM_Dedupe_Finder {
     }
 
     // handle custom data
-    $tree = CRM_Core_BAO_CustomGroup::getTree($ctype, CRM_Core_DAO::$_nullObject, NULL, -1);
+    $tree = CRM_Core_BAO_CustomGroup::getTree($ctype, NULL, NULL, -1);
     CRM_Core_BAO_CustomGroup::postProcess($tree, $fields, TRUE);
     foreach ($tree as $key => $cg) {
       if (!is_int($key)) {
index 4f88b36282a6e75ece27c3f305247225d473f371..91a933f9576ab546d118f4c9c8322989eb96e578 100644 (file)
@@ -1383,7 +1383,7 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
     $mainTree = CRM_Core_BAO_CustomGroup::getTree($main['contact_type'], NULL, $mainId, -1,
       CRM_Utils_Array::value('contact_sub_type', $main), NULL, TRUE, NULL, TRUE, $checkPermissions
     );
-    $otherTree = CRM_Core_BAO_CustomGroup::getTree($main['contact_type'], CRM_Core_DAO::$_nullObject, $otherId, -1,
+    $otherTree = CRM_Core_BAO_CustomGroup::getTree($main['contact_type'], NULL, $otherId, -1,
       CRM_Utils_Array::value('contact_sub_type', $other), NULL, TRUE, NULL, TRUE, $checkPermissions
     );
     CRM_Core_DAO::freeResult();
@@ -1515,9 +1515,7 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
     // fix custom fields so they're edible by createProfileContact()
     static $treeCache = array();
     if (!array_key_exists($migrationInfo['main_details']['contact_type'], $treeCache)) {
-      $treeCache[$migrationInfo['main_details']['contact_type']] = CRM_Core_BAO_CustomGroup::getTree($migrationInfo['main_details']['contact_type'],
-        CRM_Core_DAO::$_nullObject, NULL, -1
-      );
+      $treeCache[$migrationInfo['main_details']['contact_type']] = CRM_Core_BAO_CustomGroup::getTree($migrationInfo['main_details']['contact_type'], NULL, NULL, -1);
     }
 
     $cFields = array();
index 92291661424800b4ac263a421b10881615b68d25..c7d22619a65cebfafcda7f1c47cd2b493c2e6baf 100644 (file)
@@ -142,15 +142,15 @@ class CRM_Event_Form_ParticipantView extends CRM_Core_Form {
     $finalTree = array();
 
     foreach ($allRoleIDs as $k => $v) {
-      $roleGroupTree = CRM_Core_BAO_CustomGroup::getTree('Participant', $this, $participantID, NULL, $v, $roleCustomDataTypeID);
-      $eventGroupTree = CRM_Core_BAO_CustomGroup::getTree('Participant', $this, $participantID, NULL,
+      $roleGroupTree = CRM_Core_BAO_CustomGroup::getTree('Participant', NULL, $participantID, NULL, $v, $roleCustomDataTypeID);
+      $eventGroupTree = CRM_Core_BAO_CustomGroup::getTree('Participant', NULL, $participantID, NULL,
         $values[$participantID]['event_id'], $eventNameCustomDataTypeID
       );
       $eventTypeID = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Event", $values[$participantID]['event_id'], 'event_type_id', 'id');
-      $eventTypeGroupTree = CRM_Core_BAO_CustomGroup::getTree('Participant', $this, $participantID, NULL, $eventTypeID, $eventTypeCustomDataTypeID);
+      $eventTypeGroupTree = CRM_Core_BAO_CustomGroup::getTree('Participant', NULL, $participantID, NULL, $eventTypeID, $eventTypeCustomDataTypeID);
       $groupTree = CRM_Utils_Array::crmArrayMerge($roleGroupTree, $eventGroupTree);
       $groupTree = CRM_Utils_Array::crmArrayMerge($groupTree, $eventTypeGroupTree);
-      $groupTree = CRM_Utils_Array::crmArrayMerge($groupTree, CRM_Core_BAO_CustomGroup::getTree('Participant', $this, $participantID));
+      $groupTree = CRM_Utils_Array::crmArrayMerge($groupTree, CRM_Core_BAO_CustomGroup::getTree('Participant', NULL, $participantID));
       foreach ($groupTree as $treeId => $trees) {
         $finalTree[$treeId] = $trees;
       }
index 7b8c7d1ffb7bd1d99eb339c5c04c3f7d12981465..99b021c9b1c696b7d98daf7e94d3a2824784f355 100644 (file)
@@ -814,7 +814,7 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration {
           }
 
           //get event custom field information
-          $groupTree = CRM_Core_BAO_CustomGroup::getTree('Event', $this, $this->_eventId, 0, $this->_values['event']['event_type_id']);
+          $groupTree = CRM_Core_BAO_CustomGroup::getTree('Event', NULL, $this->_eventId, 0, $this->_values['event']['event_type_id']);
           $primaryParticipant['eventCustomFields'] = $groupTree;
 
           // call postprocess hook before leaving
index 52891e8ec3eb2e5b7d62a73e6049294cfa332d32..8a7b54aa114e316d09356cf1bdb108ea6ce5def9 100644 (file)
@@ -182,7 +182,7 @@ class CRM_Event_Page_EventInfo extends CRM_Core_Page {
     }
 
     //retrieve custom field information
-    $groupTree = CRM_Core_BAO_CustomGroup::getTree('Event', $this, $this->_id, 0, $values['event']['event_type_id'], NULL, TRUE, NULL, FALSE, TRUE, NULL, TRUE);
+    $groupTree = CRM_Core_BAO_CustomGroup::getTree('Event', NULL, $this->_id, 0, $values['event']['event_type_id'], NULL, TRUE, NULL, FALSE, TRUE, NULL, TRUE);
     CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $this->_id);
     $this->assign('action', CRM_Core_Action::VIEW);
     //To show the event location on maps directly on event info page
index 3c2522750e157a32efddad9f49a822ecc576c5f1..a0e872b7688fbcaeca6e0d5538a9ed35fa657985 100644 (file)
@@ -117,7 +117,7 @@ class CRM_Grant_Form_GrantView extends CRM_Core_Form {
     $this->assign('attachment', $attachment);
 
     $grantType = CRM_Core_DAO::getFieldValue("CRM_Grant_DAO_Grant", $this->_id, "grant_type_id");
-    $groupTree = CRM_Core_BAO_CustomGroup::getTree("Grant", $this, $this->_id, 0, $grantType);
+    $groupTree = CRM_Core_BAO_CustomGroup::getTree("Grant", NULL, $this->_id, 0, $grantType);
     CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $this->_id);
 
     $this->assign('id', $this->_id);
index eaf5e2125724867c383da87d051faa5e7b9f0b86..95c98fd3fc34bcb6c44ec806cab5b2fa6449765e 100644 (file)
@@ -655,7 +655,7 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form {
         $this->_params['paidBy'] = $paymentInstrument[$this->_params['payment_instrument_id']];
       }
       //get the group Tree
-      $this->_groupTree = CRM_Core_BAO_CustomGroup::getTree('Membership', $this, $this->_id, FALSE, $this->_memType);
+      $this->_groupTree = CRM_Core_BAO_CustomGroup::getTree('Membership', NULL, $this->_id, FALSE, $this->_memType);
 
       // retrieve custom data
       $customFields = $customValues = $fo = array();
index 8bb29aa7d2d2cded54a43132baf83e03916769b5..65c63d4868835a188183fcfa4f4c520ac74e4a01 100644 (file)
@@ -377,7 +377,7 @@ SELECT r.id, c.id as cid, c.display_name as name, c.job_title as comment,
 
       $memType = CRM_Core_DAO::getFieldValue("CRM_Member_DAO_Membership", $id, "membership_type_id");
 
-      $groupTree = CRM_Core_BAO_CustomGroup::getTree('Membership', $this, $id, 0, $memType);
+      $groupTree = CRM_Core_BAO_CustomGroup::getTree('Membership', NULL, $id, 0, $memType);
       CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $id);
 
       $isRecur = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $id, 'contribution_recur_id');
index f368882facfd7e8253daef3c94b1af4388cb0b24..aa80503a1576293018972fa8d456ba349d69c733 100644 (file)
@@ -613,7 +613,7 @@ GROUP BY  currency
 
     // handle custom data.
     if (!empty($params['hidden_custom'])) {
-      $groupTree = CRM_Core_BAO_CustomGroup::getTree('Pledge', CRM_Core_DAO::$_nullObject, $params['id']);
+      $groupTree = CRM_Core_BAO_CustomGroup::getTree('Pledge', NULL, $params['id']);
       $pledgeParams = array(array('pledge_id', '=', $params['id'], 0, 0));
       $customGroup = array();
       // retrieve custom data
index c9540c89ad0a0c52e37bca77beb61c08410b8e7c..899c00a59f5584849825c51e110e61080862f090 100644 (file)
@@ -63,7 +63,7 @@ class CRM_Pledge_Form_PledgeView extends CRM_Core_Form {
     }
 
     // handle custom data.
-    $groupTree = CRM_Core_BAO_CustomGroup::getTree('Pledge', $this, $params['id']);
+    $groupTree = CRM_Core_BAO_CustomGroup::getTree('Pledge', NULL, $params['id']);
     CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $params['id']);
 
     if (!empty($values['contribution_page_id'])) {
index d926068c032ab4709640dc9c0352b235f346990c..814e7faa6aad37faae8eafa8f155615d4bc91fb4 100644 (file)
@@ -256,6 +256,30 @@ function _civicrm_api3_custom_value_gettree_spec(&$spec) {
     'api.required' => 1,
     'options' => array_combine($entities, $entities),
   );
+  // Return params for custom group, field & value
+  foreach (CRM_Core_DAO_CustomGroup::fields() as $field) {
+    $name = 'custom_group.' . $field['name'];
+    $spec[$name] = array('name' => $name) + $field;
+  }
+  foreach (CRM_Core_DAO_CustomField::fields() as $field) {
+    $name = 'custom_field.' . $field['name'];
+    $spec[$name] = array('name' => $name) + $field;
+  }
+  $spec['custom_value.id'] = array(
+    'title' => 'Custom Value Id',
+    'description' => 'Id of record in custom value table',
+    'type' => CRM_Utils_Type::T_INT,
+  );
+  $spec['custom_value.data'] = array(
+    'title' => 'Custom Value (Raw)',
+    'description' => 'Raw value as stored in the database',
+    'type' => CRM_Utils_Type::T_STRING,
+  );
+  $spec['custom_value.display'] = array(
+    'title' => 'Custom Value (Formatted)',
+    'description' => 'Custom value formatted for display',
+    'type' => CRM_Utils_Type::T_STRING,
+  );
 }
 
 /**
@@ -279,6 +303,10 @@ function civicrm_api3_custom_value_gettree($params) {
       $toReturn[$type][] = $field;
     }
   }
+  // We must have a name if not indexing sequentially
+  if (empty($params['sequential']) && $toReturn['custom_field']) {
+    $toReturn['custom_field'][] = 'name';
+  }
   switch ($params['entity_type']) {
     case 'Contact':
       $ret = array('entityType' => 'contact_type', 'subTypes' => 'contact_sub_type');
@@ -316,7 +344,7 @@ function civicrm_api3_custom_value_gettree($params) {
       }
     }
   }
-  $tree = CRM_Core_BAO_CustomGroup::getTree($treeParams['entityType'], NULL, $params['entity_id'], NULL, $treeParams['subTypes'], $treeParams['subName'], TRUE, NULL, FALSE, CRM_Utils_Array::value('check_permissions', $params, TRUE));
+  $tree = CRM_Core_BAO_CustomGroup::getTree($treeParams['entityType'], $toReturn, $params['entity_id'], NULL, $treeParams['subTypes'], $treeParams['subName'], TRUE, NULL, FALSE, CRM_Utils_Array::value('check_permissions', $params, TRUE));
   unset($tree['info']);
   $result = array();
   foreach ($tree as $group) {
index 7ad878fe3018fcb872e81fbdb532aea4b513f579..8b94be5d9f4860f2f81957586d4fdf490a424d44 100644 (file)
       populateFields(fields, entity, action, '', required);
       showFields(required);
       renderJoinSelector();
-      if (_.includes(['get', 'getsingle', 'getvalue', 'getstat'], action)) {
+      if (_.includes(['get', 'getsingle', 'getvalue', 'getstat', 'gettree'], action)) {
         showReturn();
       }
     });
index 970b77c376df8c11b73a1b72411b2e3c7d8b8052..3709ee86d1fcdddd979540b03729e91d34147ab7 100644 (file)
@@ -412,9 +412,44 @@ class api_v3_CustomValueTest extends CiviUnitTestCase {
     ));
     $fieldName = 'custom_' . $cf['id'];
     $contact = $this->individualCreate(array($fieldName => array('2', '3')));
+
+    // Verify values are formatted correctly
     $tree = $this->callAPISuccess('CustomValue', 'gettree', array('entity_type' => 'Contact', 'entity_id' => $contact));
     $this->assertEquals(array('2', '3'), $tree['values']['TestGettree']['fields']['got_options']['value']['data']);
     $this->assertEquals('Two, Three', $tree['values']['TestGettree']['fields']['got_options']['value']['display']);
+
+    // Try limiting the return params
+    $tree = $this->callAPISuccess('CustomValue', 'gettree', array(
+      'entity_type' => 'Contact',
+      'entity_id' => $contact,
+      'return' => array(
+        'custom_group.id',
+        'custom_field.id',
+      ),
+    ));
+    $this->assertEquals(array('2', '3'), $tree['values']['TestGettree']['fields']['got_options']['value']['data']);
+    $this->assertEquals(array('id', 'fields'), array_keys($tree['values']['TestGettree']));
+
+    // Verify that custom set appears for individuals even who don't have any custom data
+    $contact2 = $this->individualCreate();
+    $tree = $this->callAPISuccess('CustomValue', 'gettree', array('entity_type' => 'Contact', 'entity_id' => $contact2));
+    $this->assertArrayHasKey('TestGettree', $tree['values']);
+
+    // Verify that custom set doesn't appear for other contact types
+    $org = $this->organizationCreate();
+    $tree = $this->callAPISuccess('CustomValue', 'gettree', array('entity_type' => 'Contact', 'entity_id' => $org));
+    $this->assertArrayNotHasKey('TestGettree', $tree['values']);
+
+  }
+
+  public function testGettree_getfields() {
+    $fields = $this->callAPISuccess('CustomValue', 'getfields', array('api_action' => 'gettree'));
+    $fields = $fields['values'];
+    $this->assertTrue((bool) $fields['entity_id']['api.required']);
+    $this->assertTrue((bool) $fields['entity_type']['api.required']);
+    $this->assertEquals('custom_group.id', $fields['custom_group.id']['name']);
+    $this->assertEquals('custom_field.id', $fields['custom_field.id']['name']);
+    $this->assertEquals('custom_value.id', $fields['custom_value.id']['name']);
   }
 
 }