if (!empty($subTypes)) {
foreach ($subTypes as $key => $subType) {
- $subTypeClauses[] = "civicrm_custom_group.extends_entity_column_value LIKE '%" . self::validateSubTypeByEntity($entityType, $subType) . "%'";
+ $subTypeClauses[] = self::whereListHas("civicrm_custom_group.extends_entity_column_value", self::validateSubTypeByEntity($entityType, $subType));
}
$subTypeClause = '(' . implode(' OR ', $subTypeClauses) . ')';
if (!$onlySubType) {
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.
*