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);
66 static function isActive($contactType) {
67 $contact = self
::contactTypeInfo(FALSE);
68 $active = array_key_exists($contactType, $contact) ?
TRUE : FALSE;
74 *function to retrieve basic contact type information.
78 * @return array of basic contact types information.
81 static function &basicTypeInfo($all = FALSE) {
82 static $_cache = NULL;
84 if ($_cache === NULL) {
88 $argString = $all ?
'CRM_CT_BTI_1' : 'CRM_CT_BTI_0';
89 if (!array_key_exists($argString, $_cache)) {
90 $cache = CRM_Utils_Cache
::singleton();
91 $_cache[$argString] = $cache->get($argString);
92 if (!$_cache[$argString]) {
95 FROM civicrm_contact_type
96 WHERE parent_id IS NULL
99 $sql .= " AND is_active = 1";
102 $dao = CRM_Core_DAO
::executeQuery($sql,
103 CRM_Core_DAO
::$_nullArray,
105 'CRM_Contact_DAO_ContactType'
107 while ($dao->fetch()) {
109 CRM_Core_DAO
::storeValues($dao, $value);
110 $_cache[$argString][$dao->name
] = $value;
113 $cache->set($argString, $_cache[$argString]);
116 return $_cache[$argString];
121 *function to retrieve all basic contact types.
125 * @return array of basic contact types
128 static function basicTypes($all = FALSE) {
129 return array_keys(self
::basicTypeInfo($all));
138 static function basicTypePairs($all = FALSE, $key = 'name') {
139 $subtypes = self
::basicTypeInfo($all);
142 foreach ($subtypes as $name => $info) {
143 $index = ($key == 'name') ?
$name : $info[$key];
144 $pairs[$index] = $info['label'];
151 *function to retrieve all subtypes Information.
153 * @param array $contactType .
155 * @param bool $ignoreCache
158 * @return array of sub type information
161 static function &subTypeInfo($contactType = NULL, $all = FALSE, $ignoreCache = FALSE, $reset = FALSE) {
162 static $_cache = NULL;
164 if ($reset === TRUE) {
168 if ($_cache === NULL) {
171 if ($contactType && !is_array($contactType)) {
172 $contactType = array($contactType);
175 $argString = $all ?
'CRM_CT_STI_1_' : 'CRM_CT_STI_0_';
176 if (!empty($contactType)) {
177 $argString .= implode('_', $contactType);
180 if ((!array_key_exists($argString, $_cache)) ||
$ignoreCache) {
181 $cache = CRM_Utils_Cache
::singleton();
182 $_cache[$argString] = $cache->get($argString);
183 if (!$_cache[$argString] ||
$ignoreCache) {
184 $_cache[$argString] = array();
187 if (!empty($contactType)) {
188 $ctWHERE = " AND parent.name IN ('" . implode("','", $contactType) . "')";
192 SELECT subtype.*, parent.name as parent, parent.label as parent_label
193 FROM civicrm_contact_type subtype
194 INNER JOIN civicrm_contact_type parent ON subtype.parent_id = parent.id
195 WHERE subtype.name IS NOT NULL AND subtype.parent_id IS NOT NULL {$ctWHERE}
197 if ($all === FALSE) {
198 $sql .= " AND subtype.is_active = 1 AND parent.is_active = 1 ORDER BY parent.id";
200 $dao = CRM_Core_DAO
::executeQuery($sql, array(),
201 FALSE, 'CRM_Contact_DAO_ContactType'
203 while ($dao->fetch()) {
205 CRM_Core_DAO
::storeValues($dao, $value);
206 $value['parent'] = $dao->parent
;
207 $value['parent_label'] = $dao->parent_label
;
208 $_cache[$argString][$dao->name
] = $value;
211 $cache->set($argString, $_cache[$argString]);
214 return $_cache[$argString];
219 *function to retrieve all subtypes
221 * @param array $contactType .
223 * @param string $columnName
224 * @param bool $ignoreCache
226 * @return array of all subtypes OR list of subtypes associated to
227 *a given basic contact type
230 static function subTypes($contactType = NULL, $all = FALSE, $columnName = 'name', $ignoreCache = FALSE) {
231 if ($columnName == 'name') {
232 return array_keys(self
::subTypeInfo($contactType, $all, $ignoreCache));
235 return array_values(self
::subTypePairs($contactType, FALSE, NULL, $ignoreCache));
241 *function to retrieve subtype pairs with name as 'subtype-name' and 'label' as value
243 * @param array $contactType .
245 * @param string $labelPrefix
246 * @param bool $ignoreCache
248 * @return list of subtypes with name as 'subtype-name' and 'label' as value
251 static function subTypePairs($contactType = NULL, $all = FALSE, $labelPrefix = '- ', $ignoreCache = FALSE) {
252 $subtypes = self
::subTypeInfo($contactType, $all, $ignoreCache);
255 foreach ($subtypes as $name => $info) {
256 $pairs[$name] = $labelPrefix . $info['label'];
263 *function to retrieve list of all types i.e basic + subtypes.
267 * @return array of basic types + all subtypes.
270 static function contactTypes($all = FALSE) {
271 return array_keys(self
::contactTypeInfo($all));
276 *function to retrieve info array about all types i.e basic + subtypes.
281 * @return array of basic types + all subtypes.
284 static function contactTypeInfo($all = FALSE, $reset = FALSE) {
285 static $_cache = NULL;
287 if ($reset === TRUE) {
291 if ($_cache === NULL) {
295 $argString = $all ?
'CRM_CT_CTI_1' : 'CRM_CT_CTI_0';
296 if (!array_key_exists($argString, $_cache)) {
297 $cache = CRM_Utils_Cache
::singleton();
298 $_cache[$argString] = $cache->get($argString);
299 if (!$_cache[$argString]) {
300 $_cache[$argString] = array();
303 SELECT type.*, parent.name as parent, parent.label as parent_label
304 FROM civicrm_contact_type type
305 LEFT JOIN civicrm_contact_type parent ON type.parent_id = parent.id
306 WHERE type.name IS NOT NULL
308 if ($all === FALSE) {
309 $sql .= " AND type.is_active = 1";
312 $dao = CRM_Core_DAO
::executeQuery($sql,
313 CRM_Core_DAO
::$_nullArray,
315 'CRM_Contact_DAO_ContactType'
317 while ($dao->fetch()) {
319 CRM_Core_DAO
::storeValues($dao, $value);
320 if (array_key_exists('parent_id', $value)) {
321 $value['parent'] = $dao->parent
;
322 $value['parent_label'] = $dao->parent_label
;
324 $_cache[$argString][$dao->name
] = $value;
327 $cache->set($argString, $_cache[$argString]);
331 return $_cache[$argString];
336 *function to retrieve basic type pairs with name as 'built-in name' and 'label' as value
339 * @param null $typeName
340 * @param null $delimiter
342 * @internal param array $contactType .
343 * @return list of basictypes with name as 'built-in name' and 'label' as value
346 static function contactTypePairs($all = FALSE, $typeName = NULL, $delimiter = NULL) {
347 $types = self
::contactTypeInfo($all);
349 if ($typeName && !is_array($typeName)) {
350 $typeName = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, trim($typeName, CRM_Core_DAO
::VALUE_SEPARATOR
));
355 foreach ($typeName as $type) {
356 if (array_key_exists($type, $types)) {
357 $pairs[$type] = $types[$type]['label'];
362 foreach ($types as $name => $info) {
363 $pairs[$name] = $info['label'];
367 return !$delimiter ?
$pairs : implode($delimiter, $pairs);
371 * Get a list of elements for select box
372 * Note that this used to default to using the hex(01) character - which results in an invalid character being used in form fields
373 * which was not handled well be anything that loaded & resaved the html (outside core)
374 * The use of this separator is now explicit in the calling functions as a step towards it's removal
377 * @param bool $isSeparator
378 * @param string $separator
382 static function getSelectElements($all = FALSE,
386 static $_cache = NULL;
388 if ($_cache === NULL) {
392 $argString = $all ?
'CRM_CT_GSE_1' : 'CRM_CT_GSE_0';
393 $argString .= $isSeparator ?
'_1' : '_0';
394 if (!array_key_exists($argString, $_cache)) {
395 $cache = CRM_Utils_Cache
::singleton();
396 $_cache[$argString] = $cache->get($argString);
398 if (!$_cache[$argString]) {
399 $_cache[$argString] = array();
402 SELECT c.name as child_name , c.label as child_label , c.id as child_id,
403 p.name as parent_name, p.label as parent_label, p.id as parent_id
404 FROM civicrm_contact_type c
405 LEFT JOIN civicrm_contact_type p ON ( c.parent_id = p.id )
406 WHERE ( c.name IS NOT NULL )
409 if ($all === FALSE) {
412 AND ( p.is_active = 1 OR p.id IS NULL )
415 $sql .= " ORDER BY c.id";
418 $dao = CRM_Core_DAO
::executeQuery($sql);
419 while ($dao->fetch()) {
420 if (!empty($dao->parent_id
)) {
421 $key = $isSeparator ?
$dao->parent_name
. $separator . $dao->child_name
: $dao->child_name
;
422 $label = "- {$dao->child_label}";
423 $pName = $dao->parent_name
;
426 $key = $dao->child_name
;
427 $label = $dao->child_label
;
428 $pName = $dao->child_name
;
431 if (!isset($values[$pName])) {
432 $values[$pName] = array();
434 $values[$pName][] = array('key' => $key, 'label' => $label);
437 $selectElements = array();
438 foreach ($values as $pName => $elements) {
439 foreach ($elements as $element) {
440 $selectElements[$element['key']] = $element['label'];
443 $_cache[$argString] = $selectElements;
445 $cache->set($argString, $_cache[$argString]);
448 return $_cache[$argString];
452 * function to check if a given type is a subtype
454 * @param string $subType contact subType.
455 * @param bool $ignoreCache
457 * @return boolean true if subType, false otherwise.
460 static function isaSubType($subType, $ignoreCache = FALSE) {
461 return in_array($subType, self
::subTypes(NULL, TRUE, 'name', $ignoreCache));
465 *function to retrieve the basic contact type associated with
468 *@param array/string $subType contact subType.
469 *@return array/string of basicTypes.
473 static function getBasicType($subType) {
474 static $_cache = NULL;
475 if ($_cache === NULL) {
480 if ($subType && !is_array($subType)) {
481 $subType = array($subType);
484 $argString = implode('_', $subType);
486 if (!array_key_exists($argString, $_cache)) {
487 $_cache[$argString] = array();
490 SELECT subtype.name as contact_subtype, type.name as contact_type
491 FROM civicrm_contact_type subtype
492 INNER JOIN civicrm_contact_type type ON ( subtype.parent_id = type.id )
493 WHERE subtype.name IN ('" . implode("','", $subType) . "' )";
494 $dao = CRM_Core_DAO
::executeQuery($sql);
495 while ($dao->fetch()) {
497 $_cache[$argString] = $dao->contact_type
;
500 $_cache[$argString][$dao->contact_subtype
] = $dao->contact_type
;
503 return $_cache[$argString];
508 *function to suppress all subtypes present in given array.
511 * @param bool $ignoreCache
513 * @internal param array $subType contact subType.
514 * @return array of suppresssubTypes .
517 static function suppressSubTypes(&$subTypes, $ignoreCache = FALSE) {
518 $subTypes = array_diff($subTypes, self
::subTypes(NULL, TRUE, 'name', $ignoreCache));
524 *function to verify if a given subtype is associated with a given basic contact type.
526 * @param string $subType contact subType
527 * @param string $contactType contact Type
528 * @param bool $ignoreCache
529 * @param string $columnName
531 * @return boolean true if contact extends, false otherwise.
534 static function isExtendsContactType($subType, $contactType, $ignoreCache = FALSE, $columnName = 'name') {
535 if (!is_array($subType)) {
536 $subType = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, trim($subType, CRM_Core_DAO
::VALUE_SEPARATOR
));
538 $subtypeList = self
::subTypes($contactType, TRUE, $columnName, $ignoreCache);
539 $intersection = array_intersect($subType, $subtypeList);
540 return $subType == $intersection;
545 *function to create shortcuts menu for contactTypes
547 *@return array of contactTypes
551 static function getCreateNewList() {
552 $shortCuts = array();
553 //@todo FIXME - using the CRM_Core_DAO::VALUE_SEPARATOR creates invalid html - if you can find the form
554 // this is loaded onto then replace with something like '__' & test
555 $separator = CRM_Core_DAO
::VALUE_SEPARATOR
;
556 $contactTypes = self
::getSelectElements(FALSE, TRUE, $separator);
557 foreach ($contactTypes as $key => $value) {
559 $typeValue = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $key);
560 $cType = CRM_Utils_Array
::value('0', $typeValue);
561 $typeUrl = 'ct=' . $cType;
562 if ($csType = CRM_Utils_Array
::value('1', $typeValue)) {
563 $typeUrl .= "&cst=$csType";
566 'path' => 'civicrm/contact/add',
567 'query' => "$typeUrl&reset=1",
568 'ref' => "new-$value",
571 if ($csType = CRM_Utils_Array
::value('1', $typeValue)) {
572 $shortCuts[$cType]['shortCuts'][] = $shortCut;
575 $shortCuts[$cType] = $shortCut;
583 * Function to delete Contact SubTypes
585 * @param int $contactTypeId ID of the Contact Subtype to be deleted.
591 static function del($contactTypeId) {
593 if (!$contactTypeId) {
597 $params = array('id' => $contactTypeId);
598 self
::retrieve($params, $typeInfo);
599 $name = $typeInfo['name'];
600 // check if any custom group
601 $custom = new CRM_Core_DAO_CustomGroup();
602 $custom->whereAdd("extends_entity_column_value LIKE '%" .
603 CRM_Core_DAO
::VALUE_SEPARATOR
.
605 CRM_Core_DAO
::VALUE_SEPARATOR
. "%'"
607 if ($custom->find()) {
611 // remove subtype for existing contacts
613 UPDATE civicrm_contact SET contact_sub_type = NULL
614 WHERE contact_sub_type = '$name'";
615 CRM_Core_DAO
::executeQuery($sql);
617 // remove subtype from contact type table
618 $contactType = new CRM_Contact_DAO_ContactType();
619 $contactType->id
= $contactTypeId;
620 $contactType->delete();
622 // remove navigation entry if any
626 FROM civicrm_navigation
628 $params = array(1 => array("New $name", 'String'));
629 $dao = CRM_Core_DAO
::executeQuery($sql, $params);
630 CRM_Core_BAO_Navigation
::resetNavigation();
636 * Function to add or update Contact SubTypes
638 * @param array $params an assoc array of name/value pairs
644 static function add($params) {
647 if (empty($params['label'])) {
650 if (!empty($params['parent_id']) &&
651 !CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_ContactType', $params['parent_id'])
656 $contactType = new CRM_Contact_DAO_ContactType();
657 $contactType->copyValues($params);
658 $contactType->id
= CRM_Utils_Array
::value('id', $params);
659 $contactType->is_active
= CRM_Utils_Array
::value('is_active', $params, 0);
661 $contactType->save();
662 if ($contactType->find(TRUE)) {
663 $contactName = $contactType->name
;
664 $contact = ucfirst($contactType->label
);
665 $active = $contactType->is_active
;
668 if (!empty($params['id'])) {
669 $params = array('name' => "New $contactName");
671 'label' => "New $contact",
672 'is_active' => $active,
674 CRM_Core_BAO_Navigation
::processUpdate($params, $newParams);
677 $name = self
::getBasicType($contactName);
681 $value = array('name' => "New $name");
682 CRM_Core_BAO_Navigation
::retrieve($value, $navinfo);
684 'label' => "New $contact",
685 'name' => "New $contactName",
686 'url' => "civicrm/contact/add?ct=$name&cst=$contactName&reset=1",
687 'permission' => 'add contacts',
688 'parent_id' => $navinfo['id'],
689 'is_active' => $active,
691 CRM_Core_BAO_Navigation
::add($navigation);
693 CRM_Core_BAO_Navigation
::resetNavigation();
695 // reset the cache after adding
696 self
::subTypeInfo(NULL, FALSE, FALSE, TRUE);
702 * update the is_active flag in the db
704 * @param int $id id of the database record
705 * @param boolean $is_active value we want to set the is_active field
707 * @return Object DAO object on success, null otherwise
710 static function setIsActive($id, $is_active) {
711 $params = array('id' => $id);
712 self
::retrieve($params, $contactinfo);
713 $params = array('name' => "New $contactinfo[name]");
714 $newParams = array('is_active' => $is_active);
715 CRM_Core_BAO_Navigation
::processUpdate($params, $newParams);
716 CRM_Core_BAO_Navigation
::resetNavigation();
717 return CRM_Core_DAO
::setFieldValue('CRM_Contact_DAO_ContactType', $id,
718 'is_active', $is_active
727 static function getLabel($typeName) {
728 $types = self
::contactTypeInfo(TRUE);
730 if (array_key_exists($typeName, $types)) {
731 return $types[$typeName]['label'];
737 * Function to check whether allow to change any contact's subtype
738 * on the basis of custom data and relationship of specific subtype
739 * currently used in contact/edit form amd in import validation
741 * @param int $contactId contact id.
742 * @param string $subType subtype.
744 * @return boolean true/false.
747 static function isAllowEdit($contactId, $subType = NULL) {
753 if (empty($subType)) {
754 $subType = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact',
760 if (self
::hasCustomData($subType, $contactId) || self
::hasRelationships($contactId, $subType)) {
768 * @param $contactType
769 * @param null $contactId
773 static function hasCustomData($contactType, $contactId = NULL) {
776 if (self
::isaSubType($contactType)) {
777 $subType = $contactType;
778 $contactType = self
::getBasicType($subType);
780 // check for empty custom data which extends subtype
781 $subTypeValue = CRM_Core_DAO
::VALUE_SEPARATOR
. $subType . CRM_Core_DAO
::VALUE_SEPARATOR
;
782 $subTypeClause = " AND extends_entity_column_value LIKE '%{$subTypeValue}%' ";
784 $query = "SELECT table_name FROM civicrm_custom_group WHERE extends = '{$contactType}' {$subTypeClause}";
786 $dao = CRM_Core_DAO
::executeQuery($query);
787 while ($dao->fetch()) {
788 $sql = "SELECT count(id) FROM {$dao->table_name}";
790 $sql .= " WHERE entity_id = {$contactId}";
794 $customDataCount = CRM_Core_DAO
::singleValueQuery($sql);
795 if (!empty($customDataCount)) {
804 * @todo what does this function do?
806 * @param $contactType
810 static function hasRelationships($contactId, $contactType) {
811 $subTypeClause = NULL;
812 if (self
::isaSubType($contactType)) {
813 $subType = $contactType;
814 $contactType = self
::getBasicType($subType);
815 $subTypeClause = " AND ( ( crt.contact_type_a = '{$contactType}' AND crt.contact_sub_type_a = '{$subType}') OR
816 ( crt.contact_type_b = '{$contactType}' AND crt.contact_sub_type_b = '{$subType}') ) ";
819 $subTypeClause = " AND ( crt.contact_type_a = '{$contactType}' OR crt.contact_type_b = '{$contactType}' ) ";
822 // check relationships for
823 $relationshipQuery = "
824 SELECT count(cr.id) FROM civicrm_relationship cr
825 INNER JOIN civicrm_relationship_type crt ON
826 ( cr.relationship_type_id = crt.id {$subTypeClause} )
827 WHERE ( cr.contact_id_a = {$contactId} OR cr.contact_id_b = {$contactId} )
830 $relationshipCount = CRM_Core_DAO
::singleValueQuery($relationshipQuery);
832 if (!empty($relationshipCount)) {
840 * @todo what does this function do?
841 * @param $contactType
842 * @param array $subtypeSet
846 static function getSubtypeCustomPair($contactType, $subtypeSet = array(
848 if (empty($subtypeSet)) {
852 $customSet = $subTypeClause = array();
853 foreach ($subtypeSet as $subtype) {
854 $subtype = CRM_Utils_Type
::escape($subtype, 'String');
855 $subType = CRM_Core_DAO
::VALUE_SEPARATOR
. $subtype . CRM_Core_DAO
::VALUE_SEPARATOR
;
856 $subTypeClause[] = "extends_entity_column_value LIKE '%{$subtype}%' ";
858 $query = "SELECT table_name
859 FROM civicrm_custom_group
860 WHERE extends = %1 AND " . implode(" OR ", $subTypeClause);
861 $dao = CRM_Core_DAO
::executeQuery($query, array(1 => array($contactType, 'String')));
862 while ($dao->fetch()) {
863 $customSet[] = $dao->table_name
;
865 return array_unique($customSet);
869 * Function that does something
870 * @todo what does this function do?
873 * @param $contactType
874 * @param array $oldSubtypeSet
875 * @param array $newSubtypeSet
879 static function deleteCustomSetForSubtypeMigration($contactID,
881 $oldSubtypeSet = array(),
882 $newSubtypeSet = array()
884 $oldCustomSet = self
::getSubtypeCustomPair($contactType, $oldSubtypeSet);
885 $newCustomSet = self
::getSubtypeCustomPair($contactType, $newSubtypeSet);
887 $customToBeRemoved = array_diff($oldCustomSet, $newCustomSet);
888 foreach ($customToBeRemoved as $customTable) {
889 self
::deleteCustomRowsForEntityID($customTable, $contactID);
895 * Delete content / rows of a custom table specific to a subtype for a given custom-group.
896 * This function currently works for contact subtypes only and could be later improved / genralized
897 * to work for other subtypes as well.
899 * @param int $gID - custom group id.
900 * @param array $subtypes - list of subtypes related to which entry is to be removed.
905 public static function deleteCustomRowsOfSubtype($gID, $subtypes = array()) {
906 if (!$gID or empty($subtypes)) {
910 $tableName = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_CustomGroup', $gID, 'table_name');
912 // drop triggers CRM-13587
913 CRM_Core_DAO
::dropTriggers($tableName);
915 $subtypeClause = array();
916 foreach ($subtypes as $subtype) {
917 $subtype = CRM_Utils_Type
::escape($subtype, 'String');
918 $subtypeClause[] = "civicrm_contact.contact_sub_type LIKE '%" . CRM_Core_DAO
::VALUE_SEPARATOR
. $subtype . CRM_Core_DAO
::VALUE_SEPARATOR
. "%'";
920 $subtypeClause = implode(' OR ', $subtypeClause);
922 $query = "DELETE custom.*
923 FROM {$tableName} custom
924 INNER JOIN civicrm_contact ON civicrm_contact.id = custom.entity_id
925 WHERE ($subtypeClause)";
927 CRM_Core_DAO
::singleValueQuery($query);
929 // rebuild triggers CRM-13587
930 CRM_Core_DAO
::triggerRebuild($tableName);
934 * Delete content / rows of a custom table specific entity-id for a given custom-group table.
936 * @param int $customTable - custom table name.
937 * @param int $entityID - entity id.
942 function deleteCustomRowsForEntityID($customTable, $entityID) {
943 $customTable = CRM_Utils_Type
::escape($customTable, 'String');
944 $query = "DELETE FROM {$customTable} WHERE entity_id = %1";
945 return CRM_Core_DAO
::singleValueQuery($query, array(1 => array($entityID, 'Integer')));