Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
stepapo committed Dec 16, 2024
1 parent db4f9ee commit 9dc1499
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Control/Dataset/DatasetControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ public function render(): void
$this->template->showPagination = (bool) $this->dataset->itemsPerPage;
$this->template->isResponsive = $this->dataset->isResponsive;
$this->template->showSearch = (bool) $this->dataset->search && !$this->dataset->search->hide;
$showFilter = false;
foreach ($this->dataset->columns as $column) {
if ($column->filter && !$column->filter->hide) {
$showFilter = true;
break;
}
}
$this->template->showFilter = $showFilter;
if ($this->dataset->itemsPerPage && $this->shouldRetrieveItems) {
$count = $this->getCurrentCount();
$term = $this->dataset->search ? $this->getComponent('searchForm')->term : null;
Expand Down Expand Up @@ -220,6 +228,9 @@ private function filter(ICollection $c): ICollection
}
$this->activeFilter = true;
if ($column->filter->type === 'single') {
if (!isset($column->filter->options[$value])) {
continue;
}
if ($column->filter->options[$value] instanceof Option && $column->filter->options[$value]->condition) {
$c = $c->findBy($column->filter->options[$value]->condition);
} elseif ($column->filter->function) {
Expand Down Expand Up @@ -248,6 +259,9 @@ private function filter(ICollection $c): ICollection
if ($column->filter->multiMode === 'any') {
$filter = [ICollection::OR];
foreach ($value as $v) {
if (!isset($column->filter->options[$v])) {
continue;
}
if ($column->filter->options[$v] instanceof Option && $column->filter->options[$v]->condition) {
$filter[] = $column->filter->options[$v]->condition;
} elseif ($column->filter->function) {
Expand All @@ -268,6 +282,9 @@ private function filter(ICollection $c): ICollection
} elseif ($column->filter->multiMode === 'all') {
$filter = [ICollection::AND];
foreach ($value as $v) {
if (!isset($column->filter->options[$v])) {
continue;
}
$aggregator = new AnyAggregator(Random::generate());
if ($column->filter->options[$v] instanceof Option && $column->filter->options[$v]->condition) {
$filter[] = [ICollection::AND, $aggregator, $column->filter->options[$v]->condition];
Expand Down
1 change: 1 addition & 0 deletions src/Control/Dataset/DatasetTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class DatasetTemplate extends DataTemplate
{
public DatasetControl $control;
public bool $showSearch;
public bool $showFilter;
public int $count;
public bool $showPagination;
public bool $isResponsive;
Expand Down

0 comments on commit 9dc1499

Please sign in to comment.