namespace wcf\system\view\grid;
+use LogicException;
+
abstract class ArrayGridView extends AbstractGridView
{
protected array $dataArray;
{
if (!isset($this->dataArray)) {
$this->dataArray = $this->loadDataArray();
+ $this->applyFilters();
}
return $this->dataArray;
}
+ protected function applyFilters(): void
+ {
+ foreach ($this->getActiveFilters() as $key => $value) {
+ $column = $this->getColumn($key);
+ if (!$column) {
+ throw new LogicException("Unknown column '" . $key . "'");
+ }
+
+ $this->dataArray = \array_filter($this->dataArray, function (array $row) use ($column, $value) {
+ return $column->getFilter()->matches($value, $row[$column->getID()]);
+ });
+ }
+ }
+
protected abstract function loadDataArray(): array;
}
return $this->objectList;
}
- private function applyFilters(): void
+ protected function applyFilters(): void
{
foreach ($this->getActiveFilters() as $key => $value) {
$column = $this->getColumn($key);
return $row['exceptionID'];
}
+ #[\Override]
protected function loadDataArray(): array
{
if (!empty($this->getActiveFilters()['exceptionID'])) {
return [];
}
+ #[\Override]
+ protected function applyFilters(): void
+ {
+ // Overwrite the default filtering, as this is already applied when the data is loaded.
+ }
+
private function getAvailableLogFiles(): array
{
if (!isset($this->availableLogFiles)) {
public function applyFilter(DatabaseObjectList $list, string $id, string $value): void;
+ public function matches(string $filterValue, string $rowValue): bool;
+
public function renderValue(string $value): string;
}
$list->getConditionBuilder()->add("$id = ?", [$value]);
}
+ #[\Override]
+ public function matches(string $filterValue, string $rowValue): bool
+ {
+ return $filterValue === $rowValue;
+ }
+
#[\Override]
public function renderValue(string $value): string
{
$list->getConditionBuilder()->add("$id LIKE ?", ['%' . $value . '%']);
}
+ #[\Override]
+ public function matches(string $filterValue, string $rowValue): bool
+ {
+ return \str_contains(\mb_strtolower($rowValue), \mb_strtolower($filterValue));
+ }
+
#[\Override]
public function renderValue(string $value): string
{