*
* @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
* 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
*
*/
public static function getTree(
$entityType,
- $deprecated = NULL,
+ $toReturn = array(),
$entityID = NULL,
$groupID = NULL,
$subTypes = array(),
// 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',
'option_group_id',
'in_selector',
),
- 'civicrm_custom_group' => array(
+ 'custom_group' => array(
'id',
'name',
'table_name',
'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);
$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)
$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)