// Unit test coverage in api_v3_FinancialTypeACLTest::testGetACLContribution.
$clauses = [];
if ($component === 'contribution') {
- $clauses = CRM_Contribute_BAO_Contribution::getSelectWhereClause();
+ $clauses = array_filter(CRM_Contribute_BAO_Contribution::getSelectWhereClause());
}
if ($component === 'membership') {
- $clauses = CRM_Member_BAO_Membership::getSelectWhereClause();
+ $clauses = array_filter(CRM_Member_BAO_Membership::getSelectWhereClause());
}
if ($clauses) {
$this->_whereClause .= ' AND ' . implode(' AND ', $clauses);
// Prevent infinite recursion
$subquery = $table === static::getTableName() ? NULL : CRM_Utils_SQL::mergeSubquery($ent);
if ($subquery) {
- $relatedClauses[] = "= '$table' AND {{$entityIdField}} " . implode(" AND {{$entityIdField}} ", $subquery);
+ foreach ($subquery as $index => $condition) {
+ // Join OR clauses
+ if (is_array($condition)) {
+ $subquery[$index] = "(({{$entityIdField}} " . implode(") OR ({{$entityIdField}} ", $condition) . '))';
+ }
+ else {
+ $subquery[$index] = "{{$entityIdField}} $condition";
+ }
+ }
+ $relatedClauses[] = "= '$table' AND " . implode(" AND ", $subquery);
}
// If it's the only value with no conditions, don't need to add it
elseif (!$entityTableValues || count($relatedEntities) > 1) {
}
// Arrays of arrays get joined with OR (similar to CRM_Core_Permission::check)
elseif (is_array($formattedClause)) {
- $subClauses[] = "($fieldName " . implode(" OR $fieldName ", $formattedClause) . ')';
+ $subClauses[] = "(($fieldName " . implode(") OR ($fieldName ", $formattedClause) . '))';
}
else {
$subClauses[] = "$fieldName $formattedClause";
$sql .= $join . "\n";
}
if ($this->wheres) {
- $sql .= 'WHERE (' . implode(') AND (', $this->wheres) . ")\n";
+ $sql .= 'WHERE (' . implode(")\n AND (", $this->wheres) . ")\n";
}
if ($this->groupBys) {
$sql .= 'GROUP BY ' . implode(', ', $this->groupBys) . "\n";
}
if ($this->havings) {
- $sql .= 'HAVING (' . implode(') AND (', $this->havings) . ")\n";
+ $sql .= 'HAVING (' . implode(")\n AND (", $this->havings) . ")\n";
}
if ($this->orderBys) {
$orderBys = CRM_Utils_Array::crmArraySortByField($this->orderBys,