From 6dca8d6fb0c536076588b3ba15ad2ee409bfbcf6 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Wed, 18 May 2016 08:02:06 +0000 Subject: [PATCH] CRM-18559 sync functions from master which seem to resolve this in the same but more elegant way --- CRM/Core/BAO/CustomGroup.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/CRM/Core/BAO/CustomGroup.php b/CRM/Core/BAO/CustomGroup.php index 0b37627f72..6c10622cd5 100644 --- a/CRM/Core/BAO/CustomGroup.php +++ b/CRM/Core/BAO/CustomGroup.php @@ -435,7 +435,7 @@ LEFT JOIN civicrm_custom_field ON (civicrm_custom_field.custom_group_id = civicr foreach ($subTypes as $key => $subType) { // CRM-18559: the value returned from validateSubTypeByEntity does not // include value separators, so they need to be added for the query. - $subTypeClauses[] = "civicrm_custom_group.extends_entity_column_value LIKE '%" . CRM_Core_DAO::VALUE_SEPARATOR . self::validateSubTypeByEntity($entityType, $subType) . CRM_Core_DAO::VALUE_SEPARATOR . "%'"; + $subTypeClauses[] = self::whereListHas("civicrm_custom_group.extends_entity_column_value", self::validateSubTypeByEntity($entityType, $subType)); } $subTypeClause = '(' . implode(' OR ', $subTypeClauses) . ')'; if (!$onlySubType) { @@ -651,6 +651,22 @@ ORDER BY civicrm_custom_group.weight, return $subType; } + /** + * Suppose you have a SQL column, $column, which includes a delimited list, and you want + * a WHERE condition for rows that include $value. Use whereListHas(). + * + * @param string $column + * @param string $value + * @param string $delimiter + * @return string + * SQL condition. + */ + static private function whereListHas($column, $value, $delimiter = CRM_Core_DAO::VALUE_SEPARATOR) { + $bareValue = trim($value, $delimiter); // ? + $escapedValue = CRM_Utils_Type::escape("%{$delimiter}{$bareValue}{$delimiter}%", 'String', FALSE); + return "($column LIKE \"$escapedValue\")"; + } + /** * Check whether the custom group has any data for the given entity. * -- 2.25.1