3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
35 class CRM_Contact_BAO_ContactType
extends CRM_Contact_DAO_ContactType
{
38 * Takes a bunch of params that are needed to match certain criteria and
39 * retrieves the relevant objects. Typically the valid params are only
40 * contact_id. We'll tweak this function to be more full featured over a period
41 * of time. This is the inverse function of create. It also stores all the retrieved
42 * values in the default array
44 * @param array $params (reference ) an assoc array of name/value pairs
45 * @param array $defaults (reference ) an assoc array to hold the flattened values
47 * @return object CRM_Contact_BAO_ContactType object on success, null otherwise
51 static function retrieve(&$params, &$defaults) {
52 $contactType = new CRM_Contact_DAO_ContactType();
53 $contactType->copyValues($params);
54 if ($contactType->find(TRUE)) {
55 CRM_Core_DAO
::storeValues($contactType, $defaults);
61 static function isActive($contactType) {
62 $contact = self
::contactTypeInfo(FALSE);
63 $active = array_key_exists($contactType, $contact) ?
TRUE : FALSE;
69 *function to retrieve basic contact type information.
73 * @return array of basic contact types information.
76 static function &basicTypeInfo($all = FALSE) {
77 static $_cache = NULL;
79 if ($_cache === NULL) {
83 $argString = $all ?
'CRM_CT_BTI_1' : 'CRM_CT_BTI_0';
84 if (!array_key_exists($argString, $_cache)) {
85 $cache = CRM_Utils_Cache
::singleton();
86 $_cache[$argString] = $cache->get($argString);
87 if (!$_cache[$argString]) {
90 FROM civicrm_contact_type
91 WHERE parent_id IS NULL
94 $sql .= " AND is_active = 1";
97 $dao = CRM_Core_DAO
::executeQuery($sql,
98 CRM_Core_DAO
::$_nullArray,
100 'CRM_Contact_DAO_ContactType'
102 while ($dao->fetch()) {
104 CRM_Core_DAO
::storeValues($dao, $value);
105 $_cache[$argString][$dao->name
] = $value;
108 $cache->set($argString, $_cache[$argString]);
111 return $_cache[$argString];
116 *function to retrieve all basic contact types.
120 * @return array of basic contact types
123 static function basicTypes($all = FALSE) {
124 return array_keys(self
::basicTypeInfo($all));
127 static function basicTypePairs($all = FALSE, $key = 'name') {
128 $subtypes = self
::basicTypeInfo($all);
131 foreach ($subtypes as $name => $info) {
132 $index = ($key == 'name') ?
$name : $info[$key];
133 $pairs[$index] = $info['label'];
140 *function to retrieve all subtypes Information.
142 * @param array $contactType .
144 * @param bool $ignoreCache
147 * @return array of sub type information
150 static function &subTypeInfo($contactType = NULL, $all = FALSE, $ignoreCache = FALSE, $reset = FALSE) {
151 static $_cache = NULL;
153 if ($reset === TRUE) {
157 if ($_cache === NULL) {
160 if ($contactType && !is_array($contactType)) {
161 $contactType = array($contactType);
164 $argString = $all ?
'CRM_CT_STI_1_' : 'CRM_CT_STI_0_';
165 if (!empty($contactType)) {
166 $argString .= implode('_', $contactType);
169 if ((!array_key_exists($argString, $_cache)) ||
$ignoreCache) {
170 $cache = CRM_Utils_Cache
::singleton();
171 $_cache[$argString] = $cache->get($argString);
172 if (!$_cache[$argString] ||
$ignoreCache) {
173 $_cache[$argString] = array();
176 if (!empty($contactType)) {
177 $ctWHERE = " AND parent.name IN ('" . implode("','", $contactType) . "')";
181 SELECT subtype.*, parent.name as parent, parent.label as parent_label
182 FROM civicrm_contact_type subtype
183 INNER JOIN civicrm_contact_type parent ON subtype.parent_id = parent.id
184 WHERE subtype.name IS NOT NULL AND subtype.parent_id IS NOT NULL {$ctWHERE}
186 if ($all === FALSE) {
187 $sql .= " AND subtype.is_active = 1 AND parent.is_active = 1 ORDER BY parent.id";
189 $dao = CRM_Core_DAO
::executeQuery($sql, array(),
190 FALSE, 'CRM_Contact_DAO_ContactType'
192 while ($dao->fetch()) {
194 CRM_Core_DAO
::storeValues($dao, $value);
195 $value['parent'] = $dao->parent
;
196 $value['parent_label'] = $dao->parent_label
;
197 $_cache[$argString][$dao->name
] = $value;
200 $cache->set($argString, $_cache[$argString]);
203 return $_cache[$argString];
208 *function to retrieve all subtypes
210 * @param array $contactType .
212 * @param string $columnName
213 * @param bool $ignoreCache
215 * @return array of all subtypes OR list of subtypes associated to
216 *a given basic contact type
219 static function subTypes($contactType = NULL, $all = FALSE, $columnName = 'name', $ignoreCache = FALSE) {
220 if ($columnName == 'name') {
221 return array_keys(self
::subTypeInfo($contactType, $all, $ignoreCache));
224 return array_values(self
::subTypePairs($contactType, FALSE, NULL, $ignoreCache));
230 *function to retrieve subtype pairs with name as 'subtype-name' and 'label' as value
232 * @param array $contactType .
234 * @param string $labelPrefix
235 * @param bool $ignoreCache
237 * @return list of subtypes with name as 'subtype-name' and 'label' as value
240 static function subTypePairs($contactType = NULL, $all = FALSE, $labelPrefix = '- ', $ignoreCache = FALSE) {
241 $subtypes = self
::subTypeInfo($contactType, $all, $ignoreCache);
244 foreach ($subtypes as $name => $info) {
245 $pairs[$name] = $labelPrefix . $info['label'];
252 *function to retrieve list of all types i.e basic + subtypes.
256 * @return array of basic types + all subtypes.
259 static function contactTypes($all = FALSE) {
260 return array_keys(self
::contactTypeInfo($all));
265 *function to retrieve info array about all types i.e basic + subtypes.
270 * @return array of basic types + all subtypes.
273 static function contactTypeInfo($all = FALSE, $reset = FALSE) {
274 static $_cache = NULL;
276 if ($reset === TRUE) {
280 if ($_cache === NULL) {
284 $argString = $all ?
'CRM_CT_CTI_1' : 'CRM_CT_CTI_0';
285 if (!array_key_exists($argString, $_cache)) {
286 $cache = CRM_Utils_Cache
::singleton();
287 $_cache[$argString] = $cache->get($argString);
288 if (!$_cache[$argString]) {
289 $_cache[$argString] = array();
292 SELECT type.*, parent.name as parent, parent.label as parent_label
293 FROM civicrm_contact_type type
294 LEFT JOIN civicrm_contact_type parent ON type.parent_id = parent.id
295 WHERE type.name IS NOT NULL
297 if ($all === FALSE) {
298 $sql .= " AND type.is_active = 1";
301 $dao = CRM_Core_DAO
::executeQuery($sql,
302 CRM_Core_DAO
::$_nullArray,
304 'CRM_Contact_DAO_ContactType'
306 while ($dao->fetch()) {
308 CRM_Core_DAO
::storeValues($dao, $value);
309 if (array_key_exists('parent_id', $value)) {
310 $value['parent'] = $dao->parent
;
311 $value['parent_label'] = $dao->parent_label
;
313 $_cache[$argString][$dao->name
] = $value;
316 $cache->set($argString, $_cache[$argString]);
320 return $_cache[$argString];
325 *function to retrieve basic type pairs with name as 'built-in name' and 'label' as value
328 * @param null $typeName
329 * @param null $delimiter
331 * @internal param array $contactType .
332 * @return list of basictypes with name as 'built-in name' and 'label' as value
335 static function contactTypePairs($all = FALSE, $typeName = NULL, $delimiter = NULL) {
336 $types = self
::contactTypeInfo($all);
338 if ($typeName && !is_array($typeName)) {
339 $typeName = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, trim($typeName, CRM_Core_DAO
::VALUE_SEPARATOR
));
344 foreach ($typeName as $type) {
345 if (array_key_exists($type, $types)) {
346 $pairs[$type] = $types[$type]['label'];
351 foreach ($types as $name => $info) {
352 $pairs[$name] = $info['label'];
356 return !$delimiter ?
$pairs : implode($delimiter, $pairs);
360 * Get a list of elements for select box
361 * Note that this used to default to using the hex(01) character - which results in an invalid character being used in form fields
362 * which was not handled well be anything that loaded & resaved the html (outside core)
363 * The use of this separator is now explicit in the calling functions as a step towards it's removal
366 * @param bool $isSeparator
367 * @param string $separator
371 static function getSelectElements($all = FALSE,
375 static $_cache = NULL;
377 if ($_cache === NULL) {
381 $argString = $all ?
'CRM_CT_GSE_1' : 'CRM_CT_GSE_0';
382 $argString .= $isSeparator ?
'_1' : '_0';
383 if (!array_key_exists($argString, $_cache)) {
384 $cache = CRM_Utils_Cache
::singleton();
385 $_cache[$argString] = $cache->get($argString);
387 if (!$_cache[$argString]) {
388 $_cache[$argString] = array();
391 SELECT c.name as child_name , c.label as child_label , c.id as child_id,
392 p.name as parent_name, p.label as parent_label, p.id as parent_id
393 FROM civicrm_contact_type c
394 LEFT JOIN civicrm_contact_type p ON ( c.parent_id = p.id )
395 WHERE ( c.name IS NOT NULL )
398 if ($all === FALSE) {
401 AND ( p.is_active = 1 OR p.id IS NULL )
404 $sql .= " ORDER BY c.id";
407 $dao = CRM_Core_DAO
::executeQuery($sql);
408 while ($dao->fetch()) {
409 if (!empty($dao->parent_id
)) {
410 $key = $isSeparator ?
$dao->parent_name
. $separator . $dao->child_name
: $dao->child_name
;
411 $label = "- {$dao->child_label}";
412 $pName = $dao->parent_name
;
415 $key = $dao->child_name
;
416 $label = $dao->child_label
;
417 $pName = $dao->child_name
;
420 if (!isset($values[$pName])) {
421 $values[$pName] = array();
423 $values[$pName][] = array('key' => $key, 'label' => $label);
426 $selectElements = array();
427 foreach ($values as $pName => $elements) {
428 foreach ($elements as $element) {
429 $selectElements[$element['key']] = $element['label'];
432 $_cache[$argString] = $selectElements;
434 $cache->set($argString, $_cache[$argString]);
437 return $_cache[$argString];
441 * function to check if a given type is a subtype
443 * @param string $subType contact subType.
444 * @param bool $ignoreCache
446 * @return boolean true if subType, false otherwise.
449 static function isaSubType($subType, $ignoreCache = FALSE) {
450 return in_array($subType, self
::subTypes(NULL, TRUE, 'name', $ignoreCache));
454 *function to retrieve the basic contact type associated with
457 *@param array/string $subType contact subType.
458 *@return array/string of basicTypes.
462 static function getBasicType($subType) {
463 static $_cache = NULL;
464 if ($_cache === NULL) {
469 if ($subType && !is_array($subType)) {
470 $subType = array($subType);
473 $argString = implode('_', $subType);
475 if (!array_key_exists($argString, $_cache)) {
476 $_cache[$argString] = array();
479 SELECT subtype.name as contact_subtype, type.name as contact_type
480 FROM civicrm_contact_type subtype
481 INNER JOIN civicrm_contact_type type ON ( subtype.parent_id = type.id )
482 WHERE subtype.name IN ('" . implode("','", $subType) . "' )";
483 $dao = CRM_Core_DAO
::executeQuery($sql);
484 while ($dao->fetch()) {
486 $_cache[$argString] = $dao->contact_type
;
489 $_cache[$argString][$dao->contact_subtype
] = $dao->contact_type
;
492 return $_cache[$argString];
497 *function to suppress all subtypes present in given array.
500 * @param bool $ignoreCache
502 * @internal param array $subType contact subType.
503 * @return array of suppresssubTypes .
506 static function suppressSubTypes(&$subTypes, $ignoreCache = FALSE) {
507 $subTypes = array_diff($subTypes, self
::subTypes(NULL, TRUE, 'name', $ignoreCache));
513 *function to verify if a given subtype is associated with a given basic contact type.
515 * @param string $subType contact subType
516 * @param string $contactType contact Type
517 * @param bool $ignoreCache
518 * @param string $columnName
520 * @return boolean true if contact extends, false otherwise.
523 static function isExtendsContactType($subType, $contactType, $ignoreCache = FALSE, $columnName = 'name') {
524 if (!is_array($subType)) {
525 $subType = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, trim($subType, CRM_Core_DAO
::VALUE_SEPARATOR
));
527 $subtypeList = self
::subTypes($contactType, TRUE, $columnName, $ignoreCache);
528 $intersection = array_intersect($subType, $subtypeList);
529 return $subType == $intersection;
534 *function to create shortcuts menu for contactTypes
536 *@return array of contactTypes
540 static function getCreateNewList() {
541 $shortCuts = array();
542 //@todo FIXME - using the CRM_Core_DAO::VALUE_SEPARATOR creates invalid html - if you can find the form
543 // this is loaded onto then replace with something like '__' & test
544 $separator = CRM_Core_DAO
::VALUE_SEPARATOR
;
545 $contactTypes = self
::getSelectElements(FALSE, TRUE, $separator);
546 foreach ($contactTypes as $key => $value) {
548 $typeValue = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $key);
549 $cType = CRM_Utils_Array
::value('0', $typeValue);
550 $typeUrl = 'ct=' . $cType;
551 if ($csType = CRM_Utils_Array
::value('1', $typeValue)) {
552 $typeUrl .= "&cst=$csType";
555 'path' => 'civicrm/contact/add',
556 'query' => "$typeUrl&reset=1",
557 'ref' => "new-$value",
560 if ($csType = CRM_Utils_Array
::value('1', $typeValue)) {
561 $shortCuts[$cType]['shortCuts'][] = $shortCut;
564 $shortCuts[$cType] = $shortCut;
572 * Function to delete Contact SubTypes
574 * @param int $contactTypeId ID of the Contact Subtype to be deleted.
580 static function del($contactTypeId) {
582 if (!$contactTypeId) {
586 $params = array('id' => $contactTypeId);
587 self
::retrieve($params, $typeInfo);
588 $name = $typeInfo['name'];
589 // check if any custom group
590 $custom = new CRM_Core_DAO_CustomGroup();
591 $custom->whereAdd("extends_entity_column_value LIKE '%" .
592 CRM_Core_DAO
::VALUE_SEPARATOR
.
594 CRM_Core_DAO
::VALUE_SEPARATOR
. "%'"
596 if ($custom->find()) {
600 // remove subtype for existing contacts
602 UPDATE civicrm_contact SET contact_sub_type = NULL
603 WHERE contact_sub_type = '$name'";
604 CRM_Core_DAO
::executeQuery($sql);
606 // remove subtype from contact type table
607 $contactType = new CRM_Contact_DAO_ContactType();
608 $contactType->id
= $contactTypeId;
609 $contactType->delete();
611 // remove navigation entry if any
615 FROM civicrm_navigation
617 $params = array(1 => array("New $name", 'String'));
618 $dao = CRM_Core_DAO
::executeQuery($sql, $params);
619 CRM_Core_BAO_Navigation
::resetNavigation();
625 * Function to add or update Contact SubTypes
627 * @param array $params an assoc array of name/value pairs
633 static function add($params) {
636 if (empty($params['label'])) {
639 if (!empty($params['parent_id']) &&
640 !CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_ContactType', $params['parent_id'])
645 $contactType = new CRM_Contact_DAO_ContactType();
646 $contactType->copyValues($params);
647 $contactType->id
= CRM_Utils_Array
::value('id', $params);
648 $contactType->is_active
= CRM_Utils_Array
::value('is_active', $params, 0);
650 $contactType->save();
651 if ($contactType->find(TRUE)) {
652 $contactName = $contactType->name
;
653 $contact = ucfirst($contactType->label
);
654 $active = $contactType->is_active
;
657 if (!empty($params['id'])) {
658 $params = array('name' => "New $contactName");
660 'label' => "New $contact",
661 'is_active' => $active,
663 CRM_Core_BAO_Navigation
::processUpdate($params, $newParams);
666 $name = self
::getBasicType($contactName);
670 $value = array('name' => "New $name");
671 CRM_Core_BAO_Navigation
::retrieve($value, $navinfo);
673 'label' => "New $contact",
674 'name' => "New $contactName",
675 'url' => "civicrm/contact/add&ct=$name&cst=$contactName&reset=1",
676 'permission' => 'add contacts',
677 'parent_id' => $navinfo['id'],
678 'is_active' => $active,
680 CRM_Core_BAO_Navigation
::add($navigation);
682 CRM_Core_BAO_Navigation
::resetNavigation();
684 // reset the cache after adding
685 self
::subTypeInfo(NULL, FALSE, FALSE, TRUE);
691 * update the is_active flag in the db
693 * @param int $id id of the database record
694 * @param boolean $is_active value we want to set the is_active field
696 * @return Object DAO object on success, null otherwise
699 static function setIsActive($id, $is_active) {
700 $params = array('id' => $id);
701 self
::retrieve($params, $contactinfo);
702 $params = array('name' => "New $contactinfo[name]");
703 $newParams = array('is_active' => $is_active);
704 CRM_Core_BAO_Navigation
::processUpdate($params, $newParams);
705 CRM_Core_BAO_Navigation
::resetNavigation();
706 return CRM_Core_DAO
::setFieldValue('CRM_Contact_DAO_ContactType', $id,
707 'is_active', $is_active
711 static function getLabel($typeName) {
712 $types = self
::contactTypeInfo(TRUE);
714 if (array_key_exists($typeName, $types)) {
715 return $types[$typeName]['label'];
721 * Function to check whether allow to change any contact's subtype
722 * on the basis of custom data and relationship of specific subtype
723 * currently used in contact/edit form amd in import validation
725 * @param int $contactId contact id.
726 * @param string $subType subtype.
728 * @return boolean true/false.
731 static function isAllowEdit($contactId, $subType = NULL) {
737 if (empty($subType)) {
738 $subType = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact',
744 if (self
::hasCustomData($subType, $contactId) || self
::hasRelationships($contactId, $subType)) {
751 static function hasCustomData($contactType, $contactId = NULL) {
754 if (self
::isaSubType($contactType)) {
755 $subType = $contactType;
756 $contactType = self
::getBasicType($subType);
758 // check for empty custom data which extends subtype
759 $subTypeValue = CRM_Core_DAO
::VALUE_SEPARATOR
. $subType . CRM_Core_DAO
::VALUE_SEPARATOR
;
760 $subTypeClause = " AND extends_entity_column_value LIKE '%{$subTypeValue}%' ";
762 $query = "SELECT table_name FROM civicrm_custom_group WHERE extends = '{$contactType}' {$subTypeClause}";
764 $dao = CRM_Core_DAO
::executeQuery($query);
765 while ($dao->fetch()) {
766 $sql = "SELECT count(id) FROM {$dao->table_name}";
768 $sql .= " WHERE entity_id = {$contactId}";
772 $customDataCount = CRM_Core_DAO
::singleValueQuery($sql);
773 if (!empty($customDataCount)) {
782 * @todo what does this function do?
784 * @param $contactType
788 static function hasRelationships($contactId, $contactType) {
789 $subTypeClause = NULL;
790 if (self
::isaSubType($contactType)) {
791 $subType = $contactType;
792 $contactType = self
::getBasicType($subType);
793 $subTypeClause = " AND ( ( crt.contact_type_a = '{$contactType}' AND crt.contact_sub_type_a = '{$subType}') OR
794 ( crt.contact_type_b = '{$contactType}' AND crt.contact_sub_type_b = '{$subType}') ) ";
797 $subTypeClause = " AND ( crt.contact_type_a = '{$contactType}' OR crt.contact_type_b = '{$contactType}' ) ";
800 // check relationships for
801 $relationshipQuery = "
802 SELECT count(cr.id) FROM civicrm_relationship cr
803 INNER JOIN civicrm_relationship_type crt ON
804 ( cr.relationship_type_id = crt.id {$subTypeClause} )
805 WHERE ( cr.contact_id_a = {$contactId} OR cr.contact_id_b = {$contactId} )
808 $relationshipCount = CRM_Core_DAO
::singleValueQuery($relationshipQuery);
810 if (!empty($relationshipCount)) {
818 * @todo what does this function do?
819 * @param $contactType
820 * @param array $subtypeSet
824 static function getSubtypeCustomPair($contactType, $subtypeSet = array(
826 if (empty($subtypeSet)) {
830 $customSet = $subTypeClause = array();
831 foreach ($subtypeSet as $subtype) {
832 $subtype = CRM_Utils_Type
::escape($subtype, 'String');
833 $subType = CRM_Core_DAO
::VALUE_SEPARATOR
. $subtype . CRM_Core_DAO
::VALUE_SEPARATOR
;
834 $subTypeClause[] = "extends_entity_column_value LIKE '%{$subtype}%' ";
836 $query = "SELECT table_name
837 FROM civicrm_custom_group
838 WHERE extends = %1 AND " . implode(" OR ", $subTypeClause);
839 $dao = CRM_Core_DAO
::executeQuery($query, array(1 => array($contactType, 'String')));
840 while ($dao->fetch()) {
841 $customSet[] = $dao->table_name
;
843 return array_unique($customSet);
847 * Function that does something
848 * @todo what does this function do?
851 * @param $contactType
852 * @param array $oldSubtypeSet
853 * @param array $newSubtypeSet
857 static function deleteCustomSetForSubtypeMigration($contactID,
859 $oldSubtypeSet = array(),
860 $newSubtypeSet = array()
862 $oldCustomSet = self
::getSubtypeCustomPair($contactType, $oldSubtypeSet);
863 $newCustomSet = self
::getSubtypeCustomPair($contactType, $newSubtypeSet);
865 $customToBeRemoved = array_diff($oldCustomSet, $newCustomSet);
866 foreach ($customToBeRemoved as $customTable) {
867 self
::deleteCustomRowsForEntityID($customTable, $contactID);
873 * Delete content / rows of a custom table specific to a subtype for a given custom-group.
874 * This function currently works for contact subtypes only and could be later improved / genralized
875 * to work for other subtypes as well.
877 * @param int $gID - custom group id.
878 * @param array $subtypes - list of subtypes related to which entry is to be removed.
883 public static function deleteCustomRowsOfSubtype($gID, $subtypes = array()) {
884 if (!$gID or empty($subtypes)) {
888 $tableName = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_CustomGroup', $gID, 'table_name');
890 // drop triggers CRM-13587
891 CRM_Core_DAO
::dropTriggers($tableName);
893 $subtypeClause = array();
894 foreach ($subtypes as $subtype) {
895 $subtype = CRM_Utils_Type
::escape($subtype, 'String');
896 $subtypeClause[] = "civicrm_contact.contact_sub_type LIKE '%" . CRM_Core_DAO
::VALUE_SEPARATOR
. $subtype . CRM_Core_DAO
::VALUE_SEPARATOR
. "%'";
898 $subtypeClause = implode(' OR ', $subtypeClause);
900 $query = "DELETE custom.*
901 FROM {$tableName} custom
902 INNER JOIN civicrm_contact ON civicrm_contact.id = custom.entity_id
903 WHERE ($subtypeClause)";
905 CRM_Core_DAO
::singleValueQuery($query);
907 // rebuild triggers CRM-13587
908 CRM_Core_DAO
::triggerRebuild($tableName);
912 * Delete content / rows of a custom table specific entity-id for a given custom-group table.
914 * @param int $customTable - custom table name.
915 * @param int $entityID - entity id.
920 function deleteCustomRowsForEntityID($customTable, $entityID) {
921 $customTable = CRM_Utils_Type
::escape($customTable, 'String');
922 $query = "DELETE FROM {$customTable} WHERE entity_id = %1";
923 return CRM_Core_DAO
::singleValueQuery($query, array(1 => array($entityID, 'Integer')));