Commit 1b3e7d5f authored by jaapjansma's avatar jaapjansma
Browse files

Fixed issue with configuration contact source sub type filter.

parent d72d732a
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
* Added Age field. * Added Age field.
* Added current user to contact filter. * Added current user to contact filter.
* Added data source for permissioned contact (#25). * Added data source for permissioned contact (#25).
* Fixed issue with configuration contact source sub type filter.
# Version 1.3.0 # Version 1.3.0
......
...@@ -8,6 +8,9 @@ namespace Civi\DataProcessor\Source\Contact; ...@@ -8,6 +8,9 @@ namespace Civi\DataProcessor\Source\Contact;
use Civi\DataProcessor\DataFlow\MultipleDataFlows\DataFlowDescription; use Civi\DataProcessor\DataFlow\MultipleDataFlows\DataFlowDescription;
use Civi\DataProcessor\DataFlow\MultipleDataFlows\PureSqlStatementJoin; use Civi\DataProcessor\DataFlow\MultipleDataFlows\PureSqlStatementJoin;
use Civi\DataProcessor\DataFlow\SqlDataFlow\AndClause;
use Civi\DataProcessor\DataFlow\SqlDataFlow\OrClause;
use Civi\DataProcessor\DataFlow\SqlDataFlow\SimpleWhereClause;
use Civi\DataProcessor\DataFlow\SqlTableDataFlow; use Civi\DataProcessor\DataFlow\SqlTableDataFlow;
use Civi\DataProcessor\DataFlow\SqlDataFlow\PureSqlStatementClause; use Civi\DataProcessor\DataFlow\SqlDataFlow\PureSqlStatementClause;
...@@ -53,4 +56,41 @@ class ACLContactSource extends ContactSource { ...@@ -53,4 +56,41 @@ class ACLContactSource extends ContactSource {
$this->primaryDataFlow->addWhereClause($clause); $this->primaryDataFlow->addWhereClause($clause);
} }
/**
* Adds an inidvidual filter to the data source
*
* @param $filter_field_alias
* @param $op
* @param $values
*
* @throws \Exception
*/
protected function addFilter($filter_field_alias, $op, $values) {
if ($filter_field_alias == 'contact_sub_type' && $op == 'IN') {
$contactTypeClauses = [];
foreach ($values as $value) {
$contactTypeSearchName = '%' . \CRM_Core_DAO::VALUE_SEPARATOR . $value . \CRM_Core_DAO::VALUE_SEPARATOR . '%';
$contactTypeClauses[] = new SimpleWhereClause($this->getSourceName(), 'contact_sub_type', 'LIKE', $contactTypeSearchName, 'String', TRUE);
}
if (count($contactTypeClauses)) {
$contactTypeClause = new OrClause($contactTypeClauses);
$entityDataFlow = $this->ensureEntity();
$entityDataFlow->addWhereClause($contactTypeClause);
}
} elseif ($filter_field_alias == 'contact_sub_type' && $op == 'NOT IN') {
$contactTypeClauses = [];
foreach($values as $value) {
$contactTypeSearchName = '%'.\CRM_Core_DAO::VALUE_SEPARATOR.$value.\CRM_Core_DAO::VALUE_SEPARATOR.'%';
$contactTypeClauses[] = new SimpleWhereClause($this->getSourceName(), 'contact_sub_type', 'NOT LIKE', $contactTypeSearchName, 'String',TRUE);
}
if (count($contactTypeClauses)) {
$contactTypeClause = new AndClause($contactTypeClauses);
$entityDataFlow = $this->ensureEntity();
$entityDataFlow->addWhereClause($contactTypeClause);
}
} else {
parent::addFilter($filter_field_alias, $op, $values);
}
}
} }
...@@ -6,6 +6,9 @@ ...@@ -6,6 +6,9 @@
namespace Civi\DataProcessor\Source\Contact; namespace Civi\DataProcessor\Source\Contact;
use Civi\DataProcessor\DataFlow\SqlDataFlow\AndClause;
use Civi\DataProcessor\DataFlow\SqlDataFlow\OrClause;
use Civi\DataProcessor\DataFlow\SqlDataFlow\SimpleWhereClause;
use Civi\DataProcessor\DataSpecification\DataSpecification; use Civi\DataProcessor\DataSpecification\DataSpecification;
use Civi\DataProcessor\Source\AbstractCivicrmEntitySource; use Civi\DataProcessor\Source\AbstractCivicrmEntitySource;
...@@ -60,4 +63,41 @@ class ContactSource extends AbstractCivicrmEntitySource { ...@@ -60,4 +63,41 @@ class ContactSource extends AbstractCivicrmEntitySource {
); );
} }
} /**
\ No newline at end of file * Adds an inidvidual filter to the data source
*
* @param $filter_field_alias
* @param $op
* @param $values
*
* @throws \Exception
*/
protected function addFilter($filter_field_alias, $op, $values) {
if ($filter_field_alias == 'contact_sub_type' && $op == 'IN') {
$contactTypeClauses = [];
foreach ($values as $value) {
$contactTypeSearchName = '%' . \CRM_Core_DAO::VALUE_SEPARATOR . $value . \CRM_Core_DAO::VALUE_SEPARATOR . '%';
$contactTypeClauses[] = new SimpleWhereClause($this->getSourceName(), 'contact_sub_type', 'LIKE', $contactTypeSearchName, 'String', TRUE);
}
if (count($contactTypeClauses)) {
$contactTypeClause = new OrClause($contactTypeClauses);
$entityDataFlow = $this->ensureEntity();
$entityDataFlow->addWhereClause($contactTypeClause);
}
} elseif ($filter_field_alias == 'contact_sub_type' && $op == 'NOT IN') {
$contactTypeClauses = [];
foreach($values as $value) {
$contactTypeSearchName = '%'.\CRM_Core_DAO::VALUE_SEPARATOR.$value.\CRM_Core_DAO::VALUE_SEPARATOR.'%';
$contactTypeClauses[] = new SimpleWhereClause($this->getSourceName(), 'contact_sub_type', 'NOT LIKE', $contactTypeSearchName, 'String',TRUE);
}
if (count($contactTypeClauses)) {
$contactTypeClause = new AndClause($contactTypeClauses);
$entityDataFlow = $this->ensureEntity();
$entityDataFlow->addWhereClause($contactTypeClause);
}
} else {
parent::addFilter($filter_field_alias, $op, $values);
}
}
}
...@@ -6,6 +6,9 @@ ...@@ -6,6 +6,9 @@
namespace Civi\DataProcessor\Source\Contact; namespace Civi\DataProcessor\Source\Contact;
use Civi\DataProcessor\DataFlow\SqlDataFlow\AndClause;
use Civi\DataProcessor\DataFlow\SqlDataFlow\OrClause;
use Civi\DataProcessor\DataFlow\SqlDataFlow\SimpleWhereClause;
use Civi\DataProcessor\DataSpecification\DataSpecification; use Civi\DataProcessor\DataSpecification\DataSpecification;
use Civi\DataProcessor\Source\AbstractCivicrmEntitySource; use Civi\DataProcessor\Source\AbstractCivicrmEntitySource;
...@@ -123,5 +126,42 @@ class HouseholdSource extends AbstractCivicrmEntitySource { ...@@ -123,5 +126,42 @@ class HouseholdSource extends AbstractCivicrmEntitySource {
$this->addFilter('contact_type', '=', 'Household'); $this->addFilter('contact_type', '=', 'Household');
} }
/**
* Adds an inidvidual filter to the data source
*
* @param $filter_field_alias
* @param $op
* @param $values
*
* @throws \Exception
*/
protected function addFilter($filter_field_alias, $op, $values) {
if ($filter_field_alias == 'contact_sub_type' && $op == 'IN') {
$contactTypeClauses = [];
foreach ($values as $value) {
$contactTypeSearchName = '%' . \CRM_Core_DAO::VALUE_SEPARATOR . $value . \CRM_Core_DAO::VALUE_SEPARATOR . '%';
$contactTypeClauses[] = new SimpleWhereClause($this->getSourceName(), 'contact_sub_type', 'LIKE', $contactTypeSearchName, 'String', TRUE);
}
if (count($contactTypeClauses)) {
$contactTypeClause = new OrClause($contactTypeClauses);
$entityDataFlow = $this->ensureEntity();
$entityDataFlow->addWhereClause($contactTypeClause);
}
} elseif ($filter_field_alias == 'contact_sub_type' && $op == 'NOT IN') {
$contactTypeClauses = [];
foreach($values as $value) {
$contactTypeSearchName = '%'.\CRM_Core_DAO::VALUE_SEPARATOR.$value.\CRM_Core_DAO::VALUE_SEPARATOR.'%';
$contactTypeClauses[] = new SimpleWhereClause($this->getSourceName(), 'contact_sub_type', 'NOT LIKE', $contactTypeSearchName, 'String',TRUE);
}
if (count($contactTypeClauses)) {
$contactTypeClause = new AndClause($contactTypeClauses);
$entityDataFlow = $this->ensureEntity();
$entityDataFlow->addWhereClause($contactTypeClause);
}
} else {
parent::addFilter($filter_field_alias, $op, $values);
}
}
} }
...@@ -6,6 +6,9 @@ ...@@ -6,6 +6,9 @@
namespace Civi\DataProcessor\Source\Contact; namespace Civi\DataProcessor\Source\Contact;
use Civi\DataProcessor\DataFlow\SqlDataFlow\AndClause;
use Civi\DataProcessor\DataFlow\SqlDataFlow\OrClause;
use Civi\DataProcessor\DataFlow\SqlDataFlow\SimpleWhereClause;
use Civi\DataProcessor\DataSpecification\DataSpecification; use Civi\DataProcessor\DataSpecification\DataSpecification;
use Civi\DataProcessor\Source\AbstractCivicrmEntitySource; use Civi\DataProcessor\Source\AbstractCivicrmEntitySource;
...@@ -103,5 +106,42 @@ class IndividualSource extends AbstractCivicrmEntitySource { ...@@ -103,5 +106,42 @@ class IndividualSource extends AbstractCivicrmEntitySource {
$this->addFilter('contact_type', '=', 'Individual'); $this->addFilter('contact_type', '=', 'Individual');
} }
/**
* Adds an inidvidual filter to the data source
*
* @param $filter_field_alias
* @param $op
* @param $values
*
* @throws \Exception
*/
protected function addFilter($filter_field_alias, $op, $values) {
if ($filter_field_alias == 'contact_sub_type' && $op == 'IN') {
$contactTypeClauses = [];
foreach ($values as $value) {
$contactTypeSearchName = '%' . \CRM_Core_DAO::VALUE_SEPARATOR . $value . \CRM_Core_DAO::VALUE_SEPARATOR . '%';
$contactTypeClauses[] = new SimpleWhereClause($this->getSourceName(), 'contact_sub_type', 'LIKE', $contactTypeSearchName, 'String', TRUE);
}
if (count($contactTypeClauses)) {
$contactTypeClause = new OrClause($contactTypeClauses);
$entityDataFlow = $this->ensureEntity();
$entityDataFlow->addWhereClause($contactTypeClause);
}
} elseif ($filter_field_alias == 'contact_sub_type' && $op == 'NOT IN') {
$contactTypeClauses = [];
foreach($values as $value) {
$contactTypeSearchName = '%'.\CRM_Core_DAO::VALUE_SEPARATOR.$value.\CRM_Core_DAO::VALUE_SEPARATOR.'%';
$contactTypeClauses[] = new SimpleWhereClause($this->getSourceName(), 'contact_sub_type', 'NOT LIKE', $contactTypeSearchName, 'String',TRUE);
}
if (count($contactTypeClauses)) {
$contactTypeClause = new AndClause($contactTypeClauses);
$entityDataFlow = $this->ensureEntity();
$entityDataFlow->addWhereClause($contactTypeClause);
}
} else {
parent::addFilter($filter_field_alias, $op, $values);
}
}
} }
...@@ -6,6 +6,9 @@ ...@@ -6,6 +6,9 @@
namespace Civi\DataProcessor\Source\Contact; namespace Civi\DataProcessor\Source\Contact;
use Civi\DataProcessor\DataFlow\SqlDataFlow\AndClause;
use Civi\DataProcessor\DataFlow\SqlDataFlow\OrClause;
use Civi\DataProcessor\DataFlow\SqlDataFlow\SimpleWhereClause;
use Civi\DataProcessor\DataSpecification\DataSpecification; use Civi\DataProcessor\DataSpecification\DataSpecification;
use Civi\DataProcessor\Source\AbstractCivicrmEntitySource; use Civi\DataProcessor\Source\AbstractCivicrmEntitySource;
...@@ -115,5 +118,42 @@ class OrganizationSource extends AbstractCivicrmEntitySource { ...@@ -115,5 +118,42 @@ class OrganizationSource extends AbstractCivicrmEntitySource {
$this->addFilter('contact_type', '=', 'Organization'); $this->addFilter('contact_type', '=', 'Organization');
} }
/**
* Adds an inidvidual filter to the data source
*
* @param $filter_field_alias
* @param $op
* @param $values
*
* @throws \Exception
*/
protected function addFilter($filter_field_alias, $op, $values) {
if ($filter_field_alias == 'contact_sub_type' && $op == 'IN') {
$contactTypeClauses = [];
foreach ($values as $value) {
$contactTypeSearchName = '%' . \CRM_Core_DAO::VALUE_SEPARATOR . $value . \CRM_Core_DAO::VALUE_SEPARATOR . '%';
$contactTypeClauses[] = new SimpleWhereClause($this->getSourceName(), 'contact_sub_type', 'LIKE', $contactTypeSearchName, 'String', TRUE);
}
if (count($contactTypeClauses)) {
$contactTypeClause = new OrClause($contactTypeClauses);
$entityDataFlow = $this->ensureEntity();
$entityDataFlow->addWhereClause($contactTypeClause);
}
} elseif ($filter_field_alias == 'contact_sub_type' && $op == 'NOT IN') {
$contactTypeClauses = [];
foreach($values as $value) {
$contactTypeSearchName = '%'.\CRM_Core_DAO::VALUE_SEPARATOR.$value.\CRM_Core_DAO::VALUE_SEPARATOR.'%';
$contactTypeClauses[] = new SimpleWhereClause($this->getSourceName(), 'contact_sub_type', 'NOT LIKE', $contactTypeSearchName, 'String',TRUE);
}
if (count($contactTypeClauses)) {
$contactTypeClause = new AndClause($contactTypeClauses);
$entityDataFlow = $this->ensureEntity();
$entityDataFlow->addWhereClause($contactTypeClause);
}
} else {
parent::addFilter($filter_field_alias, $op, $values);
}
}
} }
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