Skip to content
Snippets Groups Projects
Commit 6f6fc960 authored by jaapjansma's avatar jaapjansma
Browse files

changed simple non required join to accept extra filters

parent 31cf106c
No related branches found
No related tags found
No related merge requests found
......@@ -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}";
......
<?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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment