3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
12 use Civi\Api4\ContactType
;
17 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 class CRM_Contact_BAO_ContactType
extends CRM_Contact_DAO_ContactType
{
22 * Fetch object based on array of properties.
24 * @param array $params
25 * (reference ) an assoc array of name/value pairs.
26 * @param array $defaults
27 * (reference ) an assoc array to hold the flattened values.
29 * @return CRM_Contact_DAO_ContactType|null
30 * object on success, null otherwise
32 public static function retrieve(&$params, &$defaults) {
33 $contactType = new CRM_Contact_DAO_ContactType();
34 $contactType->copyValues($params);
35 if ($contactType->find(TRUE)) {
36 CRM_Core_DAO
::storeValues($contactType, $defaults);
43 * Is this contact type active.
45 * @param string $contactType
49 public static function isActive($contactType) {
50 $contact = self
::contactTypeInfo(FALSE);
51 return array_key_exists($contactType, $contact);
55 * Retrieve basic contact type information.
57 * @todo - call getAllContactTypes & return filtered results.
59 * @param bool $includeInactive
62 * Array of basic contact types information.
64 * @throws \API_Exception
65 * @throws \Civi\API\Exception\UnauthorizedException
67 public static function basicTypeInfo($includeInactive = FALSE) {
68 $cacheKey = 'CRM_CT_BTI_' . (int) $includeInactive;
69 if (!Civi
::cache('contactTypes')->has($cacheKey)) {
70 $contactType = ContactType
::get(FALSE)->setSelect(['*'])->addWhere('parent_id', 'IS NULL');
71 if ($includeInactive === FALSE) {
72 $contactType->addWhere('is_active', '=', 1);
74 Civi
::cache('contactTypes')->set($cacheKey, (array) $contactType->execute()->indexBy('name'));
76 return Civi
::cache('contactTypes')->get($cacheKey);
80 * Retrieve all basic contact types.
85 * Array of basic contact types
87 * @throws \API_Exception
88 * @throws \Civi\API\Exception\UnauthorizedException
90 public static function basicTypes($all = FALSE) {
91 return array_keys(self
::basicTypeInfo($all));
99 * @throws \API_Exception
100 * @throws \Civi\API\Exception\UnauthorizedException
102 public static function basicTypePairs($all = FALSE, $key = 'name') {
103 $subtypes = self
::basicTypeInfo($all);
106 foreach ($subtypes as $name => $info) {
107 $index = ($key == 'name') ?
$name : $info[$key];
108 $pairs[$index] = $info['label'];
114 * Retrieve all subtypes Information.
116 * @todo - call getAllContactTypes & return filtered results.
118 * @param array $contactType
121 * @param bool $ignoreCache
124 * Array of sub type information
126 public static function subTypeInfo($contactType = NULL, $all = FALSE, $ignoreCache = FALSE) {
127 $argString = $all ?
'CRM_CT_STI_1_' : 'CRM_CT_STI_0_';
128 if (!empty($contactType)) {
129 $contactType = (array) $contactType;
130 $argString .= implode('_', $contactType);
132 if (!Civi
::cache('contactTypes')->has($argString) ||
$ignoreCache) {
134 if (!empty($contactType)) {
135 $ctWHERE = " AND parent.name IN ('" . implode("','", $contactType) . "')";
139 SELECT subtype.*, parent.name as parent, parent.label as parent_label
140 FROM civicrm_contact_type subtype
141 INNER JOIN civicrm_contact_type parent ON subtype.parent_id = parent.id
142 WHERE subtype.name IS NOT NULL AND subtype.parent_id IS NOT NULL {$ctWHERE}
144 if ($all === FALSE) {
145 $sql .= " AND subtype.is_active = 1 AND parent.is_active = 1 ORDER BY parent.id";
147 $dao = CRM_Core_DAO
::executeQuery($sql, [],
148 FALSE, 'CRM_Contact_DAO_ContactType'
151 while ($dao->fetch()) {
153 CRM_Core_DAO
::storeValues($dao, $value);
154 $value['parent'] = $dao->parent
;
155 $value['parent_label'] = $dao->parent_label
;
156 $values[$dao->name
] = $value;
158 Civi
::cache('contactTypes')->set($argString, $values);
160 return Civi
::cache('contactTypes')->get($argString);
165 * retrieve all subtypes
167 * @param array $contactType
170 * @param string $columnName
171 * @param bool $ignoreCache
174 * all subtypes OR list of subtypes associated to
175 * a given basic contact type
177 public static function subTypes($contactType = NULL, $all = FALSE, $columnName = 'name', $ignoreCache = FALSE) {
178 if ($columnName === 'name') {
179 return array_keys(self
::subTypeInfo($contactType, $all, $ignoreCache));
182 return array_values(self
::subTypePairs($contactType, FALSE, NULL, $ignoreCache));
188 * retrieve subtype pairs with name as 'subtype-name' and 'label' as value
190 * @param array $contactType
192 * @param string $labelPrefix
193 * @param bool $ignoreCache
196 * list of subtypes with name as 'subtype-name' and 'label' as value
198 public static function subTypePairs($contactType = NULL, $all = FALSE, $labelPrefix = '- ', $ignoreCache = FALSE) {
199 $subtypes = self
::subTypeInfo($contactType, $all, $ignoreCache);
202 foreach ($subtypes as $name => $info) {
203 $pairs[$name] = $labelPrefix . $info['label'];
210 * retrieve list of all types i.e basic + subtypes.
215 * Array of basic types + all subtypes.
217 public static function contactTypes($all = FALSE) {
218 return array_keys(self
::contactTypeInfo($all));
222 * Retrieve info array about all types i.e basic + subtypes.
224 * @todo deprecate calling this with $all = TRUE in favour of getAllContactTypes
225 * & ideally add getActiveContactTypes & call that from this fully
226 * deprecated function.
231 * Array of basic types + all subtypes.
232 * @throws \API_Exception
234 public static function contactTypeInfo($all = FALSE) {
235 $contactTypes = self
::getAllContactTypes();
237 foreach ($contactTypes as $index => $value) {
238 if (!$value['is_active']) {
239 unset($contactTypes[$index]);
243 return $contactTypes;
247 * Retrieve basic type pairs with name as 'built-in name' and 'label' as value.
250 * @param null $typeName
251 * @param null $delimiter
254 * Array of basictypes with name as 'built-in name' and 'label' as value
255 * @throws \API_Exception
257 public static function contactTypePairs($all = FALSE, $typeName = NULL, $delimiter = NULL) {
258 $types = self
::contactTypeInfo($all);
260 if ($typeName && !is_array($typeName)) {
261 $typeName = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, trim($typeName, CRM_Core_DAO
::VALUE_SEPARATOR
));
266 foreach ($typeName as $type) {
267 if (array_key_exists($type, $types)) {
268 $pairs[$type] = $types[$type]['label'];
273 foreach ($types as $name => $info) {
274 $pairs[$name] = $info['label'];
278 return !$delimiter ?
$pairs : implode($delimiter, $pairs);
282 * Get a list of elements for select box.
283 * Note that this used to default to using the hex(01) character - which results in an invalid character being used in form fields
284 * which was not handled well be anything that loaded & resaved the html (outside core)
285 * The use of this separator is now explicit in the calling functions as a step towards it's removal
288 * @param bool $isSeparator
289 * @param string $separator
293 public static function getSelectElements(
298 // @todo - use Cache class - ie like Civi::cache('contactTypes')
299 static $_cache = NULL;
301 if ($_cache === NULL) {
305 // @todo - call getAllContactTypes & return filtered results.
306 $argString = $all ?
'CRM_CT_GSE_1' : 'CRM_CT_GSE_0';
307 $argString .= $isSeparator ?
'_1' : '_0';
308 $argString .= $separator;
309 $argString = CRM_Utils_Cache
::cleanKey($argString);
310 if (!array_key_exists($argString, $_cache)) {
311 $cache = CRM_Utils_Cache
::singleton();
312 $_cache[$argString] = $cache->get($argString);
314 if (!$_cache[$argString]) {
315 $_cache[$argString] = [];
318 SELECT c.name as child_name , c.label as child_label , c.id as child_id,
319 p.name as parent_name, p.label as parent_label, p.id as parent_id
320 FROM civicrm_contact_type c
321 LEFT JOIN civicrm_contact_type p ON ( c.parent_id = p.id )
322 WHERE ( c.name IS NOT NULL )
325 if ($all === FALSE) {
328 AND ( p.is_active = 1 OR p.id IS NULL )
331 $sql .= " ORDER BY c.id";
334 $dao = CRM_Core_DAO
::executeQuery($sql);
335 while ($dao->fetch()) {
336 if (!empty($dao->parent_id
)) {
337 $key = $isSeparator ?
$dao->parent_name
. $separator . $dao->child_name
: $dao->child_name
;
338 $label = "- {$dao->child_label}";
339 $pName = $dao->parent_name
;
342 $key = $dao->child_name
;
343 $label = $dao->child_label
;
344 $pName = $dao->child_name
;
347 if (!isset($values[$pName])) {
348 $values[$pName] = [];
350 $values[$pName][] = ['key' => $key, 'label' => $label];
353 $selectElements = [];
354 foreach ($values as $pName => $elements) {
355 foreach ($elements as $element) {
356 $selectElements[$element['key']] = $element['label'];
359 $_cache[$argString] = $selectElements;
361 $cache->set($argString, $_cache[$argString]);
364 return $_cache[$argString];
368 * Check if a given type is a subtype.
370 * @param string $subType
372 * @param bool $ignoreCache
375 * true if subType, false otherwise.
377 public static function isaSubType($subType, $ignoreCache = FALSE) {
378 return in_array($subType, self
::subTypes(NULL, TRUE, 'name', $ignoreCache));
382 * Retrieve the basic contact type associated with given subType.
384 * @param array|string $subType contact subType.
385 * @return array|string
388 public static function getBasicType($subType) {
389 // @todo - use Cache class - ie like Civi::cache('contactTypes')
390 static $_cache = NULL;
391 if ($_cache === NULL) {
396 if ($subType && !is_array($subType)) {
397 $subType = [$subType];
400 $argString = implode('_', $subType);
402 if (!array_key_exists($argString, $_cache)) {
403 $_cache[$argString] = [];
406 SELECT subtype.name as contact_subtype, type.name as contact_type
407 FROM civicrm_contact_type subtype
408 INNER JOIN civicrm_contact_type type ON ( subtype.parent_id = type.id )
409 WHERE subtype.name IN ('" . implode("','", $subType) . "' )";
410 $dao = CRM_Core_DAO
::executeQuery($sql);
411 while ($dao->fetch()) {
413 $_cache[$argString] = $dao->contact_type
;
416 $_cache[$argString][$dao->contact_subtype
] = $dao->contact_type
;
419 return $_cache[$argString];
423 * Suppress all subtypes present in given array.
425 * @param array $subTypes
427 * @param bool $ignoreCache
430 * Array of suppressed subTypes.
432 public static function suppressSubTypes(&$subTypes, $ignoreCache = FALSE) {
433 $subTypes = array_diff($subTypes, self
::subTypes(NULL, TRUE, 'name', $ignoreCache));
438 * Verify if a given subtype is associated with a given basic contact type.
440 * @param string $subType
442 * @param string $contactType
444 * @param bool $ignoreCache
445 * @param string $columnName
448 * true if contact extends, false otherwise.
450 public static function isExtendsContactType($subType, $contactType, $ignoreCache = FALSE, $columnName = 'name') {
451 $subType = (array) CRM_Utils_Array
::explodePadded($subType);
452 $subtypeList = self
::subTypes($contactType, TRUE, $columnName, $ignoreCache);
453 $intersection = array_intersect($subType, $subtypeList);
454 return $subType == $intersection;
458 * Create shortcuts menu for contactTypes.
463 public static function getCreateNewList() {
465 //@todo FIXME - using the CRM_Core_DAO::VALUE_SEPARATOR creates invalid html - if you can find the form
466 // this is loaded onto then replace with something like '__' & test
467 $separator = CRM_Core_DAO
::VALUE_SEPARATOR
;
468 $contactTypes = self
::getSelectElements(FALSE, TRUE, $separator);
469 foreach ($contactTypes as $key => $value) {
471 $typeValue = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $key);
472 $cType = $typeValue['0'] ??
NULL;
473 $typeUrl = 'ct=' . $cType;
474 if ($csType = CRM_Utils_Array
::value('1', $typeValue)) {
475 $typeUrl .= "&cst=$csType";
478 'path' => 'civicrm/contact/add',
479 'query' => "$typeUrl&reset=1",
480 'ref' => "new-$value",
483 if ($csType = CRM_Utils_Array
::value('1', $typeValue)) {
484 $shortCuts[$cType]['shortCuts'][] = $shortCut;
487 $shortCuts[$cType] = $shortCut;
495 * Delete Contact SubTypes.
497 * @param int $contactTypeId
498 * ID of the Contact Subtype to be deleted.
502 public static function del($contactTypeId) {
504 if (!$contactTypeId) {
508 $params = ['id' => $contactTypeId];
509 self
::retrieve($params, $typeInfo);
510 $name = $typeInfo['name'];
511 // check if any custom group
512 $custom = new CRM_Core_DAO_CustomGroup();
513 $custom->whereAdd("extends_entity_column_value LIKE '%" .
514 CRM_Core_DAO
::VALUE_SEPARATOR
.
516 CRM_Core_DAO
::VALUE_SEPARATOR
. "%'"
518 if ($custom->find()) {
522 // remove subtype for existing contacts
524 UPDATE civicrm_contact SET contact_sub_type = NULL
525 WHERE contact_sub_type = '$name'";
526 CRM_Core_DAO
::executeQuery($sql);
528 // remove subtype from contact type table
529 $contactType = new CRM_Contact_DAO_ContactType();
530 $contactType->id
= $contactTypeId;
531 $contactType->delete();
533 // remove navigation entry if any
537 FROM civicrm_navigation
539 $params = [1 => ["New $name", 'String']];
540 CRM_Core_DAO
::executeQuery($sql, $params);
541 CRM_Core_BAO_Navigation
::resetNavigation();
542 Civi
::cache('contactTypes')->clear();
548 * Add or update Contact SubTypes.
550 * @param array $params
551 * An assoc array of name/value pairs.
553 * @return object|void
554 * @throws \CRM_Core_Exception
556 public static function add($params) {
559 if (empty($params['id']) && empty($params['label'])) {
560 // @todo consider throwing exception instead.
563 if (empty($params['id']) && empty($params['name'])) {
564 $params['name'] = ucfirst(CRM_Utils_String
::munge($params['label']));
566 if (!empty($params['parent_id']) &&
567 !CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_ContactType', $params['parent_id'])
572 $contactType = new CRM_Contact_DAO_ContactType();
573 $contactType->copyValues($params);
574 $contactType->id
= $params['id'] ??
NULL;
576 $contactType->save();
577 if ($contactType->find(TRUE)) {
578 $contactName = $contactType->name
;
579 $contact = ucfirst($contactType->label
);
580 $active = $contactType->is_active
;
583 if (!empty($params['id'])) {
585 'label' => ts("New %1", [1 => $contact]),
586 'is_active' => $contactType->is_active
,
588 CRM_Core_BAO_Navigation
::processUpdate(['name' => "New $contactName"], $newParams);
591 $name = self
::getBasicType($contactName);
595 $value = ['name' => "New $name"];
596 CRM_Core_BAO_Navigation
::retrieve($value, $navinfo);
598 'label' => ts("New %1", [1 => $contact]),
599 'name' => "New $contactName",
600 'url' => "civicrm/contact/add?ct=$name&cst=$contactName&reset=1",
601 'permission' => 'add contacts',
602 'parent_id' => $navinfo['id'],
603 'is_active' => $active,
605 CRM_Core_BAO_Navigation
::add($navigation);
607 CRM_Core_BAO_Navigation
::resetNavigation();
608 Civi
::cache('contactTypes')->clear();
614 * Update the is_active flag in the db.
617 * Id of the database record.
618 * @param bool $is_active
619 * Value we want to set the is_active field.
622 * true if we found and updated the object, else false
624 public static function setIsActive($id, $is_active) {
625 $params = ['id' => $id];
626 self
::retrieve($params, $contactinfo);
627 $params = ['name' => "New $contactinfo[name]"];
628 $newParams = ['is_active' => $is_active];
629 CRM_Core_BAO_Navigation
::processUpdate($params, $newParams);
630 CRM_Core_BAO_Navigation
::resetNavigation();
631 return CRM_Core_DAO
::setFieldValue('CRM_Contact_DAO_ContactType', $id,
632 'is_active', $is_active
637 * @param string $typeName
640 * @throws \API_Exception
642 public static function getLabel($typeName) {
643 $types = self
::contactTypeInfo(TRUE);
645 if (array_key_exists($typeName, $types)) {
646 return $types[$typeName]['label'];
652 * Check whether allow to change any contact's subtype
653 * on the basis of custom data and relationship of specific subtype
654 * currently used in contact/edit form amd in import validation
656 * @param int $contactId
658 * @param string $subType
662 * @throws \CRM_Core_Exception
664 public static function isAllowEdit($contactId, $subType = NULL) {
670 if (empty($subType)) {
671 $subType = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact',
677 if (self
::hasCustomData($subType, $contactId) || self
::hasRelationships($contactId, $subType)) {
685 * @param $contactType
686 * @param int $contactId
690 public static function hasCustomData($contactType, $contactId = NULL) {
693 if (self
::isaSubType($contactType)) {
694 $subType = $contactType;
695 $contactType = self
::getBasicType($subType);
697 // check for empty custom data which extends subtype
698 $subTypeValue = CRM_Core_DAO
::VALUE_SEPARATOR
. $subType . CRM_Core_DAO
::VALUE_SEPARATOR
;
699 $subTypeClause = " AND extends_entity_column_value LIKE '%{$subTypeValue}%' ";
701 $query = "SELECT table_name FROM civicrm_custom_group WHERE extends = '{$contactType}' {$subTypeClause}";
703 $dao = CRM_Core_DAO
::executeQuery($query);
704 while ($dao->fetch()) {
705 $sql = "SELECT count(id) FROM {$dao->table_name}";
707 $sql .= " WHERE entity_id = {$contactId}";
711 $customDataCount = CRM_Core_DAO
::singleValueQuery($sql);
712 if (!empty($customDataCount)) {
720 * @todo what does this function do?
721 * @param int $contactId
722 * @param $contactType
726 public static function hasRelationships($contactId, $contactType) {
727 $subTypeClause = NULL;
728 if (self
::isaSubType($contactType)) {
729 $subType = $contactType;
730 $contactType = self
::getBasicType($subType);
731 $subTypeClause = " AND ( ( crt.contact_type_a = '{$contactType}' AND crt.contact_sub_type_a = '{$subType}') OR
732 ( crt.contact_type_b = '{$contactType}' AND crt.contact_sub_type_b = '{$subType}') ) ";
735 $subTypeClause = " AND ( crt.contact_type_a = '{$contactType}' OR crt.contact_type_b = '{$contactType}' ) ";
738 // check relationships for
739 $relationshipQuery = "
740 SELECT count(cr.id) FROM civicrm_relationship cr
741 INNER JOIN civicrm_relationship_type crt ON
742 ( cr.relationship_type_id = crt.id {$subTypeClause} )
743 WHERE ( cr.contact_id_a = {$contactId} OR cr.contact_id_b = {$contactId} )
746 $relationshipCount = CRM_Core_DAO
::singleValueQuery($relationshipQuery);
748 if (!empty($relationshipCount)) {
756 * @param $contactType
757 * @param array $subtypeSet
760 * @throws \CRM_Core_Exception
761 * @todo what does this function do?
763 public static function getSubtypeCustomPair($contactType, $subtypeSet = []) {
764 if (empty($subtypeSet)) {
768 $customSet = $subTypeClause = [];
769 foreach ($subtypeSet as $subtype) {
770 $subtype = CRM_Utils_Type
::escape($subtype, 'String');
771 $subtype = CRM_Core_DAO
::VALUE_SEPARATOR
. $subtype . CRM_Core_DAO
::VALUE_SEPARATOR
;
772 $subTypeClause[] = "extends_entity_column_value LIKE '%{$subtype}%' ";
774 $query = 'SELECT table_name
775 FROM civicrm_custom_group
776 WHERE extends = %1 AND ' . implode(" OR ", $subTypeClause);
777 $dao = CRM_Core_DAO
::executeQuery($query, [1 => [$contactType, 'String']]);
778 while ($dao->fetch()) {
779 $customSet[] = $dao->table_name
;
781 return array_unique($customSet);
785 * Function that does something.
787 * @param int $contactID
788 * @param string $contactType
789 * @param array $oldSubtypeSet
790 * @param array $newSubtypeSet
793 * @throws \CRM_Core_Exception
795 * @todo what does this function do?
797 public static function deleteCustomSetForSubtypeMigration(
803 $oldCustomSet = self
::getSubtypeCustomPair($contactType, $oldSubtypeSet);
804 $newCustomSet = self
::getSubtypeCustomPair($contactType, $newSubtypeSet);
806 $customToBeRemoved = array_diff($oldCustomSet, $newCustomSet);
807 foreach ($customToBeRemoved as $customTable) {
808 self
::deleteCustomRowsForEntityID($customTable, $contactID);
814 * Delete content / rows of a custom table specific to a subtype for a given custom-group.
815 * This function currently works for contact subtypes only and could be later improved / genralized
816 * to work for other subtypes as well.
820 * @param array $subtypes
821 * List of subtypes related to which entry is to be removed.
822 * @param array $subtypesToPreserve
826 * @throws \CRM_Core_Exception
828 public static function deleteCustomRowsOfSubtype($gID, $subtypes = [], $subtypesToPreserve = []) {
829 if (!$gID or empty($subtypes)) {
833 $tableName = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_CustomGroup', $gID, 'table_name');
835 // drop triggers CRM-13587
836 CRM_Core_DAO
::dropTriggers($tableName);
838 foreach ($subtypesToPreserve as $subtypeToPreserve) {
839 $subtypeToPreserve = CRM_Utils_Type
::escape($subtypeToPreserve, 'String');
840 $subtypesToPreserveClause[] = "(civicrm_contact.contact_sub_type NOT LIKE '%" . CRM_Core_DAO
::VALUE_SEPARATOR
. $subtypeToPreserve . CRM_Core_DAO
::VALUE_SEPARATOR
. "%')";
842 $subtypesToPreserveClause = implode(' AND ', $subtypesToPreserveClause);
845 foreach ($subtypes as $subtype) {
846 $subtype = CRM_Utils_Type
::escape($subtype, 'String');
847 $subtypeClause[] = "( civicrm_contact.contact_sub_type LIKE '%" . CRM_Core_DAO
::VALUE_SEPARATOR
. $subtype . CRM_Core_DAO
::VALUE_SEPARATOR
. "%'"
848 . " AND " . $subtypesToPreserveClause . ")";
850 $subtypeClause = implode(' OR ', $subtypeClause);
852 $query = "DELETE custom.*
853 FROM {$tableName} custom
854 INNER JOIN civicrm_contact ON civicrm_contact.id = custom.entity_id
855 WHERE ($subtypeClause)";
857 CRM_Core_DAO
::singleValueQuery($query);
859 // rebuild triggers CRM-13587
860 CRM_Core_DAO
::triggerRebuild($tableName);
864 * Delete content / rows of a custom table specific entity-id for a given custom-group table.
866 * @param int $customTable
868 * @param int $entityID
871 * @return null|string
873 * @throws \CRM_Core_Exception
875 public static function deleteCustomRowsForEntityID($customTable, $entityID) {
876 $customTable = CRM_Utils_Type
::escape($customTable, 'String');
877 $query = "DELETE FROM {$customTable} WHERE entity_id = %1";
878 return CRM_Core_DAO
::singleValueQuery($query, [1 => [$entityID, 'Integer']]);
882 * Get all contact types, leveraging caching.
886 * @throws \API_Exception
888 protected static function getAllContactTypes() {
889 if (!Civi
::cache('contactTypes')->has('all')) {
890 $contactTypes = (array) ContactType
::get(FALSE)
891 ->setSelect(['id', 'name', 'label', 'description', 'is_active', 'is_reserved', 'image_URL', 'parent_id', 'parent_id:name', 'parent_id:label'])
892 ->execute()->indexBy('name');
894 foreach ($contactTypes as $id => $contactType) {
895 $contactTypes[$id]['parent'] = $contactType['parent_id:name'];
896 $contactTypes[$id]['parent_label'] = $contactType['parent_id:label'];
897 unset($contactTypes[$id]['parent_id:name'], $contactTypes[$id]['parent_id:label']);
899 Civi
::cache('contactTypes')->set('all', $contactTypes);
901 $contactTypes = Civi
::cache('contactTypes')->get('all');
902 return $contactTypes;