Skip to content

Commit 55e2035

Browse files
committed
Patch: Search by any text field looks in both plain text and existent html field
1 parent 0a44087 commit 55e2035

2 files changed

Lines changed: 25 additions & 7 deletions

File tree

src/Controllers/TicketsController.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class TicketsController extends Controller
3434
protected $tickets;
3535
protected $member;
3636
protected $a_search_fields_numeric = ['creator_id', 'user_id', 'status_id', 'priority_id', 'category_id', 'agent_id'];
37-
protected $a_search_fields_text = ['subject', 'html', 'intervention_html'];
37+
protected $a_search_fields_text = ['subject', 'content', 'intervention'];
3838
protected $a_search_fields_date = ['start_date', 'limit_date', 'created_at', 'completed_at', 'updated_at'];
3939

4040
public function __construct(Ticket $tickets, \PanicHDMember $member)
@@ -95,7 +95,21 @@ public function data($ticketList = 'active')
9595
}
9696

9797
}elseif(in_array($field, $this->a_search_fields_text)){
98-
$collection->where($field, 'like', '%' . $value . '%');
98+
if ($field == 'content'){
99+
$collection->where(function($query) use($search_fields, $value){
100+
$query->where('content', 'like', '%' . $value . '%')
101+
->orWhere('html', 'like', '%' . $value . '%');
102+
});
103+
104+
}elseif ($field == 'intervention'){
105+
$collection->where(function($query) use($search_fields, $value){
106+
$query->where('intervention', 'like', '%' . $value . '%')
107+
->orWhere('intervention_html', 'like', '%' . $value . '%');
108+
});
109+
110+
}else{
111+
$collection->where($field, 'like', '%' . $value . '%');
112+
}
99113

100114
}elseif(in_array($field, $this->a_search_fields_numeric)){
101115
$collection->where($field, $value);
@@ -110,7 +124,8 @@ public function data($ticketList = 'active')
110124

111125
if (isset($search_fields['comments'])){
112126
$collection->whereHas('comments', function($q1) use($search_fields){
113-
$q1->where('content', 'like', '%' . $search_fields['comments'] . '%');
127+
$q1->where('content', 'like', '%' . $search_fields['comments'] . '%')
128+
->orWhere('html', 'like', '%' . $search_fields['comments'] . '%');
114129
});
115130
}
116131

@@ -134,15 +149,18 @@ public function data($ticketList = 'active')
134149
if (isset($search_fields['any_text_field'])){
135150
$collection->where(function($query) use($search_fields){
136151
$query->where('subject', 'like', '%' . $search_fields['any_text_field'] . '%')
152+
->orWhere('content', 'like', '%' . $search_fields['any_text_field'] . '%')
137153
->orWhere('html', 'like', '%' . $search_fields['any_text_field'] . '%')
154+
->orWhere('intervention', 'like', '%' . $search_fields['any_text_field'] . '%')
138155
->orWhere('intervention_html', 'like', '%' . $search_fields['any_text_field'] . '%')
139156
->orWhereHas('attachments', function($q1) use($search_fields){
140157
$q1->where('original_filename', 'like', '%' . $search_fields['any_text_field'] . '%')
141158
->orWhere('new_filename', 'like', '%' . $search_fields['any_text_field'] . '%')
142159
->orWhere('description', 'like', '%' . $search_fields['any_text_field'] . '%');
143160
})
144161
->orWhereHas('comments', function($q2) use($search_fields) {
145-
$q2->where('html', 'like', '%' . $search_fields['any_text_field'] . '%')
162+
$q2->where('content', 'like', '%' . $search_fields['any_text_field'] . '%')
163+
->orWhere('html', 'like', '%' . $search_fields['any_text_field'] . '%')
146164
->orWhereHas('attachments', function($q3) use($search_fields){
147165
$q3->where('original_filename', 'like', '%' . $search_fields['any_text_field'] . '%')
148166
->orWhere('new_filename', 'like', '%' . $search_fields['any_text_field'] . '%')

src/Views/tickets/search/form.blade.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,16 +206,16 @@
206206
</div><div class="col-md-6">
207207

208208
<div class="form-group row"><!-- DESCRIPTION -->
209-
<label for="html" class="col-lg-3 col-form-label"> *{{trans('panichd::lang.description')}}{{trans('panichd::lang.colon')}}</label>
209+
<label for="content" class="col-lg-3 col-form-label"> *{{trans('panichd::lang.description')}}{{trans('panichd::lang.colon')}}</label>
210210
<div class="col-lg-9">
211-
<textarea class="form-control" rows="2" name="html" cols="50"></textarea>
211+
<textarea class="form-control" rows="2" name="content" cols="50"></textarea>
212212
</div>
213213
</div>
214214

215215
<div class="form-group row"><!-- INTERVENTION -->
216216
<label for="intervention" class="col-lg-3 col-form-label">{{ trans('panichd::lang.intervention') . trans('panichd::lang.colon') }}</label>
217217
<div class="col-lg-9">
218-
<textarea class="form-control" rows="2" name="intervention_html" cols="50"></textarea>
218+
<textarea class="form-control" rows="2" name="intervention" cols="50"></textarea>
219219
</div>
220220
</div>
221221

0 commit comments

Comments
 (0)