PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.1
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.1
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.6.1, at app/Services/Filter/LicenseSiteFilter.php

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