diff --git a/Civi/DataProcessor/DataFlow/MultipleDataFlows/SimpleNonRequiredJoin.php b/Civi/DataProcessor/DataFlow/MultipleDataFlows/SimpleNonRequiredJoin.php index 8c0bf86281839ab3d8f7296d2dba8e38d24623eb..ef84eb4e0fde1869b12030df81476adec3c4646b 100644 --- a/Civi/DataProcessor/DataFlow/MultipleDataFlows/SimpleNonRequiredJoin.php +++ b/Civi/DataProcessor/DataFlow/MultipleDataFlows/SimpleNonRequiredJoin.php @@ -11,9 +11,13 @@ use Civi\DataProcessor\DataFlow\CombinedDataFlow\CombinedSqlDataFlow; use Civi\DataProcessor\DataFlow\SqlDataFlow; use Civi\DataProcessor\DataFlow\SqlTableDataFlow; use Civi\DataProcessor\ProcessorType\AbstractProcessorType; +use Civi\DataProcessor\DataFlow\SqlDataFlow\WhereClauseInterface; class SimpleNonRequiredJoin extends SimpleJoin { + /** + * @var WhereClauseInterface[] + */ protected $filterClauses = array(); public function __construct($left_prefix = null, $left_field = null, $right_prefix = null, $right_field = null, $type = "INNER") { @@ -38,6 +42,17 @@ class SimpleNonRequiredJoin extends SimpleJoin { return parent::setConfiguration($configuration); } + + /** + * @param WhereClauseInterface $clause + * + * @return \Civi\DataProcessor\DataFlow\MultipleDataFlows\JoinInterface + */ + public function addFilterClause(WhereClauseInterface $clause) { + $this->filterClauses[] = $clause; + return $this; + } + /** * Returns the SQL join statement * @@ -75,7 +90,11 @@ class SimpleNonRequiredJoin extends SimpleJoin { } } if (count($this->filterClauses)) { - $extraClause = " AND (".implode(" AND ", $this->filterClauses). ")"; + $extraClauses = array(); + foreach($this->filterClauses as $filterClause) { + $extraClauses[] = $filterClause->getWhereClause(); + } + $extraClause = " AND (".implode(" AND ", $extraClauses). ")"; } return "{$this->type} JOIN `{$table}` `{$table_alias}` {$joinClause} {$extraClause}"; diff --git a/Civi/DataProcessor/DataFlow/SqlDataFlow/IsNotNullWhereClause.php b/Civi/DataProcessor/DataFlow/SqlDataFlow/IsNotNullWhereClause.php new file mode 100644 index 0000000000000000000000000000000000000000..9707465465e3fda3c6866892103ea9197c747b4e --- /dev/null +++ b/Civi/DataProcessor/DataFlow/SqlDataFlow/IsNotNullWhereClause.php @@ -0,0 +1,34 @@ +<?php +/** + * @author Jaap Jansma <jaap.jansma@civicoop.org> + * @license AGPL-3.0 + */ + +namespace Civi\DataProcessor\DataFlow\SqlDataFlow; + +class IsNotNullWhereClause implements WhereClauseInterface { + + protected $table_alias; + + protected $field; + + protected $operator; + + protected $value; + + public function __construct($table_alias, $field) { + $this->table_alias = $table_alias; + $this->field = $field; + } + + /** + * Returns the where clause + * E.g. contact_type = 'Individual' + * + * @return string + */ + public function getWhereClause() { + return "`{$this->table_alias}`.`{$this->field}` IS NOT NULL"; + } + +} \ No newline at end of file