Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev/core/544 Add report support for filter on multiple contact subtypes #13158

Merged
merged 1 commit into from
Mar 28, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions CRM/Report/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -2055,6 +2055,10 @@ public function whereClause(&$field, $op, $value, $min, $max) {
break;
}

//dev/core/544 Add report support for multiple contact subTypes
if ($field['name'] == 'contact_sub_type' && $clause) {
$clause = $this->whereSubtypeClause($field, $value, $op);
}
if (!empty($field['group']) && $clause) {
$clause = $this->whereGroupClause($field, $value, $op);
}
Expand All @@ -2073,6 +2077,27 @@ public function whereClause(&$field, $op, $value, $min, $max) {
return $clause;
}

/**
* Get SQL where clause for contact subtypes
* @param string $field
* @param mixed $value
* @param string $op SQL Operator
*
* @return string
*/
public function whereSubtypeClause($field, $value, $op) {
$clause = '( ';
$subtypeFilters = count($value);
for ($i = 0; $i < $subtypeFilters; $i++) {
$clause .= "{$field['dbAlias']} LIKE '%$value[$i]%'";
if ($i !== ($subtypeFilters - 1)) {
$clause .= " OR ";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eileenmcnaughton will the OR here cause performance issues possibly?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll give it a whirl - but my first instinct here is that we are defining the field metadata incorrectly in some way or this wouldn't be needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eileenmcnaughton I agree as commented in the issue I was surprised to see how this was stored. From my point of view using this function is kind of like "this is the result we're shooting for in terms of output, and if we can get there in another way without causing too much ruckus elsewhere... even better"

@seamuslee001 I didn't notice delay or anything but I also didn't do any real stress test and my dev environment has access to lots of memory, so that's a good point.

}
}
$clause .= ' )';
return $clause;
}

/**
* Get SQL where clause for a date field.
*
Expand Down