Commit 0fe65570 authored by Michael McAndrew's avatar Michael McAndrew

first draft adding contact acl to data processor

parent 185cc345
<?php
namespace Civi\DataProcessor\DataFlow\MultipleDataFlows;
class PureSqlStatementJoin implements SqlJoinInterface {
public function __construct($sql) {
$this->sql = $sql;
}
public function getJoinClause(DataFlowDescription $sourceDataFlowDescription) {
return $this->sql;
}
}
......@@ -95,6 +95,7 @@ class Factory {
$this->addDataProcessorType('default', new Definition('Civi\DataProcessor\ProcessorType\DefaultProcessorType'), E::ts('Default'));
$this->addDataSource('activity', new Definition('Civi\DataProcessor\Source\Activity\ActivitySource'), E::ts('Activity'));
$this->addDataSource('contact', new Definition('Civi\DataProcessor\Source\Contact\ContactSource'), E::ts('Contact'));
$this->addDataSource('contact_acl', new Definition('Civi\DataProcessor\Source\Contact\ACLContactSource'), E::ts('Permissioned Contact'));
$this->addDataSource('individual', new Definition('Civi\DataProcessor\Source\Contact\IndividualSource'), E::ts('Individual'));
$this->addDataSource('household', new Definition('Civi\DataProcessor\Source\Contact\HouseholdSource'), E::ts('Household'));
$this->addDataSource('organization', new Definition('Civi\DataProcessor\Source\Contact\OrganizationSource'), E::ts('Organization'));
......
<?php
/**
* @author Jaap Jansma <jaap.jansma@civicoop.org>
* @license AGPL-3.0
*/
namespace Civi\DataProcessor\Source\Contact;
use Civi\DataProcessor\DataFlow\MultipleDataFlows\DataFlowDescription;
use Civi\DataProcessor\DataFlow\MultipleDataFlows\PureSqlStatementJoin;
use Civi\DataProcessor\DataFlow\SqlTableDataFlow;
use Civi\DataProcessor\DataFlow\SqlDataFlow\PureSqlStatementClause;
class ACLContactSource extends ContactSource {
/**
* @var \Civi\DataProcessor\DataFlow\CombinedDataFlow\CombinedSqlDataFlow
*/
protected $dataFlow;
public function initialize() {
$tables = array();
$whereTables = array();
$where = \CRM_ACL_API::whereClause(\CRM_ACL_API::VIEW, $tables, $whereTables, NULL, FALSE, TRUE, FALSE);
foreach ($whereTables as $tableAndAlias => $joinCriteria) {
$this->addAclJoin($tableAndAlias, $joinCriteria);
}
$this->addAclWhere($where);
parent::initialize();
}
/**
* This is a more generalisable path but requires a bit more work before it
* can be accepted into Dataprocessor
* @param String $tableAndAlias
* @param String $joinCriteria
*/
protected function addAclJoin($tableAndAlias, $joinCriteria) {
list($table, $alias) = explode(' ', $tableAndAlias);
$aclTable = new SqlTableDataFlow($table, $alias);
// CiviCRM's ACL hook expects the contact table to be called contact_a.
// In DataProcessor, it might be called something else.
$joinCriteria = str_replace('contact_a', $this->primaryDataFlow->getName(), $joinCriteria);
$join = new PureSqlStatementJoin(' JOIN ' . $tableAndAlias . ' ON ' . $joinCriteria);
$this->additionalDataFlowDescriptions[$tableAndAlias] = new DataFlowDescription($aclTable, $join);
}
protected function addAclWhere($where) {
$where = str_replace('contact_a', $this->primaryDataFlow->getName(), $where);
$clause = new PureSqlStatementClause($where);
$this->primaryDataFlow->addWhereClause($clause);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment