From 374609496279c3c8cf58c56e75dcdc181fe77f65 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Mon, 28 Nov 2022 00:20:22 -0500 Subject: [PATCH] ContactType BAO - Simplify getAllContactTypes Looking up pseudoconstants was silly, the data is already there --- CRM/Contact/BAO/ContactType.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/CRM/Contact/BAO/ContactType.php b/CRM/Contact/BAO/ContactType.php index cf55ff487c..e867e13be9 100644 --- a/CRM/Contact/BAO/ContactType.php +++ b/CRM/Contact/BAO/ContactType.php @@ -870,16 +870,15 @@ WHERE ($subtypeClause)"; $query = CRM_Utils_SQL_Select::from('civicrm_contact_type'); $dao = CRM_Core_DAO::executeQuery($query->toSQL()); $contactTypes = array_column($dao->fetchAll(), NULL, 'name'); - $name_options = self::buildOptions('parent_id', 'validate'); - $label_options = self::buildOptions('parent_id', 'get'); - foreach ($contactTypes as $id => $contactType) { - $contactTypes[$id]['parent'] = $contactType['parent_id'] ? $name_options[$contactType['parent_id']] : NULL; - $contactTypes[$id]['parent_label'] = $contactType['parent_id'] ? $label_options[$contactType['parent_id']] : NULL; + $parents = array_column($contactTypes, NULL, 'id'); + foreach ($contactTypes as $name => $contactType) { + $contactTypes[$name]['parent'] = $contactType['parent_id'] ? $parents[$contactType['parent_id']]['name'] : NULL; + $contactTypes[$name]['parent_label'] = $contactType['parent_id'] ? $parents[$contactType['parent_id']]['label'] : NULL; // Cast int/bool types. - $contactTypes[$id]['id'] = (int) $contactType['id']; - $contactTypes[$id]['parent_id'] = $contactType['parent_id'] ? (int) $contactType['parent_id'] : NULL; - $contactTypes[$id]['is_active'] = (bool) $contactType['is_active']; - $contactTypes[$id]['is_reserved'] = (bool) $contactType['is_reserved']; + $contactTypes[$name]['id'] = (int) $contactType['id']; + $contactTypes[$name]['parent_id'] = $contactType['parent_id'] ? (int) $contactType['parent_id'] : NULL; + $contactTypes[$name]['is_active'] = (bool) $contactType['is_active']; + $contactTypes[$name]['is_reserved'] = (bool) $contactType['is_reserved']; } $cache->set($cacheKey, $contactTypes); } -- 2.25.1