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

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

190 lines 6.8 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 /**
20 * @return array<string, array<string, mixed>>
21 */
22 protected static function sortableColumns(): array
23 {
24 return [
25 'site_url' => ['label' => __('Site URL', 'fluent-cart'), 'column' => 'site_url'],
26 'created_at' => ['label' => __('Created At', 'fluent-cart'), 'column' => 'created_at'],
27 ];
28 }
29
30 /**
31 * Intentionally empty, and verified so: LicenseSiteTable.js sends no `with`
32 * at all. In particular `LicenseSite::activations()` must stay denied — it
33 * walks back to the licence keys this list deliberately does not show.
34 *
35 * @return array<string, callable>
36 */
37 protected function allowedWiths(): array
38 {
39 return [];
40 }
41
42 public function tabsMap(): array
43 {
44 return [];
45 }
46
47 public function applySimpleFilter(?string $search = null): void
48 {
49 $isApplied = $this->applySimpleOperatorFilter($search);
50 if ($isApplied) {
51 return;
52 }
53
54 $this->query->when($search ?? $this->search, function ($query, $search) {
55 $search = is_array($search) ? implode(' ', $search) : $search;
56
57 if (empty($search)) {
58 return $query;
59 }
60
61 $query->where('site_url', 'like', '%' . $search . '%');
62
63 return $query;
64 });
65 }
66
67 public function applyActiveViewFilter(?string $activeView = null): void
68 {
69 // No tab-based filtering for sites
70 }
71
72 public function customQuery()
73 {
74 return $this->query
75 ->withCount(['activations as active_licenses_count' => function ($q) {
76 $q->where('status', 'active');
77 }])
78 ->whereHas('activations');
79 }
80
81 public static function getSearchableFields(): array
82 {
83 return [
84 'url' => [
85 'column' => 'site_url',
86 'description' => 'site_url',
87 'type' => 'string'
88 ]
89 ];
90 }
91
92 public static function advanceFilterOptions(): array
93 {
94 return [
95 'site' => [
96 'label' => __('Site Property', 'fluent-cart'),
97 'value' => 'site',
98 'children' => [
99 [
100 'label' => __('Site URL', 'fluent-cart'),
101 'value' => 'site_url',
102 'type' => 'text',
103 'filter_type' => 'column',
104 'column' => 'site_url',
105 ],
106 [
107 'label' => __('Platform Version', 'fluent-cart'),
108 'value' => 'platform_version',
109 'type' => 'text',
110 'filter_type' => 'column',
111 'column' => 'platform_version',
112 ],
113 [
114 'label' => __('Server Version', 'fluent-cart'),
115 'value' => 'server_version',
116 'type' => 'text',
117 'filter_type' => 'column',
118 'column' => 'server_version',
119 ],
120 [
121 'label' => __('Registered Date', 'fluent-cart'),
122 'value' => 'created_at',
123 'type' => 'dates',
124 'filter_type' => 'date',
125 'column' => 'created_at',
126 ],
127 ],
128 ],
129 'product' => [
130 'label' => __('Product', 'fluent-cart'),
131 'value' => 'product',
132 'children' => [
133 [
134 'label' => __('By Products', 'fluent-cart'),
135 'value' => 'product',
136 'type' => 'remote_tree_select',
137 'filter_type' => 'custom',
138 'remote_data_key' => 'product_variations',
139 'limit' => 10,
140 'callback' => function ($query, $data) {
141 $variationIds = (array)$data['value'];
142 $query->whereHas('activations', function ($q) use ($variationIds) {
143 $q->whereHas('license', function ($lq) use ($variationIds) {
144 $lq->whereIn('variation_id', $variationIds);
145 });
146 });
147 }
148 ],
149 ],
150 ],
151 'license' => [
152 'label' => __('License Property', 'fluent-cart'),
153 'value' => 'license',
154 'children' => [
155 [
156 'label' => __('Activation Status', 'fluent-cart'),
157 'value' => 'activation_status',
158 'type' => 'selections',
159 'filter_type' => 'custom',
160 'options' => [
161 'active' => __('Active', 'fluent-cart'),
162 'inactive' => __('Inactive', 'fluent-cart'),
163 ],
164 'is_multiple' => true,
165 'is_only_in' => true,
166 'callback' => function ($query, $data) {
167 $query->whereHas('activations', function ($q) use ($data) {
168 $q->whereIn('status', (array)$data['value']);
169 });
170 }
171 ],
172 [
173 'label' => __('Active License Count', 'fluent-cart'),
174 'value' => 'active_license_count',
175 'type' => 'numeric',
176 'filter_type' => 'custom',
177 'callback' => function ($query, $data) {
178 $operator = isset($data['operator']) ? $data['operator'] : '=';
179 $value = intval($data['value']);
180 $query->whereHas('activations', function ($q) {
181 $q->where('status', 'active');
182 }, $operator, $value);
183 }
184 ],
185 ],
186 ],
187 ];
188 }
189 }
190