* @inheritDoc
*/
public $className = ACPSessionLog::class;
-
- /**
- * @inheritDoc
- */
- public function readObjects()
- {
- if (!empty($this->sqlSelects)) {
- $this->sqlSelects .= ',';
- }
- $this->sqlSelects .= "
- (
- SELECT username
- FROM wcf1_user
- WHERE userID = " . $this->getDatabaseTableAlias() . ".userID
- ) AS username,
- 0 AS active,
- (
- SELECT COUNT(*)
- FROM wcf1_acp_session_access_log
- WHERE sessionLogID = " . $this->getDatabaseTableAlias() . ".sessionLogID
- ) AS accesses";
-
- parent::readObjects();
- }
}
namespace wcf\system\gridView;
+use wcf\acp\form\UserEditForm;
use wcf\acp\page\ACPSessionLogPage;
use wcf\data\acp\session\log\ACPSessionLogList;
use wcf\data\DatabaseObjectList;
use wcf\system\gridView\renderer\NumberColumnRenderer;
use wcf\system\gridView\renderer\TimeColumnRenderer;
use wcf\system\gridView\renderer\TruncatedTextColumnRenderer;
-use wcf\system\gridView\renderer\UserColumnRenderer;
+use wcf\system\gridView\renderer\UserLinkColumnRenderer;
use wcf\system\WCF;
/**
->sortable(),
GridViewColumn::for('userID')
->label('wcf.user.username')
- ->sortable()
- ->sortById('username')
- ->renderer(new UserColumnRenderer())
+ ->sortable(true, 'user_table.username')
+ ->renderer(new UserLinkColumnRenderer(UserEditForm::class))
->filter(new UserFilter()),
GridViewColumn::for('ipAddress')
->label('wcf.user.ipAddress')
->label('wcf.user.userAgent')
->sortable()
->valueEncoding(false)
- ->renderer(new TruncatedTextColumnRenderer())
+ ->renderer(new TruncatedTextColumnRenderer(50))
->filter(new TextFilter()),
GridViewColumn::for('time')
->label('wcf.acp.sessionLog.time')
->filter(new TimeFilter()),
GridViewColumn::for('accesses')
->label('wcf.acp.sessionLog.actions')
- ->sortable()
+ ->sortable(true, 'accesses')
->renderer(new NumberColumnRenderer()),
]);
#[\Override]
protected function createObjectList(): DatabaseObjectList
{
- return new ACPSessionLogList();
+ $list = new ACPSessionLogList();
+ $list->sqlSelects .= "
+ user_table.username,
+ 0 AS active,
+ (
+ SELECT COUNT(*)
+ FROM wcf1_acp_session_access_log
+ WHERE sessionLogID = " . $list->getDatabaseTableAlias() . ".sessionLogID
+ ) AS accesses";
+ $list->sqlJoins = $list->sqlConditionJoins .= " JOIN wcf" . WCF_N . "_user user_table ON (user_table.userID = " . $list->getDatabaseTableAlias() . ".userID)";
+
+ return $list;
}
#[\Override]
throw new LogicException("No value for filter '" . $id . "' found.");
}
- return $column->getLabel() . ': ' . $column->getFilter()->renderValue($this->activeFilters[$id]);
+ $value = $column->getFilter()->renderValue($this->activeFilters[$id]);
+
+ return $column->getLabel() . ($value !== '' ? ': ' . $value : '');
}
/**
{
protected DatabaseObjectList $objectList;
private int $objectCount;
+ public int $counter = 0;
#[\Override]
public function getRows(): array
{
$this->getObjectList()->readObjects();
+ $this->counter++;
+
return $this->getObjectList()->getObjects();
}
$this->objectList->sqlOffset = ($this->getPageNo() - 1) * $this->getRowsPerPage();
if ($this->getSortField()) {
$column = $this->getColumn($this->getSortField());
- if ($column && $column->getSortById()) {
- $this->objectList->sqlOrderBy = $column->getSortById() . ' ' . $this->getSortOrder();
+ if ($column && $column->getSortByDatabaseColumn()) {
+ $this->objectList->sqlOrderBy = $column->getSortByDatabaseColumn() . ' ' . $this->getSortOrder();
} else {
- $this->objectList->sqlOrderBy = $this->getSortField() . ' ' . $this->getSortOrder();
+ $this->objectList->sqlOrderBy = $this->objectList->getDatabaseTableAlias() .
+ '.' . $this->getSortField() . ' ' . $this->getSortOrder();
}
+
+ $this->objectList->sqlOrderBy .= ',' . $this->objectList->getDatabaseTableAlias() .
+ '.' . $this->objectList->getDatabaseTableIndexName() . ' ' . $this->getSortOrder();
}
$this->applyFilters();
$this->fireInitializedEvent();
private string $label = '';
private static DefaultColumnRenderer $defaultRenderer;
private bool $sortable = false;
- private string $sortById = '';
+ private string $sortByDatabaseColumn = '';
private ?IGridViewFilter $filter = null;
private bool $hidden = false;
private bool $valueEncoding = true;
/**
* Sets the sortable state of this column.
*/
- public function sortable(bool $sortable = true): static
+ public function sortable(bool $sortable = true, string $sortByDatabaseColumn = ''): static
{
$this->sortable = $sortable;
-
- return $this;
- }
-
- /**
- * Defines the ID by which this column is to be sorted.
- */
- public function sortById(string $id): static
- {
- $this->sortById = $id;
+ $this->sortByDatabaseColumn = $sortByDatabaseColumn;
return $this;
}
}
/**
- * Returns the ID by which this column is to be sorted.
+ * Returns the name of the database column by which this column is to be sorted.
*/
- public function getSortById(): string
+ public function getSortByDatabaseColumn(): string
{
- return $this->sortById;
+ return $this->sortByDatabaseColumn;
}
/**
->sortable(),
GridViewColumn::for('userID')
->label('wcf.user.username')
- ->sortable()
- ->sortById('username')
+ ->sortable(true, 'modification_log.username')
->renderer(new UserLinkColumnRenderer())
- ->filter(new TextFilter('username')),
+ ->filter(new TextFilter('modification_log.username')),
GridViewColumn::for('action')
->label('wcf.acp.modificationLog.action')
->renderer([
->sortable(),
GridViewColumn::for('rankTitle')
->label('wcf.acp.user.rank.title')
- ->sortable()
- ->sortById('rankTitleI18n')
+ ->sortable(true, 'rankTitleI18n')
->filter(new I18nTextFilter())
->renderer([
new class extends TitleColumnRenderer {
--- /dev/null
+<?php
+
+namespace wcf\system\gridView\filter;
+
+use wcf\data\DatabaseObjectList;
+
+/**
+ * Abstract implementation for grid view column filters.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.2
+ */
+abstract class AbstractFilter implements IGridViewFilter
+{
+ public function __construct(protected readonly string $databaseColumn = '') {}
+
+ #[\Override]
+ public function renderValue(string $value): string
+ {
+ return $value;
+ }
+
+ protected function getDatabaseColumnName(DatabaseObjectList $list, string $id): string
+ {
+ return ($this->databaseColumn ?: $list->getDatabaseTableAlias() . '.' . $id);
+ }
+}
--- /dev/null
+<?php
+
+namespace wcf\system\gridView\filter;
+
+use wcf\data\DatabaseObjectList;
+use wcf\system\form\builder\field\AbstractFormField;
+use wcf\system\form\builder\field\CheckboxFormField;
+
+/**
+ * Filter for boolean columns.
+ *
+ * @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 BooleanFilter extends AbstractFilter
+{
+ #[\Override]
+ public function getFormField(string $id, string $label): AbstractFormField
+ {
+ return CheckboxFormField::create($id)
+ ->label($label)
+ ->nullable();
+ }
+
+ #[\Override]
+ public function applyFilter(DatabaseObjectList $list, string $id, string $value): void
+ {
+ $columnName = $this->getDatabaseColumnName($list, $id);
+
+ $list->getConditionBuilder()->add("{$columnName} = ?", [1]);
+ }
+
+ #[\Override]
+ public function matches(string $filterValue, string $rowValue): bool
+ {
+ return $rowValue == 1;
+ }
+
+ #[\Override]
+ public function renderValue(string $value): string
+ {
+ return '';
+ }
+}
#[\Override]
public function applyFilter(DatabaseObjectList $list, string $id, string $value): void
{
- $list->getConditionBuilder()->add("($id LIKE ? OR $id IN (SELECT languageItem FROM wcf1_language_item WHERE languageID = ? AND languageItemValue LIKE ?))", [
+ $columnName = $this->getDatabaseColumnName($list, $id);
+
+ $list->getConditionBuilder()->add("({$columnName} LIKE ? OR {$columnName} IN (SELECT languageItem FROM wcf1_language_item WHERE languageID = ? AND languageItemValue LIKE ?))", [
'%' . WCF::getDB()->escapeLikeValue($value) . '%',
WCF::getLanguage()->languageID,
'%' . WCF::getDB()->escapeLikeValue($value) . '%'
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @since 6.2
*/
-class IpAddressFilter implements IGridViewFilter
+class IpAddressFilter extends AbstractFilter
{
#[\Override]
public function getFormField(string $id, string $label): AbstractFormField
#[\Override]
public function applyFilter(DatabaseObjectList $list, string $id, string $value): void
{
+ $columnName = $this->getDatabaseColumnName($list, $id);
+
$list->getConditionBuilder()->add(
- "{$id} LIKE ?",
+ "{$columnName} LIKE ?",
['%' . WCF::getDB()->escapeLikeValue($this->convertIPv4To6($value)) . '%']
);
}
return \str_contains($rowValue, $this->convertIPv4To6($filterValue));
}
- #[\Override]
- public function renderValue(string $value): string
- {
- return $value;
- }
-
private function convertIPv4To6(string $value): string
{
return UserUtil::convertIPv4To6($value);
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @since 6.2
*/
-class ObjectIdFilter implements IGridViewFilter
+class ObjectIdFilter extends AbstractFilter
{
#[\Override]
public function getFormField(string $id, string $label): AbstractFormField
#[\Override]
public function applyFilter(DatabaseObjectList $list, string $id, string $value): void
{
- $list->getConditionBuilder()->add("$id = ?", [$value]);
+ $columnName = $this->getDatabaseColumnName($list, $id);
+
+ $list->getConditionBuilder()->add("{$columnName} = ?", [$value]);
}
#[\Override]
{
return $filterValue == $rowValue;
}
-
- #[\Override]
- public function renderValue(string $value): string
- {
- return $value;
- }
}
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @since 6.2
*/
-class SelectFilter implements IGridViewFilter
+class SelectFilter extends AbstractFilter
{
- public function __construct(private readonly array $options) {}
+ public function __construct(private readonly array $options, string $databaseColumn = '')
+ {
+ parent::__construct($databaseColumn);
+ }
#[\Override]
public function getFormField(string $id, string $label): AbstractFormField
#[\Override]
public function applyFilter(DatabaseObjectList $list, string $id, string $value): void
{
- $list->getConditionBuilder()->add("$id = ?", [$value]);
+ $columnName = $this->getDatabaseColumnName($list, $id);
+
+ $list->getConditionBuilder()->add("{$columnName} = ?", [$value]);
}
#[\Override]
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @since 6.2
*/
-class TextFilter implements IGridViewFilter
+class TextFilter extends AbstractFilter
{
- public function __construct(private readonly string $columnName = '') {}
-
#[\Override]
public function getFormField(string $id, string $label): AbstractFormField
{
#[\Override]
public function applyFilter(DatabaseObjectList $list, string $id, string $value): void
{
+ $columnName = $this->getDatabaseColumnName($list, $id);
+
$list->getConditionBuilder()->add(
- ($this->columnName ?: $id) . " LIKE ?",
+ "{$columnName} LIKE ?",
['%' . WCF::getDB()->escapeLikeValue($value) . '%']
);
}
{
return \str_contains(\mb_strtolower($rowValue), \mb_strtolower($filterValue));
}
-
- #[\Override]
- public function renderValue(string $value): string
- {
- return $value;
- }
}
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @since 6.2
*/
-class TimeFilter implements IGridViewFilter
+class TimeFilter extends AbstractFilter
{
#[\Override]
public function getFormField(string $id, string $label): AbstractFormField
#[\Override]
public function applyFilter(DatabaseObjectList $list, string $id, string $value): void
{
+ $columnName = $this->getDatabaseColumnName($list, $id);
$timestamps = $this->getTimestamps($value);
if (!$timestamps['from'] && !$timestamps['to']) {
}
if (!$timestamps['to']) {
- $list->getConditionBuilder()->add("$id >= ?", [$timestamps['from']]);
+ $list->getConditionBuilder()->add("{$columnName} >= ?", [$timestamps['from']]);
} else {
- $list->getConditionBuilder()->add("$id BETWEEN ? AND ?", [$timestamps['from'], $timestamps['to']]);
+ $list->getConditionBuilder()->add("{$columnName} BETWEEN ? AND ?", [$timestamps['from'], $timestamps['to']]);
}
}
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @since 6.2
*/
-class UserFilter implements IGridViewFilter
+class UserFilter extends AbstractFilter
{
#[\Override]
public function getFormField(string $id, string $label): AbstractFormField
#[\Override]
public function applyFilter(DatabaseObjectList $list, string $id, string $value): void
{
- $list->getConditionBuilder()->add("{$id} = ?", [$value]);
+ $columnName = $this->getDatabaseColumnName($list, $id);
+
+ $list->getConditionBuilder()->add("{$columnName} = ?", [$value]);
}
#[\Override]