Add filter for object ids
authorMarcel Werk <burntime@woltlab.com>
Mon, 9 Dec 2024 16:04:40 +0000 (17:04 +0100)
committerMarcel Werk <burntime@woltlab.com>
Mon, 9 Dec 2024 16:04:40 +0000 (17:04 +0100)
wcfsetup/install/files/lib/system/gridView/filter/ObjectIdFilter.class.php [new file with mode: 0644]

diff --git a/wcfsetup/install/files/lib/system/gridView/filter/ObjectIdFilter.class.php b/wcfsetup/install/files/lib/system/gridView/filter/ObjectIdFilter.class.php
new file mode 100644 (file)
index 0000000..501026b
--- /dev/null
@@ -0,0 +1,45 @@
+<?php
+
+namespace wcf\system\gridView\filter;
+
+use wcf\data\DatabaseObjectList;
+use wcf\system\form\builder\field\AbstractFormField;
+use wcf\system\form\builder\field\IntegerFormField;
+
+/**
+ * Filter for columns that contain object ids.
+ *
+ * @author      Marcel Werk
+ * @copyright   2001-2024 WoltLab GmbH
+ * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since       6.2
+ */
+class ObjectIdFilter implements IGridViewFilter
+{
+    #[\Override]
+    public function getFormField(string $id, string $label): AbstractFormField
+    {
+        return IntegerFormField::create($id)
+            ->label($label)
+            ->minimum(1)
+            ->nullable();
+    }
+
+    #[\Override]
+    public function applyFilter(DatabaseObjectList $list, string $id, string $value): void
+    {
+        $list->getConditionBuilder()->add("$id = ?", [$value]);
+    }
+
+    #[\Override]
+    public function matches(string $filterValue, string $rowValue): bool
+    {
+        return $filterValue == $rowValue;
+    }
+
+    #[\Override]
+    public function renderValue(string $value): string
+    {
+        return $value;
+    }
+}