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

refactor step2 checked filters not tested yet #16

parent 64d5405c
No related branches found
No related tags found
No related merge requests found
......@@ -94,13 +94,13 @@ abstract class AbstractFieldFilterHandler extends AbstractFilterHandler {
*/
public function setFilter($filter) {
$this->resetFilter();
$dataFlow = $this->dataSource->ensureField($this->fieldSpecification);
$dataFlow = $this->dataSource->ensureField($this->inputFieldSpecification);
if ($dataFlow && $dataFlow instanceof SqlDataFlow) {
$value = $filter['value'];
if (!is_array($value)) {
$value = explode(",", $value);
}
$this->whereClause = new SqlDataFlow\SimpleWhereClause($dataFlow->getName(), $this->fieldSpecification->name, $filter['op'], $value, $this->fieldSpecification->type);
$this->whereClause = new SqlDataFlow\SimpleWhereClause($dataFlow->getName(), $this->inputFieldSpecification->name, $filter['op'], $value, $this->inputFieldSpecification->type);
$dataFlow->addWhereClause($this->whereClause);
}
}
......
......@@ -58,12 +58,12 @@ class CaseRoleFilter extends AbstractFieldFilterHandler {
public function setFilter($filter) {
$this->resetFilter();
$dataFlow = $this->dataSource->ensureField($this->fieldSpecification);
$dataFlow = $this->dataSource->ensureField($this->inputFieldSpecification);
$cids = $filter['value'];
if (!is_array($cids)) {
$cids = array($cids);
}
$relationshipTableAlias = 'civicrm_relationship_'.$this->fieldSpecification->alias;
$relationshipTableAlias = 'civicrm_relationship_'.$this->inputFieldSpecification->alias;
$relationshipFilters = array(
new SqlDataFlow\SimpleWhereClause($relationshipTableAlias, 'is_active', '=', '1'),
new SqlDataFlow\SimpleWhereClause($relationshipTableAlias, 'case_id', 'IS NOT NULL', 0),
......@@ -80,7 +80,7 @@ class CaseRoleFilter extends AbstractFieldFilterHandler {
$relationshipTableAlias,
$relationshipFilters,
$dataFlow->getName(),
$this->fieldSpecification->name,
$this->inputFieldSpecification->name,
$filter['op']
);
......
......@@ -49,12 +49,12 @@ class ContactInGroupFilter extends AbstractFieldFilterHandler {
*/
public function setFilter($filter) {
$this->resetFilter();
$dataFlow = $this->dataSource->ensureField($this->fieldSpecification);
$dataFlow = $this->dataSource->ensureField($this->inputFieldSpecification);
$group_ids = $filter['value'];
if (!is_array($group_ids)) {
$group_ids = array($group_ids);
}
$groupTableAlias = 'civicrm_group_contact_'.$this->fieldSpecification->alias;
$groupTableAlias = 'civicrm_group_contact_'.$this->inputFieldSpecification->alias;
$groupFilters = array(
new SqlDataFlow\SimpleWhereClause($groupTableAlias, 'status', '=', 'Added'),
new SqlDataFlow\SimpleWhereClause($groupTableAlias, 'group_id', 'IN', $group_ids),
......@@ -67,7 +67,7 @@ class ContactInGroupFilter extends AbstractFieldFilterHandler {
$groupTableAlias,
$groupFilters,
$dataFlow->getName(),
$this->fieldSpecification->name,
$this->inputFieldSpecification->name,
$filter['op']
);
......
......@@ -33,12 +33,12 @@ class ContactTypeFilter extends AbstractFieldFilterHandler {
*/
public function setFilter($filter) {
$this->resetFilter();
$dataFlow = $this->dataSource->ensureField($this->fieldSpecification);
$dataFlow = $this->dataSource->ensureField($this->inputFieldSpecification);
$contactTypeIds = $filter['value'];
if (!is_array($contactTypeIds)) {
$contactTypeIds = explode(",", $contactTypeIds);
}
$contactTableAlias = 'civicrm_contact_'.$this->fieldSpecification->alias;
$contactTableAlias = 'civicrm_contact_'.$this->inputFieldSpecification->alias;
$contactTypeApiParams['id']['IN'] = $contactTypeIds;
$contactTypeApiParams['options']['limit'] = 0;
$contactTypeApi = civicrm_api3('ContactType', 'get', $contactTypeApiParams);
......@@ -60,7 +60,7 @@ class ContactTypeFilter extends AbstractFieldFilterHandler {
$contactTableAlias,
array($contactTypeClause),
$dataFlow->getName(),
$this->fieldSpecification->name,
$this->inputFieldSpecification->name,
$filter['op']
);
......
......@@ -33,12 +33,12 @@ class ContactWithTagFilter extends AbstractFieldFilterHandler {
*/
public function setFilter($filter) {
$this->resetFilter();
$dataFlow = $this->dataSource->ensureField($this->fieldSpecification);
$dataFlow = $this->dataSource->ensureField($this->inputFieldSpecification);
$tag_ids = $filter['value'];
if (!is_array($tag_ids)) {
$tag_ids = array($tag_ids);
}
$tagTableAlias = 'civicrm_entity_tag_'.$this->fieldSpecification->alias;
$tagTableAlias = 'civicrm_entity_tag_'.$this->inputFieldSpecification->alias;
$tagFilters = array(
new SqlDataFlow\SimpleWhereClause($tagTableAlias, 'entity_table', '=', 'civicrm_contact'),
new SqlDataFlow\SimpleWhereClause($tagTableAlias, 'tag_id', 'IN', $tag_ids),
......@@ -51,7 +51,7 @@ class ContactWithTagFilter extends AbstractFieldFilterHandler {
$tagTableAlias,
$tagFilters,
$dataFlow->getName(),
$this->fieldSpecification->name,
$this->inputFieldSpecification->name,
$filter['op']
);
......
......@@ -57,14 +57,11 @@ class MultipleFieldFilter extends AbstractFilterHandler {
if (!$dataSource) {
throw new DataSourceNotFoundException(E::ts("Filter %1 requires data source '%2' which could not be found. Did you rename or deleted the data source?", array(1=>$this->title, 2=>$datasource_name)));
}
if (!$dataSource->getAvailableFilterFields()->getFieldSpecificationByName($field_name)) {
throw new FieldNotFoundException(E::ts("Filter %1 requires a field with the name '%2' in the data source '%3'. Did you change the data source type?", array(
1 => $this->title,
2 => $field_name,
3 => $datasource_name
)));
$fieldSpecification = $dataSource->getAvailableFilterFields()->getFieldSpecificationByAlias($field_name);
if (!$fieldSpecification) {
$fieldSpecification = $dataSource->getAvailableFilterFields()
->getFieldSpecificationByName($field_name);
}
$fieldSpecification = clone $dataSource->getAvailableFilterFields()->getFieldSpecificationByName($field_name);
if (!$fieldSpecification) {
throw new FieldNotFoundException(E::ts("Filter %1 requires a field with the name '%2' in the data source '%3'. Did you change the data source type?", array(
1 => $this->title,
......@@ -185,7 +182,7 @@ class MultipleFieldFilter extends AbstractFilterHandler {
}
$dataFlow = $dataSource->ensureField($fieldSpec);
if ($dataFlow && $dataFlow instanceof SqlDataFlow) {
$clauses[] = new SqlDataFlow\SimpleWhereClause($dataFlow->getName(), $field_name, $filterParams['op'], $filterParams['value'], $this->fieldSpecification->type);
$clauses[] = new SqlDataFlow\SimpleWhereClause($dataFlow->getName(), $fieldSpec->name, $filterParams['op'], $filterParams['value'], $this->fieldSpecification->type);
}
}
if (count($clauses)) {
......
......@@ -42,9 +42,9 @@ class PermissionToViewContactFilter extends AbstractFieldFilterHandler {
*/
public function setFilter($filter) {
$this->resetFilter();
$dataFlow = $this->dataSource->ensureField($this->fieldSpecification);
$dataFlow = $this->dataSource->ensureField($this->inputFieldSpecification);
$where = $this->getAclWhereClause();
$contactTableAlias = 'civicrm_contact_'.$this->fieldSpecification->alias;
$contactTableAlias = 'civicrm_contact_'.$this->inputFieldSpecification->alias;
$where = str_replace(["`contact_a`.", "contact_a."], "`{$contactTableAlias}`.", $where);
if ($where) {
$contactFilters[] = new SqlDataFlow\PureSqlStatementClause($where);
......@@ -55,7 +55,7 @@ class PermissionToViewContactFilter extends AbstractFieldFilterHandler {
$contactTableAlias,
$contactFilters,
$dataFlow->getName(),
$this->fieldSpecification->name,
$this->inputFieldSpecification->name,
'IN'
);
......
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