| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Services\Filter; |
| 4 |
|
| 5 |
use FluentCart\App\Models\AttributeTerm; |
| 6 |
use FluentCart\App\Services\Filter\BaseFilter; |
| 7 |
use FluentCart\App\Services\Filter\Concerns\HasIdTitleSlugSearch; |
| 8 |
|
| 9 |
class AttrTermFilter extends BaseFilter |
| 10 |
{ |
| 11 |
use HasIdTitleSlugSearch; |
| 12 |
public string $defaultSortBy = 'serial'; |
| 13 |
public string $defaultSortType = 'asc'; |
| 14 |
|
| 15 |
protected function parseSortBy(): string |
| 16 |
{ |
| 17 |
return 'serial'; |
| 18 |
} |
| 19 |
|
| 20 |
protected function parseSortType(): string |
| 21 |
{ |
| 22 |
return 'asc'; |
| 23 |
} |
| 24 |
|
| 25 |
protected ?int $groupId = null; |
| 26 |
|
| 27 |
public function setGroupId(int $groupId): self |
| 28 |
{ |
| 29 |
$this->groupId = $groupId; |
| 30 |
return $this; |
| 31 |
} |
| 32 |
|
| 33 |
public function applySelect(): void |
| 34 |
{ |
| 35 |
$this->query->select(['id', 'title', 'settings', 'serial', 'created_at']); |
| 36 |
} |
| 37 |
|
| 38 |
protected function buildCommonQuery() |
| 39 |
{ |
| 40 |
if ($this->groupId) { |
| 41 |
$this->query->where('group_id', $this->groupId); |
| 42 |
} |
| 43 |
|
| 44 |
parent::buildCommonQuery(); |
| 45 |
|
| 46 |
// Default sort is serial ASC, but two terms can share the same serial |
| 47 |
// (the swap-on-reorder logic guarantees uniqueness within a group at |
| 48 |
// the moment of reorder, but bulk imports or partial states can leave |
| 49 |
// ties). Append id ASC as a deterministic tie-breaker so paginated |
| 50 |
// listings stay stable across requests. |
| 51 |
$this->query->orderBy('id', 'ASC'); |
| 52 |
} |
| 53 |
|
| 54 |
public function tabsMap(): array |
| 55 |
{ |
| 56 |
return []; |
| 57 |
} |
| 58 |
|
| 59 |
public function getModel(): string |
| 60 |
{ |
| 61 |
return AttributeTerm::class; |
| 62 |
} |
| 63 |
|
| 64 |
public static function getFilterName(): string |
| 65 |
{ |
| 66 |
return 'attr_terms'; |
| 67 |
} |
| 68 |
|
| 69 |
public function applyActiveViewFilter(?string $activeView = null): void |
| 70 |
{ |
| 71 |
// Terms have no tab views; this hook is intentionally a no-op. |
| 72 |
} |
| 73 |
} |
| 74 |
|