X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FCore%2FBAO%2FCustomGroup.php;h=12016aa21f94a1071c104d00e3b4e91e5f6ef889;hb=0b330e6d69c2b7bfc8c03d45b253ca36da4e91db;hp=74eac1fc6d4e39a03739e9a2234e31ff2740f4b2;hpb=24871985168cd37bd5d75b23d746ba627132552b;p=civicrm-core.git diff --git a/CRM/Core/BAO/CustomGroup.php b/CRM/Core/BAO/CustomGroup.php index 74eac1fc6d..12016aa21f 100644 --- a/CRM/Core/BAO/CustomGroup.php +++ b/CRM/Core/BAO/CustomGroup.php @@ -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)