| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Services\Filter; |
| 4 |
|
| 5 |
use FluentCart\App\Models\Activity; |
| 6 |
use FluentCart\Framework\Support\Str; |
| 7 |
|
| 8 |
class LogFilter extends BaseFilter |
| 9 |
{ |
| 10 |
|
| 11 |
public function applySimpleFilter(?string $search = null): void |
| 12 |
{ |
| 13 |
$this->query->when($search ?? $this->search, function ($query, $search) { |
| 14 |
return $query |
| 15 |
->where(function ($query) use ($search) { |
| 16 |
$searchOptions = []; |
| 17 |
if (Str::of($search)->contains('#')) { |
| 18 |
$searchableColumns = ['id']; |
| 19 |
$search = Str::of($search)->remove('#')->toString(); |
| 20 |
} else { |
| 21 |
$searchableColumns = ['id', 'title', 'content', 'module_name']; |
| 22 |
} |
| 23 |
|
| 24 |
foreach ($searchableColumns as $index => $column) { |
| 25 |
$searchOptions[$column] = [ |
| 26 |
'column' => $column, |
| 27 |
'operator' => $index === 0 ? 'like_all' : 'or_like_all', |
| 28 |
'value' => $search |
| 29 |
]; |
| 30 |
} |
| 31 |
$query->search($searchOptions); |
| 32 |
}); |
| 33 |
}); |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
public function tabsMap(): array |
| 38 |
{ |
| 39 |
return [ |
| 40 |
'success' => 'status', |
| 41 |
'warning' => 'status', |
| 42 |
'error' => 'status', |
| 43 |
'failed' => 'status', |
| 44 |
'info' => 'status', |
| 45 |
'api' => 'log_type', |
| 46 |
]; |
| 47 |
} |
| 48 |
|
| 49 |
public function getModel(): string |
| 50 |
{ |
| 51 |
return Activity::class; |
| 52 |
} |
| 53 |
|
| 54 |
public static function getFilterName(): string |
| 55 |
{ |
| 56 |
return 'logs'; |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
public function applyActiveViewFilter(?string $activeView = null): void |
| 61 |
{ |
| 62 |
$activeView = $activeView ?? $this->activeView; |
| 63 |
$tabsMap = $this->tabsMap(); |
| 64 |
|
| 65 |
$this->query->when($activeView, function ($query, $activeView) use ($tabsMap) { |
| 66 |
$query->where($tabsMap[$activeView], $activeView); |
| 67 |
}); |
| 68 |
} |
| 69 |
} |
| 70 |
|