PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 2.4.5
Fluent Support – Helpdesk & Customer Support Ticket System v2.4.5
2.4.5 2.4.0 2.3.2 2.3.1 2.3.0 2.2.1 2.2.0 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.4.0 1.4.1 1.4.2 1.4.5 1.4.6 1.4.7 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 All 69 releases
← All changes | app/Services/TicketQueryService.php +29 -16 1.5.4 → 2.4.5 View file →
@@ -27,10 +27,14 @@
27 27 ]);
28 28 $this->setupQuery();
29 29 }
30 30
31 + /**
32 + *setupQuery method will prepare query to get the tickets based on the selected filter options
33 + */
31 34 private function setupQuery()
32 35 {
36 + //If filter conditions added in advanced filtering
33 37 if ($this->args['filters_groups_raw']) {
34 38 $this->formatAdvancedFilters();
35 39 }
36 40
@@ -37,19 +41,23 @@
37 41 $ticketsQuery = Ticket::with($this->args['with']);
38 42
39 43 if ($this->args['filter_type'] == 'advanced') {
40 44 $filtersGroups = $this->args['filters_groups'];
41 - foreach ($filtersGroups as $groupIndex => $group) {
42 - $method = 'orWhere';
43 - if ($groupIndex == 0) {
44 - $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 + });
45 58 }
46 - $ticketsQuery->{$method}(function ($q) use ($group) {
47 - foreach ($group as $providerName => $items) {
48 - do_action_ref_array('fluent_support\tickets_filter_' . $providerName, [&$q, $items]);
49 - }
50 - });
51 - }
59 + });
52 60 } else {
53 61
54 62 if($simpleFilters = $this->args['simple_filters']) {
55 63 $ticketsQuery->applyFilters($simpleFilters);
@@ -63,10 +71,10 @@
63 71 $ticketsQuery->searchBy($search);
64 72 }
65 73 }
66 74
67 - $ticketsQuery->orderBy($this->args['sort_by'], $this->args['sort_type']);
68 -
75 + $ticketsQuery->orderBy(sanitize_sql_orderby($this->args['sort_by']), sanitize_sql_orderby($this->args['sort_type']));
76 + do_action_ref_array('fluent_support\main_tickets_query', [&$ticketsQuery, $this->args]);
69 77 $this->model = $ticketsQuery;
70 78 }
71 79
72 80 public function paginate()
@@ -92,28 +100,33 @@
92 100 {
93 101 return $this->model;
94 102 }
95 103
104 + /**
105 + *formatAdvancedFilters method will format the requested variable for advanced filtering
106 + */
96 107 private function formatAdvancedFilters()
97 108 {
98 109 $filters = $this->args['filters_groups_raw'];
99 110
100 111 $groups = [];
101 -
112 + //$filterGroup mean all items under And, OR
102 113 foreach ($filters as $filterGroup) {
103 114 $group = [];
115 + //$filterItem is individual item under a group(And/OR)
104 116 foreach ($filterGroup as $filterItem) {
105 - if (count($filterItem['source']) != 2 || empty($filterItem['source'][0]) || empty($filterItem['source'][1]) || empty($filterItem['operator'])) {
117 + $source = $filterItem['source'] ?? [];
118 + if (!is_array($source) || count($source) != 2 || empty($source[0]) || empty($source[1]) || empty($filterItem['operator'])) {
106 119 continue;
107 120 }
108 121
109 - $provider = $filterItem['source'][0];
122 + $provider = $source[0];
110 123
111 124 if (!isset($group[$provider])) {
112 125 $group[$provider] = [];
113 126 }
114 127
115 - $property = $filterItem['source'][1];
128 + $property = $source[1];
116 129
117 130 $group[$provider][] = [
118 131 'property' => $property,
119 132 'operator' => $filterItem['operator'],