}
}
+ // Add ACL permission clause generated by the BAO. This is the same clause used by API::get.
+ // TODO: Why only activities?
if (isset($this->_tables['civicrm_activity'])) {
- $bao = new CRM_Activity_BAO_Activity();
- $clauses = $subclauses = [];
- foreach ($bao->addSelectWhereClause() as $field => $vals) {
- if ($vals && $field !== 'id') {
- foreach ($vals as $val) {
- $clauses[] = $bao->tableName() . ".$field " . $val;
- }
- }
- elseif ($vals) {
- $subclauses[] = "$field " . implode(" AND $field ", (array) $vals);
- }
- }
- if ($subclauses) {
- $clauses[] = $bao->tableName() . '.`id` IN (SELECT `id` FROM `' . $bao->tableName() . '` WHERE ' . implode(' AND ', $subclauses) . ')';
- }
- if (!empty($clauses) && $this->_permissionWhereClause) {
- $this->_permissionWhereClause .= ' AND (' . implode(' AND ', $clauses) . ')';
- }
- elseif (!empty($clauses)) {
- $this->_permissionWhereClause .= '(' . implode(' AND ', $clauses) . ')';
+ $clauses = array_filter(CRM_Activity_BAO_Activity::getSelectWhereClause());
+ if ($clauses) {
+ $this->_permissionWhereClause .= ($this->_permissionWhereClause ? ' AND ' : '') . '(' . implode(' AND ', $clauses) . ')';
}
}
}