| @@ -41,20 +41,23 @@ | ||
| 41 | 41 | $ticketsQuery = Ticket::with($this->args['with']); |
| 42 | 42 | |
| 43 | 43 | if ($this->args['filter_type'] == 'advanced') { |
| 44 | 44 | $filtersGroups = $this->args['filters_groups']; |
| 45 | - foreach ($filtersGroups as $groupIndex => $group) { | |
| 46 | - $method = 'orWhere'; | |
| 47 | - if ($groupIndex == 0) { | |
| 48 | - $method = 'where'; | |
| 45 | + // One closure keeps the OR chain from swallowing the AND-ed agent scopes added later. | |
| 46 | + $ticketsQuery->where(function ($groupsQuery) use ($filtersGroups) { | |
| 47 | + foreach ($filtersGroups as $groupIndex => $group) { | |
| 48 | + $method = 'orWhere'; | |
| 49 | + if ($groupIndex == 0) { | |
| 50 | + $method = 'where'; | |
| 51 | + } | |
| 52 | + $groupsQuery->{$method}(function ($q) use ($group) { | |
| 53 | + foreach ($group as $providerName => $items) { | |
| 54 | + //Call doSearchForAdvancedFilter/filterTicketByUser dynamically from pro | |
| 55 | + do_action_ref_array('fluent_support\tickets_filter_' . $providerName, [&$q, $items]); | |
| 56 | + } | |
| 57 | + }); | |
| 49 | 58 | } |
| 50 | - $ticketsQuery->{$method}(function ($q) use ($group) { | |
| 51 | - foreach ($group as $providerName => $items) { | |
| 52 | - //Call doSearchForAdvancedFilter/filterTicketByUser dynamically from pro | |
| 53 | - do_action_ref_array('fluent_support\tickets_filter_' . $providerName, [&$q, $items]); | |
| 54 | - } | |
| 55 | - }); | |
| 56 | - } | |
| 59 | + }); | |
| 57 | 60 | } else { |
| 58 | 61 | |
| 59 | 62 | if($simpleFilters = $this->args['simple_filters']) { |
| 60 | 63 | $ticketsQuery->applyFilters($simpleFilters); |