hook_civicrm_aclWhereClause() for dataprocessor
I have an implementation of hook_civicrm_aclWhereClause()
that
- adds a where clause
- adds a join to a table that is referenced in the where clause
But PermissionToViewContactFilter
isn't adding the join to the query so we're ending up with an error along the lines of
Unknown column 'geodata.local_group' in 'where clause'
Looking at PermissionToViewContactFilter
, I see that ::getAclWhereClause()
does actually retreive values for $tables and $whereTables in a form that could be easily inserted into a query, but I'm not 100% on how I might insert that join statement. From an initial glance over the code, it doesn't look like I can add joins via a filter. My instinct would be to try and add a method to AbstractFilterHandler called something like addJoin
and then call this method in PermissionToViewContactFilter::getAclWhereClause
.
In this case, $whereTables looks something like this
$whereTables = [
"civicrm_value_geo_data geodata" => "geodata.entity_id = contact_a.id"
"civicrm_membership membership" => "membership.contact_id = contact_a.id"
];
So I'm imagining some code along the lines of:
foreach($whereTable => $whereJoinClause in $whereTables){
$this->addJoin(" JOIN {$whereTable} ON {$whereJoinClause} "
}
I've never really been sure why $tables is in hook_civicrm_aclWhereClause()
. It says 'array $tables - (reference ) add the tables that are needed for the select clause' in the docs, which doesn't make any sense to me. In any case, I have ignored it in the code above.
Not sure if this sounds like the right approach to you and/or how easy it would be to add the addJoin method.
Let me know what you think.