PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.5.4
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.5.4
1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk All 48 releases
fluent-cart / app / Services / Filter / LogFilter.php

LogFilter.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.5.4, at app/Services/Filter/LogFilter.php

70 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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