Rename ArrayGridView to DataSourceGridView
authorMarcel Werk <burntime@woltlab.com>
Tue, 12 Nov 2024 15:57:47 +0000 (16:57 +0100)
committerMarcel Werk <burntime@woltlab.com>
Tue, 12 Nov 2024 15:57:47 +0000 (16:57 +0100)
wcfsetup/install/files/lib/system/view/grid/ArrayGridView.class.php [deleted file]
wcfsetup/install/files/lib/system/view/grid/DataSourceGridView.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/view/grid/ExceptionLogGridView.class.php

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 (file)
index 4bb726d..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-<?php
-
-namespace wcf\system\view\grid;
-
-use LogicException;
-
-abstract class ArrayGridView extends AbstractGridView
-{
-    protected array $dataArray;
-
-    public function getRows(): array
-    {
-        $this->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 (file)
index 0000000..b59c065
--- /dev/null
@@ -0,0 +1,67 @@
+<?php
+
+namespace wcf\system\view\grid;
+
+use LogicException;
+
+abstract class DataSourceGridView extends AbstractGridView
+{
+    protected array $dataSource;
+
+    public function getRows(): array
+    {
+        $this->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;
+}
index a8da2dd2f97565eb6d0cf78f56e98f252a470788..a075458ccb28392c777ff5c2ccb862796d69319b 100644 (file)
@@ -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'];