Skip to content
Snippets Groups Projects
Commit 8b179339 authored by jaapjansma's avatar jaapjansma
Browse files

Refactor

parent 4ba08039
No related branches found
No related tags found
No related merge requests found
......@@ -60,6 +60,15 @@ class CombinedSqlDataFlow extends SqlDataFlow implements MultipleSourceDataFlows
$this->sourceDataFlowDescriptions[] = $dataFlowDescription;
}
/**
* Returns the Table part in the from statement.
*
* @return string
*/
public function getTableStatement() {
return "`{$this->primary_table}` `{$this->primary_table_alias}`";
}
/**
* Returns the From Statement.
*
......
......@@ -4,9 +4,8 @@
* @license AGPL-3.0
*/
namespace Civi\DataProcessor\DataFlow\SqlDataFlow;
namespace Civi\DataProcessor\DataFlow\CombinedDataFlow;
use Civi\DataProcessor\DataFlow\CombinedDataFlow\CombinedSqlDataFlow;
use Civi\DataProcessor\DataFlow\EndOfFlowException;
use Civi\DataProcessor\DataSpecification\DataSpecification;
use Civi\DataProcessor\DataSpecification\SqlFieldSpecification;
......@@ -19,6 +18,26 @@ class SubqueryDataFlow extends CombinedSqlDataFlow {
* @return string
*/
public function getFromStatement() {
return "FROM {$this->getTableStatement()}";
}
/**
* Returns the join Statement part.
*
* @param int $skip
* @return string
*/
public function getJoinStatement($skip=0) {
$fromStatements = array();
return $fromStatements;
}
/**
* Returns the Table part in the from statement.
*
* @return string
*/
public function getTableStatement() {
$fields = array();
foreach($this->sourceDataFlowDescriptions as $sourceDataFlowDescription) {
$fields = array_merge($fields, $sourceDataFlowDescription->getDataFlow()->getFieldsForSelectStatement());
......@@ -47,19 +66,7 @@ class SubqueryDataFlow extends CombinedSqlDataFlow {
$from = implode(" ", $fromStatements);
$select = implode(", ", $fields);
return "FROM (SELECT {$select} {$from}) `{$this->getPrimaryTableAlias()}`";
}
/**
* Returns the join Statement part.
*
* @param int $skip
* @return string
*/
public function getJoinStatement($skip=0) {
$fromStatements = array();
$i = 0;
return $fromStatements;
return "(SELECT {$select} {$from}) `{$this->getPrimaryTableAlias()}`";
}
/**
......
......@@ -309,15 +309,11 @@ class SimpleJoin implements JoinInterface, SqlJoinInterface {
}
$joinClause = "ON {$leftColumnName} = {$rightColumnName}";
}
if ($sourceDataFlowDescription->getDataFlow() instanceof SqlTableDataFlow) {
$table = $sourceDataFlowDescription->getDataFlow()->getTable();
$table_alias = $sourceDataFlowDescription->getDataFlow()->getTableAlias();
} elseif ($sourceDataFlowDescription->getDataFlow() instanceof CombinedSqlDataFlow) {
$table = $sourceDataFlowDescription->getDataFlow()->getPrimaryTable();
$table_alias = $sourceDataFlowDescription->getDataFlow()->getPrimaryTableAlias();
if ($sourceDataFlowDescription->getDataFlow() instanceof SqlDataFlow) {
$tablePart = $sourceDataFlowDescription->getDataFlow()->getTableStatement();
}
return "{$this->type} JOIN `{$table}` `{$table_alias}` {$joinClause} ";
return "{$this->type} JOIN {$tablePart} {$joinClause} ";
}
......
......@@ -80,12 +80,8 @@ class SimpleNonRequiredJoin extends SimpleJoin {
}
$joinClause = "ON {$leftColumnName} = {$rightColumnName}";
}
if ($sourceDataFlowDescription->getDataFlow() instanceof SqlTableDataFlow) {
$table = $sourceDataFlowDescription->getDataFlow()->getTable();
$table_alias = $sourceDataFlowDescription->getDataFlow()->getTableAlias();
} elseif ($sourceDataFlowDescription->getDataFlow() instanceof CombinedSqlDataFlow) {
$table = $sourceDataFlowDescription->getDataFlow()->getPrimaryTable();
$table_alias = $sourceDataFlowDescription->getDataFlow()->getPrimaryTableAlias();
if ($sourceDataFlowDescription->getDataFlow() instanceof SqlDataFlow) {
$tablePart = $sourceDataFlowDescription->getDataFlow()->getTableStatement();
}
$extraClause = "";
......@@ -107,7 +103,7 @@ class SimpleNonRequiredJoin extends SimpleJoin {
$extraClause = " AND (".implode(" AND ", $extraClauses). ")";
}
return "{$this->type} JOIN `{$table}` `{$table_alias}` {$joinClause} {$extraClause}";
return "{$this->type} JOIN {$tablePart} {$joinClause} {$extraClause}";
}
......
......@@ -44,12 +44,21 @@ abstract class SqlDataFlow extends AbstractDataFlow {
*/
abstract public function getFieldsForGroupByStatement();
/**
* Returns the Table part in the from statement.
*
* @return string
*/
abstract public function getTableStatement();
/**
* Returns the From Statement.
*
* @return string
*/
abstract public function getFromStatement();
public function getFromStatement() {
return "FROM {$this->getTableStatement()}";
}
/**
* Initialize the data flow
......
......@@ -46,12 +46,12 @@ class SqlTableDataFlow extends SqlDataFlow {
}
/**
* Returns the From Statement.
* Returns the Table part in the from statement.
*
* @return string
*/
public function getFromStatement() {
return "FROM `{$this->table}` `{$this->table_alias}`";
public function getTableStatement() {
return "`{$this->table}` `{$this->table_alias}`";
}
/**
......
......@@ -8,7 +8,7 @@ namespace Civi\DataProcessor\Source\Activity;
use Civi\DataProcessor\DataFlow\MultipleDataFlows\DataFlowDescription;
use Civi\DataProcessor\DataFlow\MultipleDataFlows\SimpleJoin;
use Civi\DataProcessor\DataFlow\SqlDataFlow\SubqueryDataFlow;
use Civi\DataProcessor\DataFlow\CombinedDataFlow\SubqueryDataFlow;
use Civi\DataProcessor\DataFlow\SqlTableDataFlow;
use Civi\DataProcessor\DataSpecification\DataSpecification;
use Civi\DataProcessor\Source\AbstractCivicrmEntitySource;
......
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