| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Services\Filter; |
| 4 |
|
| 5 |
use FluentCart\App\Models\Label; |
| 6 |
use FluentCart\App\Models\Order; |
| 7 |
use FluentCart\Framework\Database\Orm\Builder; |
| 8 |
use FluentCart\Framework\Support\Arr; |
| 9 |
|
| 10 |
class LabelFilter extends BaseFilter |
| 11 |
{ |
| 12 |
|
| 13 |
public function applySimpleFilter(?string $search = null): void |
| 14 |
{ |
| 15 |
$this->query = $this->query->when($search ?? $this->search, function ($query, $search) { |
| 16 |
return $query->where('value', 'LIKE', "%{$search}%"); |
| 17 |
}); |
| 18 |
} |
| 19 |
|
| 20 |
public function tabsMap(): array |
| 21 |
{ |
| 22 |
return []; |
| 23 |
} |
| 24 |
|
| 25 |
public function getModel(): string |
| 26 |
{ |
| 27 |
return Label::class; |
| 28 |
} |
| 29 |
|
| 30 |
public static function getFilterName(): string |
| 31 |
{ |
| 32 |
return 'label'; |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Intentionally empty. This filter cannot receive a request `with` today: |
| 37 |
* its only caller is AdvanceFilterController::getFilterOption(), which |
| 38 |
* hand-builds a five-key argument array (remote_data_key, search, |
| 39 |
* include_ids, limit, parent_id) and never forwards the raw request. |
| 40 |
* |
| 41 |
* That is the reason the map is empty, NOT an oversight — if this filter is |
| 42 |
* ever refactored to take `$request->all()`, an empty map is what keeps it |
| 43 |
* closed, and any relation it then needs must be added here deliberately as |
| 44 |
* a context key mapped to a callable. |
| 45 |
* |
| 46 |
* @return array<string, callable> |
| 47 |
*/ |
| 48 |
protected function allowedWiths(): array |
| 49 |
{ |
| 50 |
return []; |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
public function applyActiveViewFilter(?string $activeView = null): void |
| 55 |
{ |
| 56 |
|
| 57 |
} |
| 58 |
|
| 59 |
public static function getSelectFilterOptions(array $args): array |
| 60 |
{ |
| 61 |
return static::make($args)->get()->pluck('value', 'id')->toArray(); |
| 62 |
} |
| 63 |
|
| 64 |
public static function advanceFilterOptions() |
| 65 |
{ |
| 66 |
return null; |
| 67 |
} |
| 68 |
|
| 69 |
public static function advanceFilterOptionsForOther($otherFilters = []): array |
| 70 |
{ |
| 71 |
return array_merge( |
| 72 |
$otherFilters, |
| 73 |
[ |
| 74 |
'labels' => [ |
| 75 |
'label' => __('Labels', 'fluent-cart'), |
| 76 |
'value' => 'labels', |
| 77 |
'children' => [ |
| 78 |
[ |
| 79 |
'label' => __('Label Name', 'fluent-cart'), |
| 80 |
'value' => 'customer_email', |
| 81 |
'type' => 'selections', |
| 82 |
'filter_type' => 'relation', |
| 83 |
'column' => 'label_id', |
| 84 |
'relation' => 'labels', |
| 85 |
'remote' => true, |
| 86 |
'remote_data_key' => 'labels', |
| 87 |
'is_multiple' => true |
| 88 |
] |
| 89 |
] |
| 90 |
] |
| 91 |
] |
| 92 |
); |
| 93 |
} |
| 94 |
} |