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 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 class CRM_Contact_BAO_ContactType
extends CRM_Contact_DAO_ContactType
implements \Civi\Test\HookInterface
{
20 * Fetch object based on array of properties.
22 * @param array $params
23 * (reference ) an assoc array of name/value pairs.
24 * @param array $defaults
25 * (reference ) an assoc array to hold the flattened values.
27 * @return CRM_Contact_DAO_ContactType|null
28 * object on success, null otherwise
30 public static function retrieve(&$params, &$defaults) {
31 $contactType = new CRM_Contact_DAO_ContactType();
32 $contactType->copyValues($params);
33 if ($contactType->find(TRUE)) {
34 CRM_Core_DAO
::storeValues($contactType, $defaults);
41 * Is this contact type active.
43 * @param string $contactType
47 * @throws \API_Exception
49 public static function isActive($contactType) {
50 $contact = self
::contactTypeInfo();
51 return array_key_exists($contactType, $contact);
55 * Retrieve basic contact type information.
57 * @param bool $includeInactive
60 * Array of basic contact types information.
62 * @throws \API_Exception
63 * @throws \Civi\API\Exception\UnauthorizedException
65 public static function basicTypeInfo($includeInactive = FALSE) {
66 return array_filter(self
::getAllContactTypes(), function($type) use ($includeInactive) {
67 return empty($type['parent']) && ($includeInactive ||
$type['is_active']);
72 * Retrieve all basic contact types.
77 * Array of basic contact types
79 * @throws \API_Exception
80 * @throws \Civi\API\Exception\UnauthorizedException
82 public static function basicTypes($all = FALSE) {
83 return array_keys(self
::basicTypeInfo($all));
91 * @throws \API_Exception
92 * @throws \Civi\API\Exception\UnauthorizedException
94 public static function basicTypePairs($all = FALSE, $key = 'name') {
95 $subtypes = self
::basicTypeInfo($all);
98 foreach ($subtypes as $name => $info) {
99 $index = ($key == 'name') ?
$name : $info[$key];
100 $pairs[$index] = $info['label'];
106 * Retrieve all subtypes Information.
108 * @param array $contactType
112 * Array of sub type information, subset of getAllContactTypes.
114 * @throws \API_Exception
116 public static function subTypeInfo($contactType = NULL, $all = FALSE) {
117 $contactTypes = self
::getAllContactTypes();
118 foreach ($contactTypes as $index => $type) {
119 if (empty($type['parent']) ||
120 (!$all && !$type['is_active'])
121 ||
($contactType && $type['parent'] !== $contactType)
123 unset($contactTypes[$index]);
126 return $contactTypes;
131 * retrieve all subtypes
133 * @param array $contactType
136 * @param string $columnName
137 * @param bool $ignoreCache
140 * all subtypes OR list of subtypes associated to
141 * a given basic contact type
142 * @throws \API_Exception
144 public static function subTypes($contactType = NULL, $all = FALSE, $columnName = 'name', $ignoreCache = FALSE) {
145 if ($columnName === 'name') {
146 return array_keys(self
::subTypeInfo($contactType, $all, $ignoreCache));
149 return array_values(self
::subTypePairs($contactType, FALSE, NULL, $ignoreCache));
155 * retrieve subtype pairs with name as 'subtype-name' and 'label' as value
157 * @param array $contactType
159 * @param string $labelPrefix
160 * @param bool $ignoreCache
163 * list of subtypes with name as 'subtype-name' and 'label' as value
165 public static function subTypePairs($contactType = NULL, $all = FALSE, $labelPrefix = '- ', $ignoreCache = FALSE) {
166 $subtypes = self
::subTypeInfo($contactType, $all, $ignoreCache);
169 foreach ($subtypes as $name => $info) {
170 $pairs[$name] = $labelPrefix . $info['label'];
176 * Retrieve list of all types i.e basic + subtypes.
181 * Array of basic types + all subtypes.
183 public static function contactTypes($all = FALSE) {
184 return array_keys(self
::contactTypeInfo($all));
188 * Retrieve info array about all types i.e basic + subtypes.
190 * @todo deprecate calling this with $all = TRUE in favour of getAllContactTypes
191 * & ideally add getActiveContactTypes & call that from this fully
192 * deprecated function.
197 * Array of basic types + all subtypes.
199 public static function contactTypeInfo($all = FALSE) {
200 $contactTypes = self
::getAllContactTypes();
202 foreach ($contactTypes as $index => $value) {
203 if (!$value['is_active']) {
204 unset($contactTypes[$index]);
208 return $contactTypes;
212 * Retrieve basic type pairs with name as 'built-in name' and 'label' as value.
215 * @param null $typeName
216 * @param null $delimiter
218 * @return array|string
219 * Array of basictypes with name as 'built-in name' and 'label' as value
220 * @throws \API_Exception
222 public static function contactTypePairs($all = FALSE, $typeName = NULL, $delimiter = NULL) {
223 $types = self
::contactTypeInfo($all);
225 if ($typeName && !is_array($typeName)) {
226 $typeName = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, trim($typeName, CRM_Core_DAO
::VALUE_SEPARATOR
));
231 foreach ($typeName as $type) {
232 if (array_key_exists($type, $types)) {
233 $pairs[$type] = $types[$type]['label'];
238 foreach ($types as $name => $info) {
239 $pairs[$name] = $info['label'];
243 return !$delimiter ?
$pairs : implode($delimiter, $pairs);
247 * Get a list of elements for select box.
248 * Note that this used to default to using the hex(01) character - which results in an invalid character being used in form fields
249 * which was not handled well be anything that loaded & resaved the html (outside core)
250 * The use of this separator is now explicit in the calling functions as a step towards it's removal
253 * @param bool $isSeparator
254 * @param string $separator
258 public static function getSelectElements(
263 // @todo - use Cache class - ie like Civi::cache('contactTypes')
264 static $_cache = NULL;
266 if ($_cache === NULL) {
270 // @todo - call getAllContactTypes & return filtered results.
271 $argString = $all ?
'CRM_CT_GSE_1' : 'CRM_CT_GSE_0';
272 $argString .= $isSeparator ?
'_1' : '_0';
273 $argString .= $separator;
274 $argString = CRM_Utils_Cache
::cleanKey($argString);
275 if (!array_key_exists($argString, $_cache)) {
276 $cache = CRM_Utils_Cache
::singleton();
277 $_cache[$argString] = $cache->get($argString);
279 if (!$_cache[$argString]) {
280 $_cache[$argString] = [];
283 SELECT c.name as child_name , c.label as child_label , c.id as child_id,
284 p.name as parent_name, p.label as parent_label, p.id as parent_id
285 FROM civicrm_contact_type c
286 LEFT JOIN civicrm_contact_type p ON ( c.parent_id = p.id )
287 WHERE ( c.name IS NOT NULL )
290 if ($all === FALSE) {
293 AND ( p.is_active = 1 OR p.id IS NULL )
296 $sql .= " ORDER BY c.id";
299 $dao = CRM_Core_DAO
::executeQuery($sql);
300 while ($dao->fetch()) {
301 if (!empty($dao->parent_id
)) {
302 $key = $isSeparator ?
$dao->parent_name
. $separator . $dao->child_name
: $dao->child_name
;
303 $label = "- {$dao->child_label}";
304 $pName = $dao->parent_name
;
307 $key = $dao->child_name
;
308 $label = $dao->child_label
;
309 $pName = $dao->child_name
;
312 if (!isset($values[$pName])) {
313 $values[$pName] = [];
315 $values[$pName][] = ['key' => $key, 'label' => $label];
318 $selectElements = [];
319 foreach ($values as $pName => $elements) {
320 foreach ($elements as $element) {
321 $selectElements[$element['key']] = $element['label'];
324 $_cache[$argString] = $selectElements;
326 $cache->set($argString, $_cache[$argString]);
329 return $_cache[$argString];
333 * Check if a given type is a subtype.
335 * @param string $subType
337 * @param bool $ignoreCache
340 * true if subType, false otherwise.
342 public static function isaSubType($subType, $ignoreCache = FALSE) {
343 return in_array($subType, self
::subTypes(NULL, TRUE, 'name', $ignoreCache));
347 * Retrieve the basic contact type associated with given subType.
349 * @param array|string $subType contact subType.
350 * @return array|string
352 public static function getBasicType($subType) {
353 // @todo - use Cache class - ie like Civi::cache('contactTypes')
354 static $_cache = NULL;
355 if ($_cache === NULL) {
360 if ($subType && !is_array($subType)) {
361 $subType = [$subType];
364 $argString = implode('_', $subType);
366 if (!array_key_exists($argString, $_cache)) {
367 $_cache[$argString] = [];
370 SELECT subtype.name as contact_subtype, type.name as contact_type
371 FROM civicrm_contact_type subtype
372 INNER JOIN civicrm_contact_type type ON ( subtype.parent_id = type.id )
373 WHERE subtype.name IN ('" . implode("','", $subType) . "' )";
374 $dao = CRM_Core_DAO
::executeQuery($sql);
375 while ($dao->fetch()) {
377 $_cache[$argString] = $dao->contact_type
;
380 $_cache[$argString][$dao->contact_subtype
] = $dao->contact_type
;
383 return $_cache[$argString];
387 * Suppress all subtypes present in given array.
389 * @param array $subTypes
391 * @param bool $ignoreCache
394 * Array of suppressed subTypes.
396 public static function suppressSubTypes(&$subTypes, $ignoreCache = FALSE) {
397 $subTypes = array_diff($subTypes, self
::subTypes(NULL, TRUE, 'name', $ignoreCache));
402 * Verify if a given subtype is associated with a given basic contact type.
404 * @param string $subType
406 * @param string $contactType
408 * @param bool $ignoreCache
409 * @param string $columnName
412 * true if contact extends, false otherwise.
414 public static function isExtendsContactType($subType, $contactType, $ignoreCache = FALSE, $columnName = 'name') {
415 $subType = (array) CRM_Utils_Array
::explodePadded($subType);
416 $subtypeList = self
::subTypes($contactType, TRUE, $columnName, $ignoreCache);
417 $intersection = array_intersect($subType, $subtypeList);
418 return $subType == $intersection;
422 * Create shortcuts menu for contactTypes.
427 public static function getCreateNewList() {
429 //@todo FIXME - using the CRM_Core_DAO::VALUE_SEPARATOR creates invalid html - if you can find the form
430 // this is loaded onto then replace with something like '__' & test
431 $separator = CRM_Core_DAO
::VALUE_SEPARATOR
;
432 $contactTypes = self
::getSelectElements(FALSE, TRUE, $separator);
433 foreach ($contactTypes as $key => $value) {
435 $typeValue = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $key);
436 $cType = $typeValue['0'] ??
NULL;
437 $typeUrl = 'ct=' . $cType;
438 if ($csType = CRM_Utils_Array
::value('1', $typeValue)) {
439 $typeUrl .= "&cst=$csType";
442 'path' => 'civicrm/contact/add',
443 'query' => "$typeUrl&reset=1",
444 'ref' => "new-$value",
447 if ($csType = CRM_Utils_Array
::value('1', $typeValue)) {
448 $shortCuts[$cType]['shortCuts'][] = $shortCut;
451 $shortCuts[$cType] = $shortCut;
459 * Delete Contact SubTypes.
461 * @param int $contactTypeId
462 * ID of the Contact Subtype to be deleted.
466 public static function del($contactTypeId) {
467 if (!$contactTypeId) {
471 static::deleteRecord(['id' => $contactTypeId]);
474 catch (CRM_Core_Exception
$e) {
480 * Callback for hook_civicrm_pre().
481 * @param \Civi\Core\Event\PreEvent $event
482 * @throws CRM_Core_Exception
484 public static function self_hook_civicrm_pre(\Civi\Core\Event\PreEvent
$event) {
485 // Before deleting a contactType, check references by custom groups
486 if ($event->action
=== 'delete') {
487 $name = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_ContactType', $event->id
);
488 $sep = CRM_Core_DAO
::VALUE_SEPARATOR
;
489 $custom = new CRM_Core_DAO_CustomGroup();
490 $custom->whereAdd("extends_entity_column_value LIKE '%{$sep}{$name}{$sep}%'");
491 if ($custom->find()) {
492 throw new CRM_Core_Exception(ts("You can not delete this contact type -- it is used by %1 custom field group(s). The custom fields must be deleted first.", [1 => $custom->N
]));
498 * Callback for hook_civicrm_post().
499 * @param \Civi\Core\Event\PostEvent $event
501 public static function self_hook_civicrm_post(\Civi\Core\Event\PostEvent
$event) {
502 if ($event->action
=== 'delete') {
503 $sep = CRM_Core_DAO
::VALUE_SEPARATOR
;
504 $subType = "$sep{$event->object->name}$sep";
505 // For contacts with just the one sub-type, set to null
507 UPDATE civicrm_contact SET contact_sub_type = NULL
508 WHERE contact_sub_type = '$subType'";
509 CRM_Core_DAO
::executeQuery($sql);
510 // For contacts with multipe sub-types, remove this one
512 UPDATE civicrm_contact SET contact_sub_type = REPLACE(contact_sub_type, '$subType', '$sep')
513 WHERE contact_sub_type LIKE '%{$subType}%'";
514 CRM_Core_DAO
::executeQuery($sql);
516 // remove navigation entry which was auto-created when this sub-type was added
517 \Civi\Api4\Navigation
::delete(FALSE)
518 ->addWhere('name', '=', "New {$event->object->name}")
519 ->addWhere('url', 'LIKE', 'civicrm/contact/add%')
520 // Overide the default which limits to a single domain
521 ->addWhere('domain_id', '>', 0)
524 Civi
::cache('contactTypes')->clear();
529 * Add or update Contact SubTypes.
531 * @param array $params
532 * An assoc array of name/value pairs.
534 * @return object|void
535 * @throws \CRM_Core_Exception
537 public static function add($params) {
540 if (empty($params['id']) && empty($params['label'])) {
541 // @todo consider throwing exception instead.
544 if (empty($params['id']) && empty($params['name'])) {
545 $params['name'] = ucfirst(CRM_Utils_String
::munge($params['label']));
547 if (!empty($params['parent_id']) &&
548 !CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_ContactType', $params['parent_id'])
553 $contactType = new CRM_Contact_DAO_ContactType();
554 $contactType->copyValues($params);
555 $contactType->id
= $params['id'] ??
NULL;
557 $contactType->save();
558 if ($contactType->find(TRUE)) {
559 $contactName = $contactType->name
;
560 $contact = ucfirst($contactType->label
);
561 $active = $contactType->is_active
;
564 if (!empty($params['id'])) {
566 'label' => ts("New %1", [1 => $contact]),
567 'is_active' => $contactType->is_active
,
569 CRM_Core_BAO_Navigation
::processUpdate(['name' => "New $contactName"], $newParams);
572 $name = self
::getBasicType($contactName);
576 $value = ['name' => "New $name"];
577 CRM_Core_BAO_Navigation
::retrieve($value, $navinfo);
579 'label' => ts("New %1", [1 => $contact]),
580 'name' => "New $contactName",
581 'url' => "civicrm/contact/add?ct=$name&cst=$contactName&reset=1",
582 'permission' => 'add contacts',
583 'parent_id' => $navinfo['id'],
584 'is_active' => $active,
586 CRM_Core_BAO_Navigation
::add($navigation);
588 CRM_Core_BAO_Navigation
::resetNavigation();
589 Civi
::cache('contactTypes')->clear();
595 * Update the is_active flag in the db.
598 * Id of the database record.
599 * @param bool $is_active
600 * Value we want to set the is_active field.
603 * true if we found and updated the object, else false
605 public static function setIsActive($id, $is_active) {
606 $params = ['id' => $id];
607 self
::retrieve($params, $contactinfo);
608 $params = ['name' => "New $contactinfo[name]"];
609 $newParams = ['is_active' => $is_active];
610 CRM_Core_BAO_Navigation
::processUpdate($params, $newParams);
611 CRM_Core_BAO_Navigation
::resetNavigation();
612 return CRM_Core_DAO
::setFieldValue('CRM_Contact_DAO_ContactType', $id,
613 'is_active', $is_active
618 * @param string $typeName
621 * @throws \API_Exception
623 public static function getLabel($typeName) {
624 $types = self
::contactTypeInfo(TRUE);
626 if (array_key_exists($typeName, $types)) {
627 return $types[$typeName]['label'];
633 * Check whether allow to change any contact's subtype
634 * on the basis of custom data and relationship of specific subtype
635 * currently used in contact/edit form amd in import validation
637 * @param int $contactId
639 * @param string $subType
643 * @throws \CRM_Core_Exception
645 public static function isAllowEdit($contactId, $subType = NULL) {
651 if (empty($subType)) {
652 $subType = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact',
658 if (self
::hasCustomData($subType, $contactId) || self
::hasRelationships($contactId, $subType)) {
666 * @param $contactType
667 * @param int $contactId
671 public static function hasCustomData($contactType, $contactId = NULL) {
674 if (self
::isaSubType($contactType)) {
675 $subType = $contactType;
676 $contactType = self
::getBasicType($subType);
678 // check for empty custom data which extends subtype
679 $subTypeValue = CRM_Core_DAO
::VALUE_SEPARATOR
. $subType . CRM_Core_DAO
::VALUE_SEPARATOR
;
680 $subTypeClause = " AND extends_entity_column_value LIKE '%{$subTypeValue}%' ";
682 $query = "SELECT table_name FROM civicrm_custom_group WHERE extends = '{$contactType}' {$subTypeClause}";
684 $dao = CRM_Core_DAO
::executeQuery($query);
685 while ($dao->fetch()) {
686 $sql = "SELECT count(id) FROM {$dao->table_name}";
688 $sql .= " WHERE entity_id = {$contactId}";
692 $customDataCount = CRM_Core_DAO
::singleValueQuery($sql);
693 if (!empty($customDataCount)) {
701 * @todo what does this function do?
702 * @param int $contactId
703 * @param $contactType
707 public static function hasRelationships($contactId, $contactType) {
708 if (self
::isaSubType($contactType)) {
709 $subType = $contactType;
710 $contactType = self
::getBasicType($subType);
711 $subTypeClause = " AND ( ( crt.contact_type_a = '{$contactType}' AND crt.contact_sub_type_a = '{$subType}') OR
712 ( crt.contact_type_b = '{$contactType}' AND crt.contact_sub_type_b = '{$subType}') ) ";
715 $subTypeClause = " AND ( crt.contact_type_a = '{$contactType}' OR crt.contact_type_b = '{$contactType}' ) ";
718 // check relationships for
719 $relationshipQuery = "
720 SELECT count(cr.id) FROM civicrm_relationship cr
721 INNER JOIN civicrm_relationship_type crt ON
722 ( cr.relationship_type_id = crt.id {$subTypeClause} )
723 WHERE ( cr.contact_id_a = {$contactId} OR cr.contact_id_b = {$contactId} )
726 $relationshipCount = CRM_Core_DAO
::singleValueQuery($relationshipQuery);
728 if (!empty($relationshipCount)) {
736 * @param $contactType
737 * @param array $subtypeSet
740 * @throws \CRM_Core_Exception
741 * @todo what does this function do?
743 public static function getSubtypeCustomPair($contactType, $subtypeSet = []) {
744 if (empty($subtypeSet)) {
748 $customSet = $subTypeClause = [];
749 foreach ($subtypeSet as $subtype) {
750 $subtype = CRM_Utils_Type
::escape($subtype, 'String');
751 $subtype = CRM_Core_DAO
::VALUE_SEPARATOR
. $subtype . CRM_Core_DAO
::VALUE_SEPARATOR
;
752 $subTypeClause[] = "extends_entity_column_value LIKE '%{$subtype}%' ";
754 $query = 'SELECT table_name
755 FROM civicrm_custom_group
756 WHERE extends = %1 AND ' . implode(" OR ", $subTypeClause);
757 $dao = CRM_Core_DAO
::executeQuery($query, [1 => [$contactType, 'String']]);
758 while ($dao->fetch()) {
759 $customSet[] = $dao->table_name
;
761 return array_unique($customSet);
765 * Function that does something.
767 * @param int $contactID
768 * @param string $contactType
769 * @param array $oldSubtypeSet
770 * @param array $newSubtypeSet
773 * @throws \CRM_Core_Exception
775 * @todo what does this function do?
777 public static function deleteCustomSetForSubtypeMigration(
783 $oldCustomSet = self
::getSubtypeCustomPair($contactType, $oldSubtypeSet);
784 $newCustomSet = self
::getSubtypeCustomPair($contactType, $newSubtypeSet);
786 $customToBeRemoved = array_diff($oldCustomSet, $newCustomSet);
787 foreach ($customToBeRemoved as $customTable) {
788 self
::deleteCustomRowsForEntityID($customTable, $contactID);
794 * Delete content / rows of a custom table specific to a subtype for a given custom-group.
795 * This function currently works for contact subtypes only and could be later improved / genralized
796 * to work for other subtypes as well.
800 * @param array $subtypes
801 * List of subtypes related to which entry is to be removed.
802 * @param array $subtypesToPreserve
806 * @throws \CRM_Core_Exception
808 public static function deleteCustomRowsOfSubtype($gID, $subtypes = [], $subtypesToPreserve = []) {
809 if (!$gID or empty($subtypes)) {
813 $tableName = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_CustomGroup', $gID, 'table_name');
815 // drop triggers CRM-13587
816 CRM_Core_DAO
::dropTriggers($tableName);
818 foreach ($subtypesToPreserve as $subtypeToPreserve) {
819 $subtypeToPreserve = CRM_Utils_Type
::escape($subtypeToPreserve, 'String');
820 $subtypesToPreserveClause[] = "(civicrm_contact.contact_sub_type NOT LIKE '%" . CRM_Core_DAO
::VALUE_SEPARATOR
. $subtypeToPreserve . CRM_Core_DAO
::VALUE_SEPARATOR
. "%')";
822 $subtypesToPreserveClause = implode(' AND ', $subtypesToPreserveClause);
825 foreach ($subtypes as $subtype) {
826 $subtype = CRM_Utils_Type
::escape($subtype, 'String');
827 $subtypeClause[] = "( civicrm_contact.contact_sub_type LIKE '%" . CRM_Core_DAO
::VALUE_SEPARATOR
. $subtype . CRM_Core_DAO
::VALUE_SEPARATOR
. "%'"
828 . " AND " . $subtypesToPreserveClause . ")";
830 $subtypeClause = implode(' OR ', $subtypeClause);
832 $query = "DELETE custom.*
833 FROM {$tableName} custom
834 INNER JOIN civicrm_contact ON civicrm_contact.id = custom.entity_id
835 WHERE ($subtypeClause)";
837 CRM_Core_DAO
::singleValueQuery($query);
839 // rebuild triggers CRM-13587
840 CRM_Core_DAO
::triggerRebuild($tableName);
844 * Delete content / rows of a custom table specific entity-id for a given custom-group table.
846 * @param int $customTable
848 * @param int $entityID
851 * @return null|string
853 * @throws \CRM_Core_Exception
855 public static function deleteCustomRowsForEntityID($customTable, $entityID) {
856 $customTable = CRM_Utils_Type
::escape($customTable, 'String');
857 $query = "DELETE FROM {$customTable} WHERE entity_id = %1";
858 return CRM_Core_DAO
::singleValueQuery($query, [1 => [$entityID, 'Integer']]);
862 * Get all contact types, leveraging caching.
864 * Note, this function is used within APIv4 Entity.get, so must use a
865 * SQL query instead of calling APIv4 to avoid an infinite loop.
868 * @throws \API_Exception
870 protected static function getAllContactTypes() {
871 $cache = Civi
::cache('contactTypes');
872 $cacheKey = 'all_' . $GLOBALS['tsLocale'];
873 $contactTypes = $cache->get($cacheKey);
874 if ($contactTypes === NULL) {
875 $query = CRM_Utils_SQL_Select
::from('civicrm_contact_type');
876 $dao = CRM_Core_DAO
::executeQuery($query->toSQL());
877 $contactTypes = array_column($dao->fetchAll(), NULL, 'name');
878 $name_options = self
::buildOptions('parent_id', 'validate');
879 $label_options = self
::buildOptions('parent_id', 'get');
880 foreach ($contactTypes as $id => $contactType) {
881 $contactTypes[$id]['parent'] = $contactType['parent_id'] ?
$name_options[$contactType['parent_id']] : NULL;
882 $contactTypes[$id]['parent_label'] = $contactType['parent_id'] ?
$label_options[$contactType['parent_id']] : NULL;
883 // Cast int/bool types.
884 $contactTypes[$id]['id'] = (int) $contactType['id'];
885 $contactTypes[$id]['parent_id'] = $contactType['parent_id'] ?
(int) $contactType['parent_id'] : NULL;
886 $contactTypes[$id]['is_active'] = (bool) $contactType['is_active'];
887 $contactTypes[$id]['is_reserved'] = (bool) $contactType['is_reserved'];
889 $cache->set($cacheKey, $contactTypes);
891 return $contactTypes;