Skip to content

Commit

Permalink
[K6.3] fix: users view banned sorting / filtering (Kunena#9642)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruud68 authored Mar 4, 2024
1 parent 2a8b266 commit a5e1654
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
2 changes: 0 additions & 2 deletions src/admin/forms/filter_users.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@
<option value="email DESC">COM_KUNENA_FILTER_FIELD_EMAIL_DESC</option>
<option value="ip ASC">COM_KUNENA_FILTER_FIELD_IP_ASC</option>
<option value="ip DESC">COM_KUNENA_FILTER_FIELD_IP_DESC</option>
<option value="rank ASC">COM_KUNENA_FILTER_FIELD_RANK_ASC</option>
<option value="rank DESC">COM_KUNENA_FILTER_FIELD_RANK_DESC</option>
<option value="signature ASC">COM_KUNENA_FILTER_FIELD_SIGNATURE_ASC</option>
<option value="signature DESC">COM_KUNENA_FILTER_FIELD_SIGNATURE_DESC</option>
<option value="enabled ASC">COM_KUNENA_FILTER_FIELD_ENABLED_ASC</option>
Expand Down
16 changes: 8 additions & 8 deletions src/admin/src/Model/UsersModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
use Joomla\Database\QueryInterface;
use Kunena\Forum\Libraries\User\KunenaUser;
use Kunena\Forum\Libraries\User\KunenaUserHelper;
use RuntimeException;

/**
* Users Model for Kunena
Expand Down Expand Up @@ -223,10 +222,11 @@ protected function getListQuery(): QueryInterface
$query = $db->getQuery(true);

// Select the required fields from the table.
// We construct a composedBanned here to we can correctly sort of banned status
$query->select(
$this->getState(
'list.select',
'a.id'
'a.id, CASE WHEN a.block = 1 THEN "9999-12-31 23:59:59" ELSE ku.banned END AS composedBanned'
)
);
$query->from($db->quoteName('#__users', 'a'));
Expand Down Expand Up @@ -277,18 +277,18 @@ protected function getListQuery(): QueryInterface

if ($filter !== '') {
$now = new Date();
// $DB nulldate = 0000-00-00 00:00:00 but Kunena uses 1000-01-01 00:00:00 as nulldate
// $nullDate = $db->getNullDate() ? $db->quote($db->getNullDate()) : 'NULL';
$nullDate = $db->quote('1000-01-01 00:00:00');

// We create a composedBanned here to be able to filter on this composed field
$composedBannedCondition = 'CASE WHEN a.block = 1 THEN "9999-12-31 23:59:59" ELSE ku.banned END';

if ($filter) {
$query->where("ku.banned>{$nullDate}");
$query->where("$composedBannedCondition > {$nullDate}");
} else {
$query->where("(ku.banned IS NULL OR (ku.banned>={$nullDate} AND ku.banned<{$db->quote($now->toSql())}))");
$query->where("( $composedBannedCondition IS NULL OR ( $composedBannedCondition >={$nullDate} AND $composedBannedCondition < {$db->quote($now->toSql())}))");
}
}

// Filter by moderator state.
$filter = $this->getState('filter.moderator');

if ($filter !== '') {
Expand Down Expand Up @@ -318,7 +318,7 @@ protected function getListQuery(): QueryInterface
$query->order('a.block ' . $direction);
break;
case 'banned':
$query->order('ku.banned ' . $direction);
$query->order('composedBanned ' . $direction);
break;
case 'moderator':
$query->order('ku.moderator ' . $direction);
Expand Down
2 changes: 1 addition & 1 deletion src/admin/tmpl/users/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<?php echo HTMLHelper::_('searchtools.sort', 'COM_KUNENA_GEN_IP', 'ip', $listDirn, $listOrder); ?>
</th>
<th scope="col" class="w-10 d-none d-md-table-cell">
<?php echo HTMLHelper::_('searchtools.sort', 'COM_KUNENA_A_RANKS', 'rank', $listDirn, $listOrder); ?>
<?php echo Text::_('COM_KUNENA_A_RANKS'); ?>
</th>
<th scope="col" class="w-5 d-none d-md-table-cell">
<?php echo HTMLHelper::_('searchtools.sort', 'COM_KUNENA_GEN_SIGNATURE', 'signature', $listDirn, $listOrder); ?>
Expand Down

0 comments on commit a5e1654

Please sign in to comment.