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_BAO_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 $active = array_key_exists($contactType, $contact);
56 * Retrieve basic contact type information.
58 * @param bool $includeInactive
61 * Array of basic contact types information.
63 * @throws \API_Exception
64 * @throws \Civi\API\Exception\UnauthorizedException
66 public static function basicTypeInfo($includeInactive = FALSE) {
67 $cacheKey = 'CRM_CT_BTI_' . (int) $includeInactive;
68 if (!Civi
::cache('contactTypes')->has($cacheKey)) {
69 $contactType = ContactType
::get()->setCheckPermissions(FALSE)->setSelect(['*'])->addWhere('parent_id', 'IS NULL');
70 if ($includeInactive === FALSE) {
71 $contactType->addWhere('is_active', '=', 1);
73 Civi
::cache('contactTypes')->set($cacheKey, (array) $contactType->execute()->indexBy('name'));
75 return Civi
::cache('contactTypes')->get($cacheKey);
79 * Retrieve all basic contact types.
84 * Array of basic contact types
86 * @throws \API_Exception
87 * @throws \Civi\API\Exception\UnauthorizedException
89 public static function basicTypes($all = FALSE) {
90 return array_keys(self
::basicTypeInfo($all));
98 * @throws \API_Exception
99 * @throws \Civi\API\Exception\UnauthorizedException
101 public static function basicTypePairs($all = FALSE, $key = 'name') {
102 $subtypes = self
::basicTypeInfo($all);
105 foreach ($subtypes as $name => $info) {
106 $index = ($key == 'name') ?
$name : $info[$key];
107 $pairs[$index] = $info['label'];
113 * Retrieve all subtypes Information.
115 * @param array $contactType
118 * @param bool $ignoreCache
121 * Array of sub type information
123 public static function subTypeInfo($contactType = NULL, $all = FALSE, $ignoreCache = FALSE) {
124 $argString = $all ?
'CRM_CT_STI_1_' : 'CRM_CT_STI_0_';
125 if (!empty($contactType)) {
126 $contactType = (array) $contactType;
127 $argString .= implode('_', $contactType);
129 if (!Civi
::cache('contactTypes')->has($argString) ||
$ignoreCache) {
131 if (!empty($contactType)) {
132 $ctWHERE = " AND parent.name IN ('" . implode("','", $contactType) . "')";
136 SELECT subtype.*, parent.name as parent, parent.label as parent_label
137 FROM civicrm_contact_type subtype
138 INNER JOIN civicrm_contact_type parent ON subtype.parent_id = parent.id
139 WHERE subtype.name IS NOT NULL AND subtype.parent_id IS NOT NULL {$ctWHERE}
141 if ($all === FALSE) {
142 $sql .= " AND subtype.is_active = 1 AND parent.is_active = 1 ORDER BY parent.id";
144 $dao = CRM_Core_DAO
::executeQuery($sql, [],
145 FALSE, 'CRM_Contact_DAO_ContactType'
148 while ($dao->fetch()) {
150 CRM_Core_DAO
::storeValues($dao, $value);
151 $value['parent'] = $dao->parent
;
152 $value['parent_label'] = $dao->parent_label
;
153 $values[$dao->name
] = $value;
155 Civi
::cache('contactTypes')->set($argString, $values);
157 return Civi
::cache('contactTypes')->get($argString);
162 * retrieve all subtypes
164 * @param array $contactType
167 * @param string $columnName
168 * @param bool $ignoreCache
171 * all subtypes OR list of subtypes associated to
172 * a given basic contact type
174 public static function subTypes($contactType = NULL, $all = FALSE, $columnName = 'name', $ignoreCache = FALSE) {
175 if ($columnName === 'name') {
176 return array_keys(self
::subTypeInfo($contactType, $all, $ignoreCache));
179 return array_values(self
::subTypePairs($contactType, FALSE, NULL, $ignoreCache));
185 * retrieve subtype pairs with name as 'subtype-name' and 'label' as value
187 * @param array $contactType
189 * @param string $labelPrefix
190 * @param bool $ignoreCache
193 * list of subtypes with name as 'subtype-name' and 'label' as value
195 public static function subTypePairs($contactType = NULL, $all = FALSE, $labelPrefix = '- ', $ignoreCache = FALSE) {
196 $subtypes = self
::subTypeInfo($contactType, $all, $ignoreCache);
199 foreach ($subtypes as $name => $info) {
200 $pairs[$name] = $labelPrefix . $info['label'];
207 * retrieve list of all types i.e basic + subtypes.
212 * Array of basic types + all subtypes.
214 public static function contactTypes($all = FALSE) {
215 return array_keys(self
::contactTypeInfo($all));
219 * Retrieve info array about all types i.e basic + subtypes.
224 * Array of basic types + all subtypes.
226 public static function contactTypeInfo($all = FALSE) {
227 static $_cache = NULL;
229 if ($_cache === NULL) {
233 $argString = $all ?
'CRM_CT_CTI_1' : 'CRM_CT_CTI_0';
234 if (!array_key_exists($argString, $_cache)) {
235 $cache = CRM_Utils_Cache
::singleton();
236 $_cache[$argString] = $cache->get($argString);
237 if (!$_cache[$argString]) {
238 $_cache[$argString] = [];
241 SELECT type.*, parent.name as parent, parent.label as parent_label
242 FROM civicrm_contact_type type
243 LEFT JOIN civicrm_contact_type parent ON type.parent_id = parent.id';
245 if ($all === FALSE) {
246 $sql .= ' AND type.is_active = 1';
249 $dao = CRM_Core_DAO
::executeQuery($sql,
252 'CRM_Contact_DAO_ContactType'
254 while ($dao->fetch()) {
256 CRM_Core_DAO
::storeValues($dao, $value);
257 if (array_key_exists('parent_id', $value)) {
258 $value['parent'] = $dao->parent
;
259 $value['parent_label'] = $dao->parent_label
;
261 $_cache[$argString][$dao->name
] = $value;
264 $cache->set($argString, $_cache[$argString]);
268 return $_cache[$argString];
272 * Retrieve basic type pairs with name as 'built-in name' and 'label' as value.
275 * @param null $typeName
276 * @param null $delimiter
279 * Array of basictypes with name as 'built-in name' and 'label' as value
281 public static function contactTypePairs($all = FALSE, $typeName = NULL, $delimiter = NULL) {
282 $types = self
::contactTypeInfo($all);
284 if ($typeName && !is_array($typeName)) {
285 $typeName = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, trim($typeName, CRM_Core_DAO
::VALUE_SEPARATOR
));
290 foreach ($typeName as $type) {
291 if (array_key_exists($type, $types)) {
292 $pairs[$type] = $types[$type]['label'];
297 foreach ($types as $name => $info) {
298 $pairs[$name] = $info['label'];
302 return !$delimiter ?
$pairs : implode($delimiter, $pairs);
306 * Get a list of elements for select box.
307 * Note that this used to default to using the hex(01) character - which results in an invalid character being used in form fields
308 * which was not handled well be anything that loaded & resaved the html (outside core)
309 * The use of this separator is now explicit in the calling functions as a step towards it's removal
312 * @param bool $isSeparator
313 * @param string $separator
317 public static function getSelectElements(
322 // @todo - use Cache class - ie like Civi::cache('contactTypes')
323 static $_cache = NULL;
325 if ($_cache === NULL) {
329 $argString = $all ?
'CRM_CT_GSE_1' : 'CRM_CT_GSE_0';
330 $argString .= $isSeparator ?
'_1' : '_0';
331 $argString .= $separator;
332 $argString = CRM_Utils_Cache
::cleanKey($argString);
333 if (!array_key_exists($argString, $_cache)) {
334 $cache = CRM_Utils_Cache
::singleton();
335 $_cache[$argString] = $cache->get($argString);
337 if (!$_cache[$argString]) {
338 $_cache[$argString] = [];
341 SELECT c.name as child_name , c.label as child_label , c.id as child_id,
342 p.name as parent_name, p.label as parent_label, p.id as parent_id
343 FROM civicrm_contact_type c
344 LEFT JOIN civicrm_contact_type p ON ( c.parent_id = p.id )
345 WHERE ( c.name IS NOT NULL )
348 if ($all === FALSE) {
351 AND ( p.is_active = 1 OR p.id IS NULL )
354 $sql .= " ORDER BY c.id";
357 $dao = CRM_Core_DAO
::executeQuery($sql);
358 while ($dao->fetch()) {
359 if (!empty($dao->parent_id
)) {
360 $key = $isSeparator ?
$dao->parent_name
. $separator . $dao->child_name
: $dao->child_name
;
361 $label = "- {$dao->child_label}";
362 $pName = $dao->parent_name
;
365 $key = $dao->child_name
;
366 $label = $dao->child_label
;
367 $pName = $dao->child_name
;
370 if (!isset($values[$pName])) {
371 $values[$pName] = [];
373 $values[$pName][] = ['key' => $key, 'label' => $label];
376 $selectElements = [];
377 foreach ($values as $pName => $elements) {
378 foreach ($elements as $element) {
379 $selectElements[$element['key']] = $element['label'];
382 $_cache[$argString] = $selectElements;
384 $cache->set($argString, $_cache[$argString]);
387 return $_cache[$argString];
391 * Check if a given type is a subtype.
393 * @param string $subType
395 * @param bool $ignoreCache
398 * true if subType, false otherwise.
400 public static function isaSubType($subType, $ignoreCache = FALSE) {
401 return in_array($subType, self
::subTypes(NULL, TRUE, 'name', $ignoreCache));
405 * Retrieve the basic contact type associated with given subType.
407 * @param array|string $subType contact subType.
408 * @return array|string
411 public static function getBasicType($subType) {
412 // @todo - use Cache class - ie like Civi::cache('contactTypes')
413 static $_cache = NULL;
414 if ($_cache === NULL) {
419 if ($subType && !is_array($subType)) {
420 $subType = [$subType];
423 $argString = implode('_', $subType);
425 if (!array_key_exists($argString, $_cache)) {
426 $_cache[$argString] = [];
429 SELECT subtype.name as contact_subtype, type.name as contact_type
430 FROM civicrm_contact_type subtype
431 INNER JOIN civicrm_contact_type type ON ( subtype.parent_id = type.id )
432 WHERE subtype.name IN ('" . implode("','", $subType) . "' )";
433 $dao = CRM_Core_DAO
::executeQuery($sql);
434 while ($dao->fetch()) {
436 $_cache[$argString] = $dao->contact_type
;
439 $_cache[$argString][$dao->contact_subtype
] = $dao->contact_type
;
442 return $_cache[$argString];
446 * Suppress all subtypes present in given array.
448 * @param array $subTypes
450 * @param bool $ignoreCache
453 * Array of suppressed subTypes.
455 public static function suppressSubTypes(&$subTypes, $ignoreCache = FALSE) {
456 $subTypes = array_diff($subTypes, self
::subTypes(NULL, TRUE, 'name', $ignoreCache));
461 * Verify if a given subtype is associated with a given basic contact type.
463 * @param string $subType
465 * @param string $contactType
467 * @param bool $ignoreCache
468 * @param string $columnName
471 * true if contact extends, false otherwise.
473 public static function isExtendsContactType($subType, $contactType, $ignoreCache = FALSE, $columnName = 'name') {
474 $subType = (array) CRM_Utils_Array
::explodePadded($subType);
475 $subtypeList = self
::subTypes($contactType, TRUE, $columnName, $ignoreCache);
476 $intersection = array_intersect($subType, $subtypeList);
477 return $subType == $intersection;
481 * Create shortcuts menu for contactTypes.
486 public static function getCreateNewList() {
488 //@todo FIXME - using the CRM_Core_DAO::VALUE_SEPARATOR creates invalid html - if you can find the form
489 // this is loaded onto then replace with something like '__' & test
490 $separator = CRM_Core_DAO
::VALUE_SEPARATOR
;
491 $contactTypes = self
::getSelectElements(FALSE, TRUE, $separator);
492 foreach ($contactTypes as $key => $value) {
494 $typeValue = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $key);
495 $cType = $typeValue['0'] ??
NULL;
496 $typeUrl = 'ct=' . $cType;
497 if ($csType = CRM_Utils_Array
::value('1', $typeValue)) {
498 $typeUrl .= "&cst=$csType";
501 'path' => 'civicrm/contact/add',
502 'query' => "$typeUrl&reset=1",
503 'ref' => "new-$value",
506 if ($csType = CRM_Utils_Array
::value('1', $typeValue)) {
507 $shortCuts[$cType]['shortCuts'][] = $shortCut;
510 $shortCuts[$cType] = $shortCut;
518 * Delete Contact SubTypes.
520 * @param int $contactTypeId
521 * ID of the Contact Subtype to be deleted.
525 public static function del($contactTypeId) {
527 if (!$contactTypeId) {
531 $params = ['id' => $contactTypeId];
532 self
::retrieve($params, $typeInfo);
533 $name = $typeInfo['name'];
534 // check if any custom group
535 $custom = new CRM_Core_DAO_CustomGroup();
536 $custom->whereAdd("extends_entity_column_value LIKE '%" .
537 CRM_Core_DAO
::VALUE_SEPARATOR
.
539 CRM_Core_DAO
::VALUE_SEPARATOR
. "%'"
541 if ($custom->find()) {
545 // remove subtype for existing contacts
547 UPDATE civicrm_contact SET contact_sub_type = NULL
548 WHERE contact_sub_type = '$name'";
549 CRM_Core_DAO
::executeQuery($sql);
551 // remove subtype from contact type table
552 $contactType = new CRM_Contact_DAO_ContactType();
553 $contactType->id
= $contactTypeId;
554 $contactType->delete();
556 // remove navigation entry if any
560 FROM civicrm_navigation
562 $params = [1 => ["New $name", 'String']];
563 CRM_Core_DAO
::executeQuery($sql, $params);
564 CRM_Core_BAO_Navigation
::resetNavigation();
565 Civi
::cache('contactTypes')->clear();
571 * Add or update Contact SubTypes.
573 * @param array $params
574 * An assoc array of name/value pairs.
576 * @return object|void
577 * @throws \CRM_Core_Exception
579 public static function add(&$params) {
582 if (empty($params['id']) && empty($params['label'])) {
583 // @todo consider throwing exception instead.
586 if (empty($params['id']) && empty($params['name'])) {
587 $params['name'] = ucfirst(CRM_Utils_String
::munge($params['label']));
589 if (!empty($params['parent_id']) &&
590 !CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_ContactType', $params['parent_id'])
595 $contactType = new CRM_Contact_DAO_ContactType();
596 $contactType->copyValues($params);
597 $contactType->id
= $params['id'] ??
NULL;
599 $contactType->save();
600 if ($contactType->find(TRUE)) {
601 $contactName = $contactType->name
;
602 $contact = ucfirst($contactType->label
);
603 $active = $contactType->is_active
;
606 if (!empty($params['id'])) {
608 'label' => ts("New %1", [1 => $contact]),
609 'is_active' => $contactType->is_active
,
611 CRM_Core_BAO_Navigation
::processUpdate(['name' => "New $contactName"], $newParams);
614 $name = self
::getBasicType($contactName);
618 $value = ['name' => "New $name"];
619 CRM_Core_BAO_Navigation
::retrieve($value, $navinfo);
621 'label' => ts("New %1", [1 => $contact]),
622 'name' => "New $contactName",
623 'url' => "civicrm/contact/add?ct=$name&cst=$contactName&reset=1",
624 'permission' => 'add contacts',
625 'parent_id' => $navinfo['id'],
626 'is_active' => $active,
628 CRM_Core_BAO_Navigation
::add($navigation);
630 CRM_Core_BAO_Navigation
::resetNavigation();
631 Civi
::cache('contactTypes')->clear();
637 * Update the is_active flag in the db.
640 * Id of the database record.
641 * @param bool $is_active
642 * Value we want to set the is_active field.
645 * true if we found and updated the object, else false
647 public static function setIsActive($id, $is_active) {
648 $params = ['id' => $id];
649 self
::retrieve($params, $contactinfo);
650 $params = ['name' => "New $contactinfo[name]"];
651 $newParams = ['is_active' => $is_active];
652 CRM_Core_BAO_Navigation
::processUpdate($params, $newParams);
653 CRM_Core_BAO_Navigation
::resetNavigation();
654 return CRM_Core_DAO
::setFieldValue('CRM_Contact_DAO_ContactType', $id,
655 'is_active', $is_active
660 * @param string $typeName
664 public static function getLabel($typeName) {
665 $types = self
::contactTypeInfo(TRUE);
667 if (array_key_exists($typeName, $types)) {
668 return $types[$typeName]['label'];
674 * Check whether allow to change any contact's subtype
675 * on the basis of custom data and relationship of specific subtype
676 * currently used in contact/edit form amd in import validation
678 * @param int $contactId
680 * @param string $subType
684 * @throws \CRM_Core_Exception
686 public static function isAllowEdit($contactId, $subType = NULL) {
692 if (empty($subType)) {
693 $subType = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact',
699 if (self
::hasCustomData($subType, $contactId) || self
::hasRelationships($contactId, $subType)) {
707 * @param $contactType
708 * @param int $contactId
712 public static function hasCustomData($contactType, $contactId = NULL) {
715 if (self
::isaSubType($contactType)) {
716 $subType = $contactType;
717 $contactType = self
::getBasicType($subType);
719 // check for empty custom data which extends subtype
720 $subTypeValue = CRM_Core_DAO
::VALUE_SEPARATOR
. $subType . CRM_Core_DAO
::VALUE_SEPARATOR
;
721 $subTypeClause = " AND extends_entity_column_value LIKE '%{$subTypeValue}%' ";
723 $query = "SELECT table_name FROM civicrm_custom_group WHERE extends = '{$contactType}' {$subTypeClause}";
725 $dao = CRM_Core_DAO
::executeQuery($query);
726 while ($dao->fetch()) {
727 $sql = "SELECT count(id) FROM {$dao->table_name}";
729 $sql .= " WHERE entity_id = {$contactId}";
733 $customDataCount = CRM_Core_DAO
::singleValueQuery($sql);
734 if (!empty($customDataCount)) {
742 * @todo what does this function do?
743 * @param int $contactId
744 * @param $contactType
748 public static function hasRelationships($contactId, $contactType) {
749 $subTypeClause = NULL;
750 if (self
::isaSubType($contactType)) {
751 $subType = $contactType;
752 $contactType = self
::getBasicType($subType);
753 $subTypeClause = " AND ( ( crt.contact_type_a = '{$contactType}' AND crt.contact_sub_type_a = '{$subType}') OR
754 ( crt.contact_type_b = '{$contactType}' AND crt.contact_sub_type_b = '{$subType}') ) ";
757 $subTypeClause = " AND ( crt.contact_type_a = '{$contactType}' OR crt.contact_type_b = '{$contactType}' ) ";
760 // check relationships for
761 $relationshipQuery = "
762 SELECT count(cr.id) FROM civicrm_relationship cr
763 INNER JOIN civicrm_relationship_type crt ON
764 ( cr.relationship_type_id = crt.id {$subTypeClause} )
765 WHERE ( cr.contact_id_a = {$contactId} OR cr.contact_id_b = {$contactId} )
768 $relationshipCount = CRM_Core_DAO
::singleValueQuery($relationshipQuery);
770 if (!empty($relationshipCount)) {
778 * @param $contactType
779 * @param array $subtypeSet
782 * @throws \CRM_Core_Exception
783 * @todo what does this function do?
785 public static function getSubtypeCustomPair($contactType, $subtypeSet = []) {
786 if (empty($subtypeSet)) {
790 $customSet = $subTypeClause = [];
791 foreach ($subtypeSet as $subtype) {
792 $subtype = CRM_Utils_Type
::escape($subtype, 'String');
793 $subtype = CRM_Core_DAO
::VALUE_SEPARATOR
. $subtype . CRM_Core_DAO
::VALUE_SEPARATOR
;
794 $subTypeClause[] = "extends_entity_column_value LIKE '%{$subtype}%' ";
796 $query = 'SELECT table_name
797 FROM civicrm_custom_group
798 WHERE extends = %1 AND ' . implode(" OR ", $subTypeClause);
799 $dao = CRM_Core_DAO
::executeQuery($query, [1 => [$contactType, 'String']]);
800 while ($dao->fetch()) {
801 $customSet[] = $dao->table_name
;
803 return array_unique($customSet);
807 * Function that does something.
808 * @todo what does this function do?
810 * @param int $contactID
811 * @param $contactType
812 * @param array $oldSubtypeSet
813 * @param array $newSubtypeSet
817 public static function deleteCustomSetForSubtypeMigration(
823 $oldCustomSet = self
::getSubtypeCustomPair($contactType, $oldSubtypeSet);
824 $newCustomSet = self
::getSubtypeCustomPair($contactType, $newSubtypeSet);
826 $customToBeRemoved = array_diff($oldCustomSet, $newCustomSet);
827 foreach ($customToBeRemoved as $customTable) {
828 self
::deleteCustomRowsForEntityID($customTable, $contactID);
834 * Delete content / rows of a custom table specific to a subtype for a given custom-group.
835 * This function currently works for contact subtypes only and could be later improved / genralized
836 * to work for other subtypes as well.
840 * @param array $subtypes
841 * List of subtypes related to which entry is to be removed.
842 * @param array $subtypesToPreserve
846 public static function deleteCustomRowsOfSubtype($gID, $subtypes = [], $subtypesToPreserve = []) {
847 if (!$gID or empty($subtypes)) {
851 $tableName = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_CustomGroup', $gID, 'table_name');
853 // drop triggers CRM-13587
854 CRM_Core_DAO
::dropTriggers($tableName);
856 foreach ($subtypesToPreserve as $subtypeToPreserve) {
857 $subtypeToPreserve = CRM_Utils_Type
::escape($subtypeToPreserve, 'String');
858 $subtypesToPreserveClause[] = "(civicrm_contact.contact_sub_type NOT LIKE '%" . CRM_Core_DAO
::VALUE_SEPARATOR
. $subtypeToPreserve . CRM_Core_DAO
::VALUE_SEPARATOR
. "%')";
860 $subtypesToPreserveClause = implode(' AND ', $subtypesToPreserveClause);
863 foreach ($subtypes as $subtype) {
864 $subtype = CRM_Utils_Type
::escape($subtype, 'String');
865 $subtypeClause[] = "( civicrm_contact.contact_sub_type LIKE '%" . CRM_Core_DAO
::VALUE_SEPARATOR
. $subtype . CRM_Core_DAO
::VALUE_SEPARATOR
. "%'"
866 . " AND " . $subtypesToPreserveClause . ")";
868 $subtypeClause = implode(' OR ', $subtypeClause);
870 $query = "DELETE custom.*
871 FROM {$tableName} custom
872 INNER JOIN civicrm_contact ON civicrm_contact.id = custom.entity_id
873 WHERE ($subtypeClause)";
875 CRM_Core_DAO
::singleValueQuery($query);
877 // rebuild triggers CRM-13587
878 CRM_Core_DAO
::triggerRebuild($tableName);
882 * Delete content / rows of a custom table specific entity-id for a given custom-group table.
884 * @param int $customTable
886 * @param int $entityID
889 * @return null|string
891 public static function deleteCustomRowsForEntityID($customTable, $entityID) {
892 $customTable = CRM_Utils_Type
::escape($customTable, 'String');
893 $query = "DELETE FROM {$customTable} WHERE entity_id = %1";
894 return CRM_Core_DAO
::singleValueQuery($query, [1 => [$entityID, 'Integer']]);