*/
public function renderRows(): string
{
+ $this->prepareRenderers();
+
return WCF::getTPL()->fetch('shared_gridViewRows', 'wcf', ['view' => $this], true);
}
return null;
}
+ /**
+ * Prepares the column renderers.
+ */
+ protected function prepareRenderers(): void
+ {
+ foreach ($this->getVisibleColumns() as $column) {
+ foreach ($column->getRenderers() as $renderer) {
+ foreach ($this->getRows() as $row) {
+ $renderer->prepare($this->getData($row, $column->getID()), $row);
+ }
+ }
+ }
+ }
+
/**
* Returns the rows for the active page.
*/
--- /dev/null
+<?php
+
+namespace wcf\system\gridView\filter;
+
+use wcf\data\DatabaseObjectList;
+use wcf\system\cache\runtime\UserRuntimeCache;
+use wcf\system\form\builder\field\AbstractFormField;
+use wcf\system\form\builder\field\user\UserFormField;
+
+/**
+ * Filter for columns that contain user 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 UserFilter implements IGridViewFilter
+{
+ #[\Override]
+ public function getFormField(string $id, string $label): AbstractFormField
+ {
+ return UserFormField::create($id)
+ ->label($label)
+ ->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 $rowValue == $filterValue;
+ }
+
+ #[\Override]
+ public function renderValue(string $value): string
+ {
+ $user = UserRuntimeCache::getInstance()->getObject($value);
+
+ return $user ? $user->username : '';
+ }
+}
{
return '';
}
+
+ #[\Override]
+ public function prepare(mixed $value, mixed $context = null): void {}
}
* Returns the css classes of a column.
*/
public function getClasses(): string;
+
+ /**
+ * Is called after the grid view data has been loaded and allows additional data to be loaded or cached.
+ */
+ public function prepare(mixed $value, mixed $context = null): void;
}
--- /dev/null
+<?php
+
+namespace wcf\system\gridView\renderer;
+
+use wcf\system\cache\runtime\UserRuntimeCache;
+use wcf\util\StringUtil;
+
+/**
+ * Formats the content of a column as a user.
+ *
+ * @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 UserColumnRenderer extends DefaultColumnRenderer
+{
+ #[\Override]
+ public function render(mixed $value, mixed $context = null): string
+ {
+ if (!$value) {
+ return '';
+ }
+
+ $user = UserRuntimeCache::getInstance()->getObject($value);
+ if ($user === null) {
+ return '';
+ }
+
+ return StringUtil::encodeHTML($user->username);
+ }
+
+ #[\Override]
+ public function prepare(mixed $value, mixed $context = null): void
+ {
+ if (!$value) {
+ return;
+ }
+
+ UserRuntimeCache::getInstance()->cacheObjectID($value);
+ }
+}