Skip to content

Commit d86e0db

Browse files
committed
Handle list filter
1 parent 77fa0cd commit d86e0db

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

src/Console/ConfigureCmsCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public function handle(Client $ozuClient): int
4949
'isSearchable' => $list->isSearchable(),
5050
'isPaginated' => $list->isPaginated(),
5151
'defaultSort' => $list->defaultSort(),
52+
'belongsToFilter' => $list->belongsToFilter()?->toArray(),
5253
'columns' => $list
5354
->columns()
5455
->map(fn (OzuColumn $column) => [
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Code16\OzuClient\OzuCms\List;
4+
5+
class OzuBelongsToFilter
6+
{
7+
protected bool $required = true;
8+
private ?string $label = null;
9+
10+
public function __construct(protected string $ozuCollectionKey)
11+
{
12+
}
13+
14+
public function setRequired(bool $required = true): self
15+
{
16+
$this->required = $required;
17+
18+
return $this;
19+
}
20+
21+
public function setLabel(string $label): self
22+
{
23+
$this->label = $label;
24+
25+
return $this;
26+
}
27+
28+
public function toArray(): array
29+
{
30+
return [
31+
'collectionKey' => $this->ozuCollectionKey,
32+
'label' => $this->label,
33+
'required' => $this->required,
34+
];
35+
}
36+
}

src/OzuCms/OzuCollectionListConfig.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Code16\OzuClient\OzuCms;
44

5+
use Code16\OzuClient\OzuCms\Form\OzuBelongsToField;
6+
use Code16\OzuClient\OzuCms\List\OzuBelongsToFilter;
57
use Code16\OzuClient\OzuCms\List\OzuColumn;
68
use Illuminate\Support\Collection;
79

@@ -10,6 +12,8 @@ class OzuCollectionListConfig
1012
protected bool $isReorderable = false;
1113
protected bool $isSearchable = false;
1214
protected bool $isPaginated = false;
15+
16+
protected ?OzuBelongsToFilter $belongsToFilter = null;
1317
protected array $columns = [];
1418

1519
public function setIsReorderable(bool $isReorderable = true): self
@@ -33,6 +37,17 @@ public function setIsPaginated(bool $isPaginated = true): self
3337
return $this;
3438
}
3539

40+
public function declareBelongsToFilter(string $ozuModelClass, string $label, bool $required = true): self
41+
{
42+
$ozuCollectionKey = app($ozuModelClass)->ozuCollectionKey();
43+
44+
$this->belongsToFilter = (new OzuBelongsToFilter($ozuCollectionKey))
45+
->setLabel($label)
46+
->setRequired($required);
47+
48+
return $this;
49+
}
50+
3651
public function addColumn(OzuColumn $column): self
3752
{
3853
$this->columns[] = $column;
@@ -60,6 +75,11 @@ public function columns(): Collection
6075
return collect($this->columns);
6176
}
6277

78+
public function belongsToFilter(): ?OzuBelongsToFilter
79+
{
80+
return $this->belongsToFilter;
81+
}
82+
6383
public function defaultSort(): ?array
6484
{
6585
$column = collect($this->columns)

0 commit comments

Comments
 (0)