Skip to content

Commit 0737710

Browse files
committed
Merge branch 'master' of github.com:LokiExtensions/Loki_AdminComponents
2 parents 91ee0d1 + f4e4321 commit 0737710

1 file changed

Lines changed: 34 additions & 2 deletions

File tree

ProviderHandler/ArrayHandler.php

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,14 @@ public function getItems(object $provider, GridState $gridState): array
5656

5757

5858
$search = $gridState->getSearch();
59+
$searchableFields = $gridState->getSearchableFields();
5960
if (!empty($search)) {
60-
$items = array_filter($items, function (DataObject $item) use ($search) {
61-
foreach ($item->getData() as $itemValue) {
61+
$items = array_filter($items, function (DataObject $item) use ($search, $searchableFields) {
62+
foreach ($item->getData() as $fieldName => $itemValue) {
63+
if($searchableFields && !in_array($fieldName, $searchableFields)) {
64+
continue;
65+
}
66+
6267
if (is_string($itemValue) && str_contains($itemValue, $search)) {
6368
return true;
6469
}
@@ -68,6 +73,33 @@ public function getItems(object $provider, GridState $gridState): array
6873
});
6974
}
7075

76+
foreach($gridState->getFilters() as $filter) {
77+
$items = match($filter->getConditionType()) {
78+
'like' => array_filter($items, function (DataObject $item) use ($filter) {
79+
return str_contains((string)$item->getData($filter->getField()), (string)$filter->getValue());
80+
}),
81+
'equals' => array_filter($items, function (DataObject $item) use ($filter) {
82+
return (string)$item->getData($filter->getField()) === (string)$filter->getValue();
83+
}),
84+
'from_to' => array_filter($items, function (DataObject $item) use ($filter) {
85+
$fieldValue = $item->getData($filter->getField());
86+
87+
$from = $filter->getValue()['from'] ?? '';
88+
if ($from !== '' && $fieldValue < $from) {
89+
return false;
90+
}
91+
92+
$to = $filter->getValue()['to'] ?? '';
93+
if ($to !== '' && $fieldValue > $to) {
94+
return false;
95+
}
96+
97+
return true;
98+
}),
99+
default => $items
100+
};
101+
}
102+
71103
$sortField = $gridState->getSortBy();
72104
$sortDirection = $gridState->getSortDirection();
73105
if (!empty($sortField)) {

0 commit comments

Comments
 (0)