From: Marcel Werk Date: Tue, 12 Nov 2024 15:57:47 +0000 (+0100) Subject: Rename ArrayGridView to DataSourceGridView X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=e4b6a4b52a9badb5cefad2320fef521b1e97dc36;p=GitHub%2FWoltLab%2FWCF.git Rename ArrayGridView to DataSourceGridView --- diff --git a/wcfsetup/install/files/lib/system/view/grid/ArrayGridView.class.php b/wcfsetup/install/files/lib/system/view/grid/ArrayGridView.class.php deleted file mode 100644 index 4bb726d647..0000000000 --- a/wcfsetup/install/files/lib/system/view/grid/ArrayGridView.class.php +++ /dev/null @@ -1,67 +0,0 @@ -sortRows(); - - return $this->getRowsForPage(); - } - - protected function sortRows(): void - { - $this->getDataArray(); - - \uasort($this->dataArray, function (array $a, array $b) { - if ($this->getSortOrder() === 'ASC') { - return \strcmp($a[$this->getSortField()], $b[$this->getSortField()]); - } else { - return \strcmp($b[$this->getSortField()], $a[$this->getSortField()]); - } - }); - } - - protected function getRowsForPage(): array - { - return \array_slice($this->getDataArray(), ($this->getPageNo() - 1) * $this->getRowsPerPage(), $this->getRowsPerPage()); - } - - public function countRows(): int - { - return \count($this->getDataArray()); - } - - protected function getDataArray(): array - { - if (!isset($this->dataArray)) { - $this->dataArray = $this->loadDataArray(); - $this->applyFilters(); - $this->fireInitializedEvent(); - } - - 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; -} diff --git a/wcfsetup/install/files/lib/system/view/grid/DataSourceGridView.class.php b/wcfsetup/install/files/lib/system/view/grid/DataSourceGridView.class.php new file mode 100644 index 0000000000..b59c065e59 --- /dev/null +++ b/wcfsetup/install/files/lib/system/view/grid/DataSourceGridView.class.php @@ -0,0 +1,67 @@ +sortRows(); + + return $this->getRowsForPage(); + } + + protected function sortRows(): void + { + $this->getDataSource(); + + \uasort($this->dataSource, function (array $a, array $b) { + if ($this->getSortOrder() === 'ASC') { + return \strcmp($a[$this->getSortField()], $b[$this->getSortField()]); + } else { + return \strcmp($b[$this->getSortField()], $a[$this->getSortField()]); + } + }); + } + + protected function getRowsForPage(): array + { + return \array_slice($this->getDataSource(), ($this->getPageNo() - 1) * $this->getRowsPerPage(), $this->getRowsPerPage()); + } + + public function countRows(): int + { + return \count($this->getDataSource()); + } + + protected function getDataSource(): array + { + if (!isset($this->dataSource)) { + $this->dataSource = $this->loadDataSource(); + $this->applyFilters(); + $this->fireInitializedEvent(); + } + + return $this->dataSource; + } + + protected function applyFilters(): void + { + foreach ($this->getActiveFilters() as $key => $value) { + $column = $this->getColumn($key); + if (!$column) { + throw new LogicException("Unknown column '" . $key . "'"); + } + + $this->dataSource = \array_filter($this->dataSource, function (array $row) use ($column, $value) { + return $column->getFilter()->matches($value, $row[$column->getID()]); + }); + } + } + + protected abstract function loadDataSource(): array; +} diff --git a/wcfsetup/install/files/lib/system/view/grid/ExceptionLogGridView.class.php b/wcfsetup/install/files/lib/system/view/grid/ExceptionLogGridView.class.php index a8da2dd2f9..a075458ccb 100644 --- a/wcfsetup/install/files/lib/system/view/grid/ExceptionLogGridView.class.php +++ b/wcfsetup/install/files/lib/system/view/grid/ExceptionLogGridView.class.php @@ -13,7 +13,7 @@ use wcf\system\WCF; use wcf\util\DirectoryUtil; use wcf\util\ExceptionLogUtil; -final class ExceptionLogGridView extends ArrayGridView +final class ExceptionLogGridView extends DataSourceGridView { private array $availableLogFiles; @@ -62,7 +62,7 @@ final class ExceptionLogGridView extends ArrayGridView } #[\Override] - protected function loadDataArray(): array + protected function loadDataSource(): array { if (!empty($this->getActiveFilters()['exceptionID'])) { $exceptionID = $this->getActiveFilters()['exceptionID'];