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

Relationship data source

parent a0a665ee
No related branches found
No related tags found
No related merge requests found
......@@ -42,7 +42,7 @@ class CRM_Dataprocessor_Form_Source_Relationship extends CRM_Core_Form {
$relationship_types = array(' - select - ') + $this->buildRelationshipTypeSelectList();
$this->add('select', 'relationship_type_id', ts('Relationship Type'), $relationship_types, true, array('class' => 'crm-select2'));
$relationship_type_select = $this->add('select', 'relationship_type_id', ts('Relationship Type'), $relationship_types, true, array('class' => 'crm-select2', 'multiple' => 'multiple'));
$this->addButtons(array(
array('type' => 'next', 'name' => E::ts('Save'), 'isDefault' => TRUE,),
......@@ -58,7 +58,7 @@ class CRM_Dataprocessor_Form_Source_Relationship extends CRM_Core_Form {
$source = CRM_Dataprocessor_BAO_Source::getValues(array('id' => $this->source_id));
if (isset($source[$this->source_id]['configuration']['relationship_type_id'])) {
$defaults['relationship_type_id'] = $source[$this->source_id]['configuration']['relationship_type_id'].".".$source[$this->source_id]['join_configuration']['left_field'];
$defaults['relationship_type_id'] = $source[$this->source_id]['configuration']['relationship_type_id'];
}
return $defaults;
......
......@@ -114,4 +114,18 @@ class CombinedSqlDataFlow extends SqlDataFlow implements MultipleSourceDataFlows
return 'combined_sql_data_flow';
}
public function getWhereClauses() {
foreach($this->whereClauses as $clause) {
$clauses[] = $clause;
}
foreach($this->sourceDataFlowDescriptions as $sourceDataFlowDescription) {
if ($sourceDataFlowDescription->getDataFlow() instanceof SqlDataFlow) {
foreach($sourceDataFlowDescription->getDataFlow()->getWhereClauses() as $clause) {
$clauses[] = $clause;
}
}
}
return $clauses;
}
}
\ No newline at end of file
......@@ -50,6 +50,7 @@ abstract class SqlDataFlow extends AbstractDataFlow {
$from = $this->getFromStatement();
$where = $this->getWhereStatement();
$countSql = "SELECT COUNT(*) {$from} {$where}";
$this->count = \CRM_Core_DAO::singleValueQuery($countSql);
......@@ -68,7 +69,6 @@ abstract class SqlDataFlow extends AbstractDataFlow {
$limitStatement = "LIMIT {$this->offset}, {$calculatedLimit}";
}
$sql .= " {$limitStatement}";
$this->dao = \CRM_Core_DAO::executeQuery($sql);
}
......@@ -145,7 +145,7 @@ abstract class SqlDataFlow extends AbstractDataFlow {
*/
public function getWhereStatement() {
$clauses = array("1");
foreach($this->whereClauses as $clause) {
foreach($this->getWhereClauses() as $clause) {
$clauses[] = $clause->getWhereClause();
}
return "WHERE ". implode(" AND ", $clauses);
......@@ -161,4 +161,13 @@ abstract class SqlDataFlow extends AbstractDataFlow {
return $this;
}
/**
* Return all the where clauses
*
* @return array
*/
public function getWhereClauses() {
return $this->whereClauses;
}
}
\ No newline at end of file
......@@ -20,7 +20,11 @@ class SimpleWhereClause implements WhereClauseInterface {
$this->table_alias = $table_alias;
$this->field = $field;
$this->operator = $operator;
$this->value = \CRM_Utils_Type::escape($value, $valueType);
if (is_array($value)) {
$this->value = "(".implode(", ",\CRM_Utils_Type::escapeAll($value, $valueType)).")";
} else {
$this->value = \CRM_Utils_Type::escape($value, $valueType);
}
}
/**
......
......@@ -41,7 +41,7 @@ class RelationshipSource implements SourceInterface {
new FieldSpecification('contact_id_b', 'Integer', $source_name.'_contact_id_b'),
)));
if (isset($configuration['relationship_type_id'])) {
$this->dataFlow->addWhereClause(new SimpleWhereClause($source_name, 'relationship_type_id', '=', $configuration['relationship_type_id'], 'Integer'));
$this->dataFlow->addWhereClause(new SimpleWhereClause($source_name, 'relationship_type_id', 'IN', $configuration['relationship_type_id'], 'Integer'));
}
return $this;
}
......
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