PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.5.0
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.5.0
1.6.6 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 All 49 releases
fluent-cart / app / Services / Filter / LicenseSiteFilter.php

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

167 lines 6.1 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 FluentCartPro\App\Modules\Licensing\Models\LicenseSite;
6
7 class LicenseSiteFilter extends BaseFilter
8 {
9 public function getModel(): string
10 {
11 return LicenseSite::class;
12 }
13
14 public static function getFilterName(): string
15 {
16 return 'license_sites';
17 }
18
19 public function tabsMap(): array
20 {
21 return [];
22 }
23
24 public function applySimpleFilter(?string $search = null): void
25 {
26 $isApplied = $this->applySimpleOperatorFilter($search);
27 if ($isApplied) {
28 return;
29 }
30
31 $this->query->when($search ?? $this->search, function ($query, $search) {
32 $search = is_array($search) ? implode(' ', $search) : $search;
33
34 if (empty($search)) {
35 return $query;
36 }
37
38 $query->where('site_url', 'like', '%' . $search . '%');
39
40 return $query;
41 });
42 }
43
44 public function applyActiveViewFilter(?string $activeView = null): void
45 {
46 // No tab-based filtering for sites
47 }
48
49 public function customQuery()
50 {
51 return $this->query
52 ->withCount(['activations as active_licenses_count' => function ($q) {
53 $q->where('status', 'active');
54 }])
55 ->whereHas('activations');
56 }
57
58 public static function getSearchableFields(): array
59 {
60 return [
61 'url' => [
62 'column' => 'site_url',
63 'description' => 'site_url',
64 'type' => 'string'
65 ]
66 ];
67 }
68
69 public static function advanceFilterOptions(): array
70 {
71 return [
72 'site' => [
73 'label' => __('Site Property', 'fluent-cart'),
74 'value' => 'site',
75 'children' => [
76 [
77 'label' => __('Site URL', 'fluent-cart'),
78 'value' => 'site_url',
79 'type' => 'text',
80 'filter_type' => 'column',
81 'column' => 'site_url',
82 ],
83 [
84 'label' => __('Platform Version', 'fluent-cart'),
85 'value' => 'platform_version',
86 'type' => 'text',
87 'filter_type' => 'column',
88 'column' => 'platform_version',
89 ],
90 [
91 'label' => __('Server Version', 'fluent-cart'),
92 'value' => 'server_version',
93 'type' => 'text',
94 'filter_type' => 'column',
95 'column' => 'server_version',
96 ],
97 [
98 'label' => __('Registered Date', 'fluent-cart'),
99 'value' => 'created_at',
100 'type' => 'dates',
101 'filter_type' => 'date',
102 'column' => 'created_at',
103 ],
104 ],
105 ],
106 'product' => [
107 'label' => __('Product', 'fluent-cart'),
108 'value' => 'product',
109 'children' => [
110 [
111 'label' => __('By Products', 'fluent-cart'),
112 'value' => 'product',
113 'type' => 'remote_tree_select',
114 'filter_type' => 'custom',
115 'remote_data_key' => 'product_variations',
116 'limit' => 10,
117 'callback' => function ($query, $data) {
118 $variationIds = (array)$data['value'];
119 $query->whereHas('activations', function ($q) use ($variationIds) {
120 $q->whereHas('license', function ($lq) use ($variationIds) {
121 $lq->whereIn('variation_id', $variationIds);
122 });
123 });
124 }
125 ],
126 ],
127 ],
128 'license' => [
129 'label' => __('License Property', 'fluent-cart'),
130 'value' => 'license',
131 'children' => [
132 [
133 'label' => __('Activation Status', 'fluent-cart'),
134 'value' => 'activation_status',
135 'type' => 'selections',
136 'filter_type' => 'custom',
137 'options' => [
138 'active' => __('Active', 'fluent-cart'),
139 'inactive' => __('Inactive', 'fluent-cart'),
140 ],
141 'is_multiple' => true,
142 'is_only_in' => true,
143 'callback' => function ($query, $data) {
144 $query->whereHas('activations', function ($q) use ($data) {
145 $q->whereIn('status', (array)$data['value']);
146 });
147 }
148 ],
149 [
150 'label' => __('Active License Count', 'fluent-cart'),
151 'value' => 'active_license_count',
152 'type' => 'numeric',
153 'filter_type' => 'custom',
154 'callback' => function ($query, $data) {
155 $operator = isset($data['operator']) ? $data['operator'] : '=';
156 $value = intval($data['value']);
157 $query->whereHas('activations', function ($q) {
158 $q->where('status', 'active');
159 }, $operator, $value);
160 }
161 ],
162 ],
163 ],
164 ];
165 }
166 }
167